update
This commit is contained in:
@@ -1,31 +1,37 @@
|
||||
import { _decorator, Component, Tween, tween } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
import { Component, Tween, _decorator, tween } from 'cc'
|
||||
|
||||
import { FishInfo } from '../../script/game/config/FishInfo'
|
||||
import { FishPathInfo } from '../../script/game/config/FishPathInfo'
|
||||
import FishManager from '../../script/game/manager/FishManager'
|
||||
import { FishInfo } from '../../script/game/config/FishInfo'
|
||||
import WsManager from '../../script/game/manager/WsManager'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishBase')
|
||||
export default class FishBase extends Component {
|
||||
public fishInfo: FishInfo
|
||||
public fishType: number = 1
|
||||
public blood: number = 1
|
||||
public fishPathInfo: FishPathInfo
|
||||
public isDead: boolean
|
||||
onLoad() {}
|
||||
start() {}
|
||||
public playDeadMv() {
|
||||
this.isDead = true
|
||||
this.scheduleOnce(() => {
|
||||
FishManager.instance.killFish(this)
|
||||
}, 1.5)
|
||||
tween(this.node)
|
||||
.repeatForever(tween().by(0.6, { angle: -360 }))
|
||||
.start()
|
||||
}
|
||||
onDisable() {
|
||||
//this.node.stopAllActions();
|
||||
Tween.stopAllByTarget(this.node)
|
||||
this.unscheduleAllCallbacks()
|
||||
}
|
||||
public fishInfo: FishInfo
|
||||
public fishType: number = 1
|
||||
public fishId: string = ''
|
||||
public fishPathInfo: FishPathInfo
|
||||
public isDead: number = 2
|
||||
|
||||
onLoad() {}
|
||||
|
||||
start() {}
|
||||
|
||||
// 播放死亡动画
|
||||
public playDeadMv(res: any) {
|
||||
this.isDead = 1
|
||||
this.scheduleOnce(() => {
|
||||
FishManager.instance.killFish(res)
|
||||
}, 1)
|
||||
tween(this.node)
|
||||
.repeatForever(tween().by(0.6, { angle: -360 }))
|
||||
.start()
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
Tween.stopAllByTarget(this.node)
|
||||
this.unscheduleAllCallbacks()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +1,76 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Vec2,
|
||||
Node,
|
||||
Vec3,
|
||||
error,
|
||||
Collider2D,
|
||||
Contact2DType,
|
||||
IPhysics2DContact,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
import { Collider2D, Component, Contact2DType, IPhysics2DContact, Vec2, Vec3, _decorator } from 'cc'
|
||||
|
||||
import BulletManager from '../../script/game/manager/BulletManager'
|
||||
import FishNetManager from '../../script/game/manager/FishNetManager'
|
||||
|
||||
import FishBase from './FishBase'
|
||||
import FishNetManager from '../../script/game/manager/FishNetManager'
|
||||
import BulletManager from '../../script/game/manager/BulletManager'
|
||||
import WsManager from '../../script/game/manager/WsManager'
|
||||
import CannonManager from '../../script/game/manager/CannonManager'
|
||||
import FishUI from './FishUI'
|
||||
import FishManager from '../../script/game/manager/FishManager'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishBulletBase')
|
||||
export default class FishBulletBase extends Component {
|
||||
public bulletType: number = 0
|
||||
public targetP: Vec2
|
||||
public _cacheVec2: Vec2 = new Vec2()
|
||||
public _cacheVec3: Vec3 = new Vec3()
|
||||
private _collider: Collider2D
|
||||
onLoad() {
|
||||
this._collider = this.getComponent(Collider2D)
|
||||
this._collider.sensor = true
|
||||
//this._collider.on(Contact2DType.PRE_SOLVE, this.onBeginContact, this);
|
||||
// PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
start() {}
|
||||
public bulletType: number = 0
|
||||
|
||||
onEnable() {
|
||||
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
|
||||
//this._collider.on(Contact2DType.END_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
public targetP: Vec2
|
||||
|
||||
onDisable() {
|
||||
this._collider.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
|
||||
//this._collider.off(Contact2DType.END_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
public _cacheVec2: Vec2 = new Vec2()
|
||||
|
||||
onBeginContact(
|
||||
selfCollider: Collider2D,
|
||||
other: Collider2D,
|
||||
contact: IPhysics2DContact | null
|
||||
) {
|
||||
// 只在两个碰撞体开始接触时被调用一次
|
||||
if (other) {
|
||||
let fish: FishBase = other.getComponent(FishBase)
|
||||
if (fish && !fish.isDead) {
|
||||
this.node.getPosition(this._cacheVec3)
|
||||
this._cacheVec2.x = this._cacheVec3.x
|
||||
this._cacheVec2.y = this._cacheVec3.y
|
||||
FishNetManager.instance.addFishNet(this.bulletType, this._cacheVec2)
|
||||
BulletManager.instance.killBullet(this)
|
||||
fish.blood -= this.bulletType + 1
|
||||
// fish.blood -= 100
|
||||
if (fish.blood <= 0) {
|
||||
fish.playDeadMv()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public _cacheVec3: Vec3 = new Vec3()
|
||||
|
||||
//v2.4代码
|
||||
onCollisionEnter(other: Node, self: Node) {
|
||||
error('onCollisionEnter=FishBulletBase=', other, self)
|
||||
if (other) {
|
||||
let fish: FishBase = other.getComponent(FishBase)
|
||||
if (fish && !fish.isDead) {
|
||||
this.node.getPosition(this._cacheVec3)
|
||||
this._cacheVec2.x = this._cacheVec3.x
|
||||
this._cacheVec2.y = this._cacheVec3.y
|
||||
FishNetManager.instance.addFishNet(this.bulletType, this._cacheVec2)
|
||||
BulletManager.instance.killBullet(this)
|
||||
fish.blood -= this.bulletType + 1
|
||||
// fish.blood -= 100
|
||||
if (fish.blood <= 0) {
|
||||
fish.playDeadMv()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private _collider: Collider2D | null = null
|
||||
|
||||
private currFish: FishBase | null = null
|
||||
|
||||
onLoad() {
|
||||
WsManager.instance.on(5, this.handelMsg, this)
|
||||
this._collider = this.getComponent(Collider2D)
|
||||
if (this._collider) {
|
||||
this._collider.sensor = true
|
||||
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
|
||||
}
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
onEnable() {
|
||||
if (this._collider) this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
if (this._collider) this._collider.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
|
||||
}
|
||||
|
||||
// 处理碰撞
|
||||
private handleFishCollision(fish: FishBase | null, contact: IPhysics2DContact | null) {
|
||||
if (fish && fish.isDead === 2) {
|
||||
this.node.getPosition(this._cacheVec3)
|
||||
this._cacheVec2.x = this._cacheVec3.x
|
||||
this._cacheVec2.y = this._cacheVec3.y
|
||||
FishNetManager.instance.addFishNet(this.bulletType, this._cacheVec2)
|
||||
BulletManager.instance.killBullet(this)
|
||||
}
|
||||
}
|
||||
|
||||
// 碰撞检测
|
||||
onBeginContact(selfCollider: Collider2D, other: Collider2D, contact: IPhysics2DContact | null) {
|
||||
const fish: FishBase | null = other.getComponent(FishBase)
|
||||
WsManager.instance.onSend({
|
||||
fish_id: fish.fishId,
|
||||
cannon_id: CannonManager.instance.cannonType,
|
||||
})
|
||||
this.handleFishCollision(fish, contact)
|
||||
}
|
||||
|
||||
handelMsg(res: any) {
|
||||
FishUI.instance.refreshScore(res)
|
||||
if (res.fish_status === 1) {
|
||||
FishManager.instance.killFish(res)
|
||||
}
|
||||
}
|
||||
|
||||
protected onDestroy(): void {}
|
||||
}
|
||||
|
||||
@@ -1,164 +1,134 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
CCInteger,
|
||||
CCFloat,
|
||||
Vec2,
|
||||
Animation,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
import { Animation, CCFloat, CCInteger, Component, Vec2, Vec3, _decorator, log } from 'cc'
|
||||
|
||||
const {ccclass, property} = _decorator
|
||||
import { Logger } from '../../script/engine/utils/Logger'
|
||||
import MathUtils from '../../script/engine/utils/MathUtils'
|
||||
import TimeHelper from '../../script/game/utils/TimeHelper'
|
||||
|
||||
import FishBase from './FishBase'
|
||||
import MathUtils from '../../script/engine/utils/MathUtils'
|
||||
import {Logger} from '../../script/engine/utils/Logger'
|
||||
import TimeHelper from '../../script/game/utils/TimeHelper'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishMover')
|
||||
export default class FishMover extends Component {
|
||||
//鱼类型
|
||||
@property({type: CCInteger})
|
||||
public fishType: number = 1
|
||||
//鱼移动速度
|
||||
@property({type: CCFloat})
|
||||
public speed: number = 3
|
||||
//下个位置移动点
|
||||
private targetMoveIndex: number = 0
|
||||
//鱼移动位置
|
||||
public movePList: Array<Vec2> = []
|
||||
//贝萨尔曲线
|
||||
public bezierPList: Array<Vec2> = []
|
||||
public isMoving: boolean = false
|
||||
private minSpeed: number = 0.1
|
||||
private moveCount: number = 1
|
||||
private totalTimes: number = 60 * 2
|
||||
private _vec3Cahce: Vec3 = new Vec3()
|
||||
// 鱼类型
|
||||
@property({ type: CCInteger })
|
||||
public fishType: number = 1
|
||||
|
||||
public startMove() {
|
||||
this.targetMoveIndex = 0
|
||||
this.isMoving = true
|
||||
//this.node.getComponent(Animation).play()//v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(this.node, () =>
|
||||
this.node.getComponent(Animation).play()
|
||||
)
|
||||
// 鱼移动速度
|
||||
@property({ type: CCFloat })
|
||||
public speed: number = 3
|
||||
|
||||
// 下个位置移动点
|
||||
private targetMoveIndex: number = 0
|
||||
// 鱼移动位置
|
||||
public movePList: Array<Vec2> = []
|
||||
// 贝萨尔曲线
|
||||
public bezierPList: Array<Vec2> = []
|
||||
public isMoving: boolean = false
|
||||
private minSpeed: number = 0.1
|
||||
private moveCount: number = 1
|
||||
private totalTimes: number = 60 * 2
|
||||
private _vec3Cahce: Vec3 = new Vec3()
|
||||
|
||||
public startMove() {
|
||||
this.targetMoveIndex = 0
|
||||
this.isMoving = true
|
||||
// this.node.getComponent(Animation).play()//v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(this.node, () => this.node.getComponent(Animation).play())
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
// this.moveFish();
|
||||
this.checkMoveBezier()
|
||||
}
|
||||
|
||||
// 检测是否到达目标点
|
||||
private checkMoveBezier() {
|
||||
if (this.isMoving && this.getComponent(FishBase).isDead === 2) {
|
||||
this.moveCount++
|
||||
if (this.moveCount >= this.totalTimes) this.moveCount = this.totalTimes
|
||||
this.moveBezier()
|
||||
}
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
// this.moveFish();
|
||||
this.checkMoveBezier()
|
||||
}
|
||||
|
||||
private checkMoveBezier() {
|
||||
if (this.isMoving && !this.getComponent(FishBase).isDead) {
|
||||
this.moveCount++
|
||||
if (this.moveCount >= this.totalTimes) {
|
||||
this.moveCount = this.totalTimes
|
||||
}
|
||||
this.moveBezier()
|
||||
// 贝塞尔曲线移动
|
||||
public moveBezier() {
|
||||
if (this.bezierPList.length > this.targetMoveIndex + 2) {
|
||||
const p0: Vec2 = this.bezierPList[this.targetMoveIndex]
|
||||
const p1: Vec2 = this.bezierPList[this.targetMoveIndex + 1]
|
||||
const p2: Vec2 = this.bezierPList[this.targetMoveIndex + 2]
|
||||
const t: number = this.moveCount / this.totalTimes
|
||||
const mx: number = (1 - t) ** 2 * p0.x + 2 * t * (1 - t) * p1.x + t ** 2 * p2.x
|
||||
const my: number = (1 - t) ** 2 * p0.y + 2 * t * (1 - t) * p1.y + t ** 2 * p2.y
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
const rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cahce.x, this._vec3Cahce.y),
|
||||
new Vec2(mx, my),
|
||||
)
|
||||
const rot111: number = MathUtils.radiansToDegrees(rad)
|
||||
const rot: number = MathUtils.rotation2Fish(rot111)
|
||||
if (this.fishType === 7 || this.fishType === 27 || this.fishType === 29) {
|
||||
if (rot > 90 || rot < -90) {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x > 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public moveBezier() {
|
||||
// [warn] [[-632,-230],[-444,-117],[-264,-242]]
|
||||
// let p0: cc.Vec2 = cc.v2(-632, -230)
|
||||
// let p1: cc.Vec2 = cc.v2(-444, -117)
|
||||
// let p2: cc.Vec2 = cc.v2(-264, -242)
|
||||
if (this.bezierPList.length > this.targetMoveIndex + 2) {
|
||||
let p0: Vec2 = this.bezierPList[this.targetMoveIndex]
|
||||
let p1: Vec2 = this.bezierPList[this.targetMoveIndex + 1]
|
||||
let p2: Vec2 = this.bezierPList[this.targetMoveIndex + 2]
|
||||
let t: number = this.moveCount / this.totalTimes
|
||||
let mx: number =
|
||||
Math.pow(1 - t, 2) * p0.x +
|
||||
2 * t * (1 - t) * p1.x +
|
||||
Math.pow(t, 2) * p2.x
|
||||
let my: number =
|
||||
Math.pow(1 - t, 2) * p0.y +
|
||||
2 * t * (1 - t) * p1.y +
|
||||
Math.pow(t, 2) * p2.y
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cahce.x, this._vec3Cahce.y),
|
||||
new Vec2(mx, my)
|
||||
)
|
||||
let rot111: number = MathUtils.radiansToDegrees(rad)
|
||||
let rot: number = MathUtils.rotation2Fish(rot111)
|
||||
if (this.fishType == 7 || this.fishType == 27 || this.fishType == 29) {
|
||||
if (rot > 90 || rot < -90) {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x > 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
} else {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x < 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
this.fishType == 9 ||
|
||||
this.fishType == 10 ||
|
||||
this.fishType == 21 ||
|
||||
this.fishType == 28
|
||||
) {
|
||||
} else {
|
||||
// this.node.rotation = rot; //过时
|
||||
this.node.angle = -rot
|
||||
}
|
||||
// Logger.log("moveBezier====", rad, rot111, this.fishType, rot)
|
||||
let moveTimes: number = Math.round(this.speed / this.minSpeed)
|
||||
for (let i = 0; i < moveTimes; i++) {
|
||||
let speedX: number = this.minSpeed * Math.cos(rad)
|
||||
let speedY: number = this.minSpeed * Math.sin(rad)
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
this._vec3Cahce.x += speedX
|
||||
this._vec3Cahce.y += speedY
|
||||
this.node.setPosition(this._vec3Cahce)
|
||||
if (
|
||||
MathUtils.distance(this._vec3Cahce.x, this._vec3Cahce.y, mx, my) <=
|
||||
this.minSpeed
|
||||
) {
|
||||
this.node.setPosition(mx, my)
|
||||
break
|
||||
}
|
||||
if (
|
||||
MathUtils.distance(
|
||||
this._vec3Cahce.x,
|
||||
this._vec3Cahce.y,
|
||||
p2.x,
|
||||
p2.y
|
||||
) <=
|
||||
this.minSpeed * 2
|
||||
) {
|
||||
this.node.setPosition(p2.x, p2.y)
|
||||
this.targetMoveIndex += 2
|
||||
this.moveCount = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.isMoving = false
|
||||
} else if (
|
||||
this.fishType === 9 ||
|
||||
this.fishType === 10 ||
|
||||
this.fishType === 21 ||
|
||||
this.fishType === 28
|
||||
) {
|
||||
} else {
|
||||
this.node.angle = -rot
|
||||
}
|
||||
// Logger.log("moveBezier====", rad, rot111, this.fishType, rot)
|
||||
const moveTimes: number = Math.round(this.speed / this.minSpeed)
|
||||
for (let i = 0; i < moveTimes; i++) {
|
||||
const speedX: number = this.minSpeed * Math.cos(rad)
|
||||
const speedY: number = this.minSpeed * Math.sin(rad)
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
this._vec3Cahce.x += speedX
|
||||
this._vec3Cahce.y += speedY
|
||||
this.node.setPosition(this._vec3Cahce)
|
||||
if (MathUtils.distance(this._vec3Cahce.x, this._vec3Cahce.y, mx, my) <= this.minSpeed) {
|
||||
this.node.setPosition(mx, my)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this.isMoving = false
|
||||
}
|
||||
|
||||
public exportBezierConfig() {
|
||||
Logger.warn('exportBezierConfig=')
|
||||
let tempConfig: Array<Array<number>> = []
|
||||
for (let i = 0; i < this.bezierPList.length; i++) {
|
||||
tempConfig[i] = []
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].x))
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].y))
|
||||
if (
|
||||
MathUtils.distance(this._vec3Cahce.x, this._vec3Cahce.y, p2.x, p2.y) <=
|
||||
this.minSpeed * 2
|
||||
) {
|
||||
this.node.setPosition(p2.x, p2.y)
|
||||
this.targetMoveIndex += 2
|
||||
this.moveCount = 0
|
||||
break
|
||||
}
|
||||
Logger.warn('fishtype', this.fishType)
|
||||
Logger.warn('speed', this.speed)
|
||||
Logger.warn('scale', this.node.scale)
|
||||
Logger.warn(JSON.stringify(tempConfig))
|
||||
}
|
||||
} else {
|
||||
Logger.log('moveBezier====', 'end')
|
||||
this.isMoving = false
|
||||
}
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this.isMoving = false
|
||||
}
|
||||
|
||||
// 导出贝塞尔曲线配置
|
||||
public exportBezierConfig() {
|
||||
Logger.warn('exportBezierConfig=')
|
||||
const tempConfig: Array<Array<number>> = []
|
||||
for (let i = 0; i < this.bezierPList.length; i++) {
|
||||
tempConfig[i] = []
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].x))
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].y))
|
||||
}
|
||||
Logger.warn('fishtype', this.fishType)
|
||||
Logger.warn('speed', this.speed)
|
||||
Logger.warn('scale', this.node.scale)
|
||||
Logger.warn(JSON.stringify(tempConfig))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
import { _decorator, Component, Tween, tween, Vec3, Vec2 } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
import { Component, Tween, Vec3, _decorator, tween } from 'cc'
|
||||
|
||||
import FishNetManager from '../../script/game/manager/FishNetManager'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishNetBase')
|
||||
export default class FishNetBase extends Component {
|
||||
public netType: number = 0
|
||||
public netType: number = 0
|
||||
|
||||
private tween: Tween<any>
|
||||
private static vec3: Vec3 = new Vec3(2, 2, 1)
|
||||
public playMv() {
|
||||
this.node.setScale(Vec3.ZERO)
|
||||
this.tween = tween(this.node)
|
||||
.to(0.2, { scale: FishNetBase.vec3 })
|
||||
.delay(0.3)
|
||||
.call(() => {
|
||||
FishNetManager.instance.destroyFishNet(this)
|
||||
})
|
||||
.start()
|
||||
}
|
||||
onDestroy() {
|
||||
if (this.tween) {
|
||||
this.tween.stop()
|
||||
}
|
||||
}
|
||||
private tween: Tween<any>
|
||||
private static vec3: Vec3 = new Vec3(2, 2, 1)
|
||||
|
||||
// 销毁渔网
|
||||
public playMv() {
|
||||
this.node.setScale(Vec3.ZERO)
|
||||
this.tween = tween(this.node)
|
||||
.to(0.2, { scale: FishNetBase.vec3 })
|
||||
.delay(0.3)
|
||||
.call(() => {
|
||||
FishNetManager.instance.destroyFishNet(this)
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
if (this.tween) this.tween.stop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,55 @@
|
||||
import { _decorator, Slider, Node, Canvas, instantiate, director } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
import { Node, Slider, _decorator, instantiate } from 'cc'
|
||||
|
||||
import EventManager from '../../script/engine/utils/EventManager'
|
||||
import DialogBase from '../../script/engine/uicomponent/DialogBase'
|
||||
import MusicPrefab from '../../script/engine/uicomponent/MusicPrefab'
|
||||
import SoundPrefab from '../../script/engine/uicomponent/SoundPrefab'
|
||||
import EventManager from '../../script/engine/utils/EventManager'
|
||||
import PrefabLoader from '../../script/engine/utils/PrefabLoader'
|
||||
import { GameConfig } from '../../script/game/config/GameConfig'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishSetting')
|
||||
export default class FishSetting extends DialogBase {
|
||||
@property({ type: Slider })
|
||||
private musicSlider: Slider | null = null
|
||||
@property({ type: Slider })
|
||||
private soundSlider: Slider | null = null
|
||||
@property({ type: Slider })
|
||||
private musicSlider: Slider | null = null
|
||||
|
||||
onLoadMe() {
|
||||
EventManager.instance.addSliderEvent(
|
||||
this.node,
|
||||
this.musicSlider.node,
|
||||
'onMusicSlider',
|
||||
0
|
||||
)
|
||||
EventManager.instance.addSliderEvent(
|
||||
this.node,
|
||||
this.soundSlider.node,
|
||||
'onSoundSlider',
|
||||
0
|
||||
)
|
||||
this.refresh()
|
||||
}
|
||||
@property({ type: Slider })
|
||||
private soundSlider: Slider | null = null
|
||||
|
||||
private onMusicSlider(slider: Slider, customEventData) {
|
||||
let percent: number = Number(slider.progress.toFixed(3))
|
||||
// let maxMoney: number = Math.max(UserInfoModel.userScore - 10, 0)
|
||||
// this.nowExchangeNum = Math.floor(maxMoney * this.nowPercent);
|
||||
// this.refresh();
|
||||
MusicPrefab.changeVolumn(percent)
|
||||
this.refresh()
|
||||
}
|
||||
onLoadMe() {
|
||||
EventManager.instance.addSliderEvent(this.node, this.musicSlider.node, 'onMusicSlider', 0)
|
||||
EventManager.instance.addSliderEvent(this.node, this.soundSlider.node, 'onSoundSlider', 0)
|
||||
this.refresh()
|
||||
}
|
||||
|
||||
private onSoundSlider(slider: Slider, customEventData) {
|
||||
let percent: number = Number(slider.progress.toFixed(3))
|
||||
SoundPrefab.changeVolumn(percent)
|
||||
this.refresh()
|
||||
}
|
||||
// 音乐
|
||||
private onMusicSlider(slider: Slider, customEventData) {
|
||||
const percent: number = Number(slider.progress.toFixed(3))
|
||||
MusicPrefab.changeVolumn(percent)
|
||||
this.refresh()
|
||||
}
|
||||
|
||||
private refresh() {
|
||||
this.musicSlider.progress = MusicPrefab.musicVolumn
|
||||
this.soundSlider.progress = SoundPrefab.soundVolumn
|
||||
}
|
||||
// 声音
|
||||
private onSoundSlider(slider: Slider, customEventData) {
|
||||
const percent: number = Number(slider.progress.toFixed(3))
|
||||
SoundPrefab.changeVolumn(percent)
|
||||
this.refresh()
|
||||
}
|
||||
|
||||
public static show(parentNode: Node = null) {
|
||||
PrefabLoader.loadPrefab(
|
||||
GameConfig.GameName + '/' + 'game/dialog/FishSetting',
|
||||
(loadedResource) => {
|
||||
if (!parentNode) {
|
||||
parentNode = DialogBase.GetRootCanvas()
|
||||
}
|
||||
let node: Node = instantiate(loadedResource)
|
||||
parentNode.addChild(node)
|
||||
node.setPosition(0, 0)
|
||||
}
|
||||
)
|
||||
}
|
||||
// 刷新音乐和声音
|
||||
private refresh() {
|
||||
this.musicSlider.progress = MusicPrefab.musicVolumn
|
||||
this.soundSlider.progress = SoundPrefab.soundVolumn
|
||||
}
|
||||
|
||||
public static show(parentNode: Node = null) {
|
||||
PrefabLoader.loadPrefab(`${GameConfig.GameName}/game/dialog/FishSetting`, (loadedResource) => {
|
||||
if (!parentNode) parentNode = DialogBase.GetRootCanvas()
|
||||
|
||||
const node: Node = instantiate(loadedResource)
|
||||
parentNode.addChild(node)
|
||||
node.setPosition(0, 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,106 +1,109 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Label,
|
||||
Animation,
|
||||
Node,
|
||||
Vec2,
|
||||
Tween,
|
||||
tween,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
import { Animation, Component, Label, Node, Tween, Vec2, Vec3, _decorator, find, tween } from 'cc'
|
||||
|
||||
import CannonManager from '../../script/game/manager/CannonManager'
|
||||
import FishManager from '../../script/game/manager/FishManager'
|
||||
|
||||
import FishSetting from './FishSetting'
|
||||
import FishManager from '../../script/game/manager/FishManager'
|
||||
import CannonManager from '../../script/game/manager/CannonManager'
|
||||
import WsManager from '../../script/game/manager/WsManager'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishUI')
|
||||
export default class FishUI extends Component {
|
||||
public static instance: FishUI = null
|
||||
@property({ type: Label })
|
||||
private dzScore: Label | null = null
|
||||
@property({ type: Label })
|
||||
private jfScore: Label | null = null
|
||||
@property({ type: Animation })
|
||||
private clickEffect: Animation | null = null
|
||||
@property({ type: Node })
|
||||
private waveEffect: Node | null = null
|
||||
// 豆子
|
||||
public dz_score: number = 100
|
||||
// 积分
|
||||
public jf_score: number = 0
|
||||
private _vec3Cache: Vec3
|
||||
onLoad() {
|
||||
FishUI.instance = this
|
||||
this._vec3Cache = new Vec3()
|
||||
this.clickEffect.node.active = false
|
||||
this.waveEffect.active = false
|
||||
this.dzScore = this.node
|
||||
.getChildByName('dzScore')
|
||||
.getComponent(Label) as Label
|
||||
this.jfScore = this.node
|
||||
.getChildByName('jfScore')
|
||||
.getComponent(Label) as Label
|
||||
}
|
||||
public static instance: FishUI = null
|
||||
@property({ type: Label })
|
||||
private dzScore: Label | null = null
|
||||
|
||||
start() {
|
||||
this.refreshScore()
|
||||
// setTimeout(()=>{
|
||||
// this.playWaveEffect();
|
||||
// }, 5000)
|
||||
}
|
||||
@property({ type: Label })
|
||||
private jfScore: Label | null = null
|
||||
|
||||
public playClickEffect(p: Vec2) {
|
||||
this._vec3Cache.x = p.x
|
||||
this._vec3Cache.y = p.y
|
||||
this._vec3Cache.z = 0
|
||||
this.clickEffect.node.setPosition(this._vec3Cache)
|
||||
this.clickEffect.node.active = true
|
||||
this.clickEffect.play()
|
||||
}
|
||||
@property({ type: Animation })
|
||||
private clickEffect: Animation | null = null
|
||||
|
||||
public playWaveEffect() {
|
||||
this.waveEffect.active = true
|
||||
this.waveEffect.setPosition(1292.703, 0)
|
||||
@property({ type: Node })
|
||||
private waveEffect: Node | null = null
|
||||
|
||||
FishManager.instance.playFishMap()
|
||||
tween(this.waveEffect)
|
||||
.to(2, { position: new Vec3(-1319.969, 0, 0) })
|
||||
.call(() => {
|
||||
this.waveEffect.active = false
|
||||
FishManager.instance.startFishMap()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
// 豆子
|
||||
public dz_score: number = 0
|
||||
// 积分
|
||||
public jf_score: number = 0
|
||||
private _vec3Cache: Vec3
|
||||
|
||||
private onClickPre() {
|
||||
if (CannonManager.instance.cannonType > 1) {
|
||||
CannonManager.instance.cannonType--
|
||||
CannonManager.instance.refreshCannon()
|
||||
}
|
||||
}
|
||||
onLoad() {
|
||||
FishUI.instance = this
|
||||
this._vec3Cache = new Vec3()
|
||||
this.clickEffect.node.active = false
|
||||
this.waveEffect.active = false
|
||||
this.dzScore = this.node
|
||||
.getChildByName('userInfo')
|
||||
.getChildByName('info')
|
||||
.getChildByName('dz_fillet')
|
||||
.getChildByName('dz_text')
|
||||
.getComponent(Label) as Label
|
||||
this.jfScore = this.node
|
||||
.getChildByName('userInfo')
|
||||
.getChildByName('info')
|
||||
.getChildByName('jf_fillet')
|
||||
.getChildByName('jf_text')
|
||||
.getComponent(Label) as Label
|
||||
}
|
||||
|
||||
private onClickNext() {
|
||||
if (CannonManager.instance.cannonType < 7) {
|
||||
CannonManager.instance.cannonType++
|
||||
CannonManager.instance.refreshCannon()
|
||||
}
|
||||
}
|
||||
start() {
|
||||
// this.refreshScore()
|
||||
}
|
||||
|
||||
public refreshScore() {
|
||||
this.dzScore.string = this.dz_score + ''
|
||||
this.jfScore.string = this.jf_score + ''
|
||||
}
|
||||
public playClickEffect(p: Vec2) {
|
||||
this._vec3Cache.x = p.x
|
||||
this._vec3Cache.y = p.y
|
||||
this._vec3Cache.z = 0
|
||||
this.clickEffect.node.setPosition(this._vec3Cache)
|
||||
this.clickEffect.node.active = true
|
||||
this.clickEffect.play()
|
||||
}
|
||||
|
||||
private onClickSetting() {
|
||||
FishSetting.show()
|
||||
}
|
||||
public playWaveEffect() {
|
||||
this.waveEffect.active = true
|
||||
this.waveEffect.setPosition(1292.703, 0)
|
||||
|
||||
onDestroy() {
|
||||
FishUI.instance = null
|
||||
this.unscheduleAllCallbacks()
|
||||
Tween.stopAllByTarget(this.node)
|
||||
//this.node.stopAllActions();
|
||||
}
|
||||
FishManager.instance.playFishMap()
|
||||
tween(this.waveEffect)
|
||||
.to(2, { position: new Vec3(-1319.969, 0, 0) })
|
||||
.call(() => {
|
||||
this.waveEffect.active = false
|
||||
FishManager.instance.startFishMap()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
private onClickPre() {
|
||||
if (CannonManager.instance.cannonType > 1) {
|
||||
CannonManager.instance.cannonType--
|
||||
CannonManager.instance.refreshCannon()
|
||||
}
|
||||
}
|
||||
|
||||
private onClickNext() {
|
||||
if (CannonManager.instance.cannonType < 7) {
|
||||
CannonManager.instance.cannonType++
|
||||
CannonManager.instance.refreshCannon()
|
||||
}
|
||||
}
|
||||
|
||||
public refreshScore(res: any) {
|
||||
this.dz_score = res.pulse
|
||||
this.jf_score = res.integral
|
||||
this.dzScore.string = `${this.dz_score}`
|
||||
this.jfScore.string = `${this.jf_score}`
|
||||
}
|
||||
|
||||
private onClickSetting() {
|
||||
FishSetting.show()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishUI.instance = null
|
||||
this.unscheduleAllCallbacks()
|
||||
Tween.stopAllByTarget(this.node)
|
||||
// this.node.stopAllActions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
import {
|
||||
_decorator,
|
||||
ScrollView,
|
||||
Prefab,
|
||||
Node,
|
||||
instantiate,
|
||||
Label,
|
||||
Vec3,
|
||||
Animation,
|
||||
} from 'cc'
|
||||
import { _decorator, ScrollView, Prefab, Node, instantiate, Label, Vec3, Animation } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import FishBase from './FishBase'
|
||||
@@ -21,70 +12,62 @@ import TimeHelper from '../../script/game/utils/TimeHelper'
|
||||
|
||||
@ccclass('FishWiki')
|
||||
export default class FishWiki extends DialogBase {
|
||||
@property({ type: ScrollView })
|
||||
private scrollView: ScrollView | null = null
|
||||
@property({ type: Prefab })
|
||||
private wikiItemPrefab: Prefab | null = null
|
||||
@property({ type: ScrollView })
|
||||
private scrollView: ScrollView | null = null
|
||||
@property({ type: Prefab })
|
||||
private wikiItemPrefab: Prefab | null = null
|
||||
|
||||
private _vec3Cache: Vec3
|
||||
onLoadMe() {
|
||||
this._vec3Cache = new Vec3(1, 1, 1)
|
||||
this.init()
|
||||
}
|
||||
private _vec3Cache: Vec3
|
||||
onLoadMe() {
|
||||
this._vec3Cache = new Vec3(1, 1, 1)
|
||||
this.init()
|
||||
}
|
||||
|
||||
private init() {
|
||||
this.scrollView.content.removeAllChildren()
|
||||
this.initOne(0)
|
||||
}
|
||||
private init() {
|
||||
this.scrollView.content.removeAllChildren()
|
||||
this.initOne(0)
|
||||
}
|
||||
|
||||
private initOne(index: number) {
|
||||
if (index < FishConfig.config.length) {
|
||||
let itemNode: Node = instantiate(this.wikiItemPrefab)
|
||||
private initOne(index: number) {
|
||||
if (index < FishConfig.config.length) {
|
||||
let itemNode: Node = instantiate(this.wikiItemPrefab)
|
||||
|
||||
this.scrollView.content.addChild(itemNode)
|
||||
let fishInfo: FishInfo = FishConfig.config[index]
|
||||
let txtName: Label = itemNode
|
||||
.getChildByName('txtName')
|
||||
.getComponent(Label)
|
||||
txtName.string = fishInfo.name
|
||||
let txtLife: Label = itemNode
|
||||
.getChildByName('txtLife')
|
||||
.getComponent(Label)
|
||||
txtLife.string = 'life:' + fishInfo.blood + ''
|
||||
let view: Node = itemNode.getChildByName('view')
|
||||
view.removeAllChildren()
|
||||
this.scrollView.content.addChild(itemNode)
|
||||
let fishInfo: FishInfo = FishConfig.config[index]
|
||||
let txtName: Label = itemNode.getChildByName('txtName').getComponent(Label)
|
||||
txtName.string = fishInfo.name
|
||||
let txtLife: Label = itemNode.getChildByName('txtLife').getComponent(Label)
|
||||
txtLife.string = '积分:' + fishInfo.blood + ''
|
||||
let view: Node = itemNode.getChildByName('view')
|
||||
view.removeAllChildren()
|
||||
|
||||
let fish: FishBase = FishManager.instance.createFishByType(
|
||||
fishInfo.fishType
|
||||
)
|
||||
view.addChild(fish.node)
|
||||
fish.node.setPosition(0, 0)
|
||||
let fish: FishBase = FishManager.instance.createFishByType(fishInfo.fishType)
|
||||
view.addChild(fish.node)
|
||||
fish.node.setPosition(0, 0)
|
||||
|
||||
//缩放有bug
|
||||
//Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, fishInfo.wikiScale);
|
||||
//fish.node.setScale(this._vec3Cache);
|
||||
//缩放有bug
|
||||
//Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, fishInfo.wikiScale);
|
||||
//fish.node.setScale(this._vec3Cache);
|
||||
|
||||
//fish.node.getComponent(Animation).play(); //v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(this.node, () =>
|
||||
fish.node.getComponent(Animation).play()
|
||||
)
|
||||
this.scheduleOnce(() => {
|
||||
this.initOne(index + 1)
|
||||
}, 0.05)
|
||||
}
|
||||
}
|
||||
//fish.node.getComponent(Animation).play(); //v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(this.node, () => fish.node.getComponent(Animation).play())
|
||||
this.scheduleOnce(() => {
|
||||
this.initOne(index + 1)
|
||||
}, 0.05)
|
||||
}
|
||||
}
|
||||
|
||||
public static show(parentNode: Node = null) {
|
||||
PrefabLoader.loadPrefab(
|
||||
GameConfig.GameName + '/' + 'game/dialog/FishWiki',
|
||||
(loadedResource) => {
|
||||
if (!parentNode) {
|
||||
parentNode = DialogBase.GetRootCanvas()
|
||||
}
|
||||
let node: Node = instantiate(loadedResource)
|
||||
parentNode.addChild(node)
|
||||
node.setPosition(0, 0)
|
||||
}
|
||||
)
|
||||
}
|
||||
public static show(parentNode: Node = null) {
|
||||
PrefabLoader.loadPrefab(
|
||||
GameConfig.GameName + '/' + 'game/dialog/FishWiki',
|
||||
(loadedResource) => {
|
||||
if (!parentNode) {
|
||||
parentNode = DialogBase.GetRootCanvas()
|
||||
}
|
||||
let node: Node = instantiate(loadedResource)
|
||||
parentNode.addChild(node)
|
||||
node.setPosition(0, 0)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user