优化若干代码
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Prefab,
|
||||
NodePool,
|
||||
Event,
|
||||
Node,
|
||||
Vec3,
|
||||
Vec2,
|
||||
EventTouch,
|
||||
UITransform,
|
||||
instantiate,
|
||||
sys,
|
||||
error,
|
||||
_decorator,
|
||||
Component,
|
||||
EventTouch,
|
||||
instantiate,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
sys,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import FishBulletBase from '../../../fish/script/FishBulletBase'
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
import CannonManager from './CannonManager'
|
||||
@@ -25,136 +20,140 @@ import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('BulletManager')
|
||||
export default class BulletManager extends Component {
|
||||
public static instance: BulletManager = null
|
||||
@property({ type: [Prefab] })
|
||||
private bulletPrefabList: Prefab[] = []
|
||||
private bulletPool: Array<NodePool> = []
|
||||
private bulletList: Array<FishBulletBase> = []
|
||||
private bulletMoveSpeed: number = 30
|
||||
private _vec3Cache
|
||||
private _vec2Cache
|
||||
private _fireTime: number = 0
|
||||
private _fireTimeNew: number
|
||||
onLoad() {
|
||||
this._vec3Cache = new Vec3()
|
||||
this._vec2Cache = new Vec2()
|
||||
BulletManager.instance = this
|
||||
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
|
||||
// this.node.on(Node.EventType.TOUCH_MOVE, this.onShootBullet, this)
|
||||
}
|
||||
public static instance: BulletManager = null
|
||||
@property({ type: [Prefab] })
|
||||
private bulletPrefabList: Prefab[] | [] = []
|
||||
private bulletPool: Array<NodePool> = []
|
||||
private bulletList: Array<FishBulletBase> = []
|
||||
private bulletMoveSpeed: number = 30
|
||||
private _vec3Cache: Vec3
|
||||
private _vec2Cache: Vec2
|
||||
private _fireTime: number = 0
|
||||
private _fireTimeNew: number
|
||||
|
||||
start() {}
|
||||
onLoad() {
|
||||
this._vec3Cache = new Vec3()
|
||||
this._vec2Cache = new Vec2()
|
||||
BulletManager.instance = this
|
||||
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
|
||||
// this.node.on(Node.EventType.TOUCH_MOVE, this.onShootBullet, this)
|
||||
}
|
||||
|
||||
update() {
|
||||
this.checkMoveBullet()
|
||||
}
|
||||
start() {
|
||||
}
|
||||
|
||||
private checkMoveBullet() {
|
||||
for (let i = this.bulletList.length - 1; i >= 0; i--) {
|
||||
let bullet: FishBulletBase = this.bulletList[i]
|
||||
let isMoving: boolean = MoveHelper.moveNode(
|
||||
bullet.node,
|
||||
this.bulletMoveSpeed,
|
||||
bullet.targetP.x,
|
||||
bullet.targetP.y
|
||||
)
|
||||
if (!isMoving) {
|
||||
bullet.node.getPosition(this._vec3Cache)
|
||||
this._vec2Cache.x = this._vec3Cache.x
|
||||
this._vec2Cache.y = this._vec3Cache.y
|
||||
FishNetManager.instance.addFishNet(bullet.bulletType, this._vec2Cache)
|
||||
this.bulletList.splice(i, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
}
|
||||
update() {
|
||||
this.checkMoveBullet()
|
||||
}
|
||||
|
||||
private onShootBullet(event: EventTouch) {
|
||||
//TOUCH_START 在Editor上,连续触发2次,导致发2次炮弹bug
|
||||
if (sys.platform == 'EDITOR_PAGE') {
|
||||
this._fireTimeNew = new Date().getTime()
|
||||
if (this._fireTimeNew - this._fireTime < 100) {
|
||||
return
|
||||
}
|
||||
this._fireTime = this._fireTimeNew
|
||||
}
|
||||
private checkMoveBullet() {
|
||||
for (let i = this.bulletList.length - 1; i >= 0; i--) {
|
||||
let bullet: FishBulletBase = this.bulletList[i]
|
||||
let isMoving: boolean = MoveHelper.moveNode(
|
||||
bullet.node,
|
||||
this.bulletMoveSpeed,
|
||||
bullet.targetP.x,
|
||||
bullet.targetP.y
|
||||
)
|
||||
if (!isMoving) {
|
||||
bullet.node.getPosition(this._vec3Cache)
|
||||
this._vec2Cache.x = this._vec3Cache.x
|
||||
this._vec2Cache.y = this._vec3Cache.y
|
||||
FishNetManager.instance.addFishNet(bullet.bulletType, this._vec2Cache)
|
||||
this.bulletList.splice(i, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let tran = this.node.getComponent(UITransform)
|
||||
let location = event.getUILocation()
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
let localP: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
FishUI.instance.playClickEffect(localP)
|
||||
// 子弹发射
|
||||
if (FishUI.instance.dz_score >= CannonManager.instance.cannonType) {
|
||||
FishUI.instance.dz_score -= CannonManager.instance.cannonType
|
||||
FishUI.instance.refreshScore()
|
||||
this._vec3Cache = CannonManager.instance.getCannonPosition()
|
||||
private onShootBullet(event: EventTouch) {
|
||||
//TOUCH_START 在Editor上,连续触发2次,导致发2次炮弹bug
|
||||
if (sys.platform == 'EDITOR_PAGE') {
|
||||
this._fireTimeNew = new Date().getTime()
|
||||
if (this._fireTimeNew - this._fireTime < 100) {
|
||||
return
|
||||
}
|
||||
this._fireTime = this._fireTimeNew
|
||||
}
|
||||
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
|
||||
localP
|
||||
)
|
||||
let rot: number = MathUtils.radiansToDegrees(rad)
|
||||
let bullet: FishBulletBase = this.createBullet(
|
||||
CannonManager.instance.cannonType - 1
|
||||
)
|
||||
bullet.targetP = localP
|
||||
this.node.addChild(bullet.node)
|
||||
bullet.node.setPosition(CannonManager.instance.getCannonPosition())
|
||||
this._vec3Cache.x = 1
|
||||
this._vec3Cache.y = 1
|
||||
this._vec3Cache.y = 1
|
||||
Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, 2)
|
||||
bullet.node.setScale(this._vec3Cache)
|
||||
bullet.node.angle = rot
|
||||
this.bulletList.push(bullet)
|
||||
GameMusicHelper.playFire()
|
||||
let tran = this.node.getComponent(UITransform)
|
||||
let location = event.getUILocation()
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
let localP: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
FishUI.instance.playClickEffect(localP)
|
||||
// 子弹发射
|
||||
if (FishUI.instance.dz_score >= CannonManager.instance.cannonType) {
|
||||
FishUI.instance.dz_score -= CannonManager.instance.cannonType
|
||||
FishUI.instance.refreshScore()
|
||||
this._vec3Cache = CannonManager.instance.getCannonPosition()
|
||||
|
||||
//旋转炮台
|
||||
CannonManager.instance.rotateCannon(location)
|
||||
} else {
|
||||
CommonTips.showMsg('豆子不足!')
|
||||
}
|
||||
}
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
|
||||
localP
|
||||
)
|
||||
let rot: number = MathUtils.radiansToDegrees(rad)
|
||||
let bullet: FishBulletBase = this.createBullet(
|
||||
CannonManager.instance.cannonType - 1
|
||||
)
|
||||
bullet.targetP = localP
|
||||
this.node.addChild(bullet.node)
|
||||
bullet.node.setPosition(CannonManager.instance.getCannonPosition())
|
||||
this._vec3Cache.x = 1
|
||||
this._vec3Cache.y = 1
|
||||
this._vec3Cache.y = 1
|
||||
Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, 2)
|
||||
bullet.node.setScale(this._vec3Cache)
|
||||
bullet.node.angle = rot
|
||||
this.bulletList.push(bullet)
|
||||
GameMusicHelper.playFire()
|
||||
|
||||
private createBullet(bulletType: number) {
|
||||
let bulletNode: Node
|
||||
if (this.bulletPool[bulletType] && this.bulletPool[bulletType].size() > 0) {
|
||||
bulletNode = this.bulletPool[bulletType].get()
|
||||
} else {
|
||||
bulletNode = instantiate(this.bulletPrefabList[bulletType])
|
||||
}
|
||||
bulletNode.getComponent(FishBulletBase).bulletType = bulletType
|
||||
return bulletNode.getComponent(FishBulletBase)
|
||||
}
|
||||
//旋转炮台
|
||||
CannonManager.instance.rotateCannon(location)
|
||||
} else {
|
||||
CommonTips.showMsg('豆子不足!')
|
||||
}
|
||||
}
|
||||
|
||||
public killBullet(bullet: FishBulletBase) {
|
||||
let index: number = this.bulletList.indexOf(bullet)
|
||||
if (index >= 0) {
|
||||
this.bulletList.splice(index, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
private createBullet(bulletType: number) {
|
||||
let bulletNode: Node
|
||||
if (this.bulletPool[bulletType] && this.bulletPool[bulletType].size() > 0) {
|
||||
bulletNode = this.bulletPool[bulletType].get()
|
||||
} else {
|
||||
bulletNode = instantiate(this.bulletPrefabList[bulletType])
|
||||
}
|
||||
bulletNode.getComponent(FishBulletBase).bulletType = bulletType
|
||||
return bulletNode.getComponent(FishBulletBase)
|
||||
}
|
||||
|
||||
private destroyBullet(bullet: FishBulletBase) {
|
||||
//临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
|
||||
if (sys.platform == 'EDITOR_PAGE') {
|
||||
bullet.node.destroy()
|
||||
return
|
||||
}
|
||||
public killBullet(bullet: FishBulletBase) {
|
||||
let index: number = this.bulletList.indexOf(bullet)
|
||||
if (index >= 0) {
|
||||
this.bulletList.splice(index, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.bulletPool[bullet.bulletType]) {
|
||||
this.bulletPool[bullet.bulletType] = new NodePool()
|
||||
}
|
||||
this.bulletPool[bullet.bulletType].put(bullet.node)
|
||||
}
|
||||
private destroyBullet(bullet: FishBulletBase) {
|
||||
//临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
|
||||
if (sys.platform == 'EDITOR_PAGE') {
|
||||
bullet.node.destroy()
|
||||
return
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
BulletManager.instance = null
|
||||
}
|
||||
if (!this.bulletPool[bullet.bulletType]) {
|
||||
this.bulletPool[bullet.bulletType] = new NodePool()
|
||||
}
|
||||
this.bulletPool[bullet.bulletType].put(bullet.node)
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
BulletManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,58 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Node,
|
||||
SpriteFrame,
|
||||
Event,
|
||||
EventMouse,
|
||||
Sprite,
|
||||
Vec2,
|
||||
UITransform,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, EventMouse, Node, Sprite, SpriteFrame, UITransform, Vec2, Vec3 } from 'cc'
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CannonManager')
|
||||
export default class CannonManager extends Component {
|
||||
public static instance: CannonManager = null
|
||||
@property({ type: Node })
|
||||
private view: Node | null = null
|
||||
@property({ type: [SpriteFrame] })
|
||||
private cannonSpriteFrame: Array<SpriteFrame> = []
|
||||
// 炮塔倍数
|
||||
public cannonType: number = 1
|
||||
private _vec3Cache
|
||||
public static instance: CannonManager = null
|
||||
@property({ type: Node })
|
||||
private view: Node | null = null
|
||||
@property({ type: [SpriteFrame] })
|
||||
private cannonSpriteFrame: Array<SpriteFrame> | [] = []
|
||||
// 炮塔倍数
|
||||
public cannonType: number = 1
|
||||
private _vec3Cache: Vec3
|
||||
|
||||
onLoad() {
|
||||
this._vec3Cache = new Vec3()
|
||||
CannonManager.instance = this
|
||||
this.node.parent.on(Node.EventType.MOUSE_MOVE, this.onMeMove.bind(this))
|
||||
this.refreshCannon()
|
||||
}
|
||||
private onMeMove(event: EventMouse) {
|
||||
this.rotateCannon(event.getUILocation())
|
||||
}
|
||||
onLoad() {
|
||||
this._vec3Cache = new Vec3()
|
||||
CannonManager.instance = this
|
||||
this.node.parent.on(Node.EventType.MOUSE_MOVE, this.onMeMove.bind(this))
|
||||
this.refreshCannon()
|
||||
}
|
||||
|
||||
public rotateCannon(uilocation: Vec2) {
|
||||
let location = uilocation
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
let tran = this.node.getComponent(UITransform)
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
private onMeMove(event: EventMouse) {
|
||||
this.rotateCannon(event.getUILocation())
|
||||
}
|
||||
|
||||
let localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
this.view.getPosition(this._vec3Cache)
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
|
||||
localTouch
|
||||
)
|
||||
let rot: number = MathUtils.radiansToDegrees(rad)
|
||||
this.view.angle = rot - 90
|
||||
}
|
||||
public rotateCannon(uilocation: Vec2) {
|
||||
let location = uilocation
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
let tran = this.node.getComponent(UITransform)
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
|
||||
public refreshCannon() {
|
||||
this.view.getComponent(Sprite).spriteFrame =
|
||||
this.cannonSpriteFrame[this.cannonType - 1]
|
||||
}
|
||||
public getCannonPosition() {
|
||||
return this.view.getPosition()
|
||||
}
|
||||
onDestroy() {
|
||||
CannonManager.instance = null
|
||||
}
|
||||
let localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
this.view.getPosition(this._vec3Cache)
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
|
||||
localTouch
|
||||
)
|
||||
let rot: number = MathUtils.radiansToDegrees(rad)
|
||||
this.view.angle = rot - 90
|
||||
}
|
||||
|
||||
public refreshCannon() {
|
||||
this.view.getComponent(Sprite).spriteFrame =
|
||||
this.cannonSpriteFrame[this.cannonType - 1]
|
||||
}
|
||||
|
||||
public getCannonPosition() {
|
||||
return this.view.getPosition()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
CannonManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,6 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Node,
|
||||
Prefab,
|
||||
NodePool,
|
||||
game,
|
||||
Vec3,
|
||||
sys,
|
||||
instantiate,
|
||||
Animation,
|
||||
Vec2,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Animation, Component, game, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import FishBase from '../../../fish/script/FishBase'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
@@ -28,195 +13,198 @@ import { FishMapInfo } from '../config/FishMapInfo'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import TimeHelper from '../utils/TimeHelper'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishManager')
|
||||
export default class FishManager extends Component {
|
||||
public static instance: FishManager = null
|
||||
@property({ type: Node })
|
||||
private fishContainer: Node | null = null
|
||||
@property({ type: [Prefab] })
|
||||
public fishPrefabList: Array<Prefab> = []
|
||||
private fishPool: Array<NodePool> = []
|
||||
private fishList: Array<FishBase> = []
|
||||
private nextRandomFishTime: number = 0
|
||||
private minRandomTime: number = 2 * (game.frameRate as number)
|
||||
private maxRandomTime: number = 5 * (game.frameRate as number)
|
||||
private isFishMap: boolean = false
|
||||
private mapCount: number = 0
|
||||
private minMapCount: number = 30 * (game.frameRate as number)
|
||||
private maxMapCount: number = 60 * (game.frameRate as number)
|
||||
// // private minMapCount: number = 2 * cc.game.getFrameRate();
|
||||
// // private maxMapCount: number = 5 * cc.game.getFrameRate();
|
||||
public static instance: FishManager = null
|
||||
@property({ type: Node })
|
||||
private fishContainer: Node | null = null
|
||||
@property({ type: [Prefab] })
|
||||
public fishPrefabList: Array<Prefab> = []
|
||||
private fishPool: Array<NodePool> = []
|
||||
private fishList: Array<FishBase> = []
|
||||
private nextRandomFishTime: number = 0
|
||||
private minRandomTime: number = 2 * (game.frameRate as number)
|
||||
private maxRandomTime: number = 5 * (game.frameRate as number)
|
||||
private isFishMap: boolean = false
|
||||
private mapCount: number = 0
|
||||
private minMapCount: number = 30 * (game.frameRate as number)
|
||||
private maxMapCount: number = 60 * (game.frameRate as number)
|
||||
// // private minMapCount: number = 2 * cc.game.getFrameRate();
|
||||
// // private maxMapCount: number = 5 * cc.game.getFrameRate();
|
||||
|
||||
private _fishPosCache
|
||||
onLoad() {
|
||||
FishManager.instance = this
|
||||
this._fishPosCache = new Vec3()
|
||||
Logger.log(
|
||||
'maxRandomTime=',
|
||||
this.minRandomTime,
|
||||
this.maxRandomTime,
|
||||
game.frameRate
|
||||
)
|
||||
}
|
||||
private _fishPosCache: Vec3
|
||||
|
||||
start() {
|
||||
this.randomFish()
|
||||
}
|
||||
onLoad() {
|
||||
FishManager.instance = this
|
||||
this._fishPosCache = new Vec3()
|
||||
Logger.log(
|
||||
'maxRandomTime=',
|
||||
this.minRandomTime,
|
||||
this.maxRandomTime,
|
||||
game.frameRate
|
||||
)
|
||||
}
|
||||
|
||||
update() {
|
||||
this.checkRandomFish()
|
||||
this.checkFishMoveEnd()
|
||||
this.checkFishMap()
|
||||
}
|
||||
start() {
|
||||
this.randomFish()
|
||||
}
|
||||
|
||||
private checkFishMap() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.mapCount > 0) {
|
||||
this.mapCount--
|
||||
if (this.mapCount <= 0) {
|
||||
FishUI.instance.playWaveEffect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update() {
|
||||
this.checkRandomFish()
|
||||
this.checkFishMoveEnd()
|
||||
this.checkFishMap()
|
||||
}
|
||||
|
||||
private checkRandomFish() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.nextRandomFishTime > 0) {
|
||||
this.nextRandomFishTime--
|
||||
if (this.nextRandomFishTime == 0) {
|
||||
this.randomFish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private checkFishMap() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.mapCount > 0) {
|
||||
this.mapCount--
|
||||
if (this.mapCount <= 0) {
|
||||
FishUI.instance.playWaveEffect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private checkFishMoveEnd() {
|
||||
for (let i = this.fishList.length - 1; i >= 0; i--) {
|
||||
let fish: FishBase = this.fishList[i]
|
||||
if (this.isFishMap) {
|
||||
if (!fish.isDead) {
|
||||
fish.node.getPosition(this._fishPosCache)
|
||||
this._fishPosCache.x -= 2
|
||||
fish.node.setPosition(this._fishPosCache)
|
||||
if (this._fishPosCache.x <= -screen.width / 2) {
|
||||
//winSize.width
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
} else if (!fish.getComponent(FishMover).isMoving) {
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
private checkRandomFish() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.nextRandomFishTime > 0) {
|
||||
this.nextRandomFishTime--
|
||||
if (this.nextRandomFishTime == 0) {
|
||||
this.randomFish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private checkEndFishMap() {
|
||||
Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
|
||||
if (this.isFishMap && this.fishList.length <= 0) {
|
||||
this.isFishMap = false
|
||||
this.randomFish()
|
||||
}
|
||||
}
|
||||
private checkFishMoveEnd() {
|
||||
for (let i = this.fishList.length - 1; i >= 0; i--) {
|
||||
let fish: FishBase = this.fishList[i]
|
||||
if (this.isFishMap) {
|
||||
if (!fish.isDead) {
|
||||
fish.node.getPosition(this._fishPosCache)
|
||||
this._fishPosCache.x -= 2
|
||||
fish.node.setPosition(this._fishPosCache)
|
||||
if (this._fishPosCache.x <= -screen.width / 2) {
|
||||
//winSize.width
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
} else if (!fish.getComponent(FishMover).isMoving) {
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private randomFish() {
|
||||
if (this.isFishMap) return
|
||||
let randomNum: number = RandomUtil.nextInt(1, 10)
|
||||
// let randomNum: number = RandomUtil.nextInt(1, 1);
|
||||
for (let i = 0; i < randomNum; i++) {
|
||||
let fishType: number = RandomUtil.nextInt(1, 29)
|
||||
// let fishType: number = RandomUtil.nextInt(1, 1);
|
||||
let fish: FishBase = this.createFishByType(fishType)
|
||||
fish.fishPathInfo = FishPathConfig.randomPathInfo()
|
||||
this._fishPosCache.z = 0
|
||||
this._fishPosCache.x = fish.fishPathInfo.path[0].x
|
||||
this._fishPosCache.y = fish.fishPathInfo.path[0].y
|
||||
fish.node.setPosition(this._fishPosCache)
|
||||
fish.getComponent(FishMover).bezierPList = fish.fishPathInfo.path
|
||||
fish.getComponent(FishMover).startMove()
|
||||
this.fishList.push(fish)
|
||||
this.fishContainer.addChild(fish.node)
|
||||
}
|
||||
Logger.log('checkFishMoveEnd=randomFish=', this.fishList)
|
||||
this.nextRandomFishTime = RandomUtil.nextInt(
|
||||
this.minRandomTime,
|
||||
this.maxRandomTime
|
||||
)
|
||||
if (this.mapCount <= 0) {
|
||||
this.mapCount = RandomUtil.nextInt(this.minMapCount, this.maxMapCount)
|
||||
}
|
||||
}
|
||||
private checkEndFishMap() {
|
||||
Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
|
||||
if (this.isFishMap && this.fishList.length <= 0) {
|
||||
this.isFishMap = false
|
||||
this.randomFish()
|
||||
}
|
||||
}
|
||||
|
||||
public createFishByType(fishType: number): FishBase {
|
||||
let fishNode: Node
|
||||
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
|
||||
fishNode = this.fishPool[fishType - 1].get()
|
||||
} else {
|
||||
fishNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
}
|
||||
//fishNode.getComponent(Animation).play() //v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(fishNode, () =>
|
||||
fishNode.getComponent(Animation).play()
|
||||
)
|
||||
let fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
|
||||
fishNode.getComponent(FishBase).fishInfo = fishInfo
|
||||
fishNode.getComponent(FishBase).fishType = fishType
|
||||
fishNode.getComponent(FishBase).blood = fishInfo.blood
|
||||
fishNode.getComponent(FishBase).isDead = false
|
||||
return fishNode.getComponent(FishBase)
|
||||
}
|
||||
private randomFish() {
|
||||
if (this.isFishMap) return
|
||||
let randomNum: number = RandomUtil.nextInt(1, 10)
|
||||
// let randomNum: number = RandomUtil.nextInt(1, 1);
|
||||
for (let i = 0; i < randomNum; i++) {
|
||||
let fishType: number = RandomUtil.nextInt(1, 29)
|
||||
// let fishType: number = RandomUtil.nextInt(1, 1);
|
||||
let fish: FishBase = this.createFishByType(fishType)
|
||||
fish.fishPathInfo = FishPathConfig.randomPathInfo()
|
||||
this._fishPosCache.z = 0
|
||||
this._fishPosCache.x = fish.fishPathInfo.path[0].x
|
||||
this._fishPosCache.y = fish.fishPathInfo.path[0].y
|
||||
fish.node.setPosition(this._fishPosCache)
|
||||
fish.getComponent(FishMover).bezierPList = fish.fishPathInfo.path
|
||||
fish.getComponent(FishMover).startMove()
|
||||
this.fishList.push(fish)
|
||||
this.fishContainer.addChild(fish.node)
|
||||
}
|
||||
Logger.log('checkFishMoveEnd=randomFish=', this.fishList)
|
||||
this.nextRandomFishTime = RandomUtil.nextInt(
|
||||
this.minRandomTime,
|
||||
this.maxRandomTime
|
||||
)
|
||||
if (this.mapCount <= 0) {
|
||||
this.mapCount = RandomUtil.nextInt(this.minMapCount, this.maxMapCount)
|
||||
}
|
||||
}
|
||||
|
||||
public killFish(fish: FishBase) {
|
||||
let index: number = this.fishList.indexOf(fish)
|
||||
if (index >= 0) {
|
||||
// console.log("鱼挂了")
|
||||
GameMusicHelper.playFishDead(fish.fishType)
|
||||
fish.node.getPosition(this._fishPosCache)
|
||||
let vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
|
||||
ScoreManager.instance.addScore(fish.fishInfo.blood, vec2)
|
||||
this.fishList.splice(index, 1)
|
||||
this.destroyFish(fish)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
public createFishByType(fishType: number): FishBase {
|
||||
let fishNode: Node
|
||||
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
|
||||
fishNode = this.fishPool[fishType - 1].get()
|
||||
} else {
|
||||
fishNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
}
|
||||
//fishNode.getComponent(Animation).play() //v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(fishNode, () =>
|
||||
fishNode.getComponent(Animation).play()
|
||||
)
|
||||
let fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
|
||||
fishNode.getComponent(FishBase).fishInfo = fishInfo
|
||||
fishNode.getComponent(FishBase).fishType = fishType
|
||||
fishNode.getComponent(FishBase).blood = fishInfo.blood
|
||||
fishNode.getComponent(FishBase).isDead = false
|
||||
return fishNode.getComponent(FishBase)
|
||||
}
|
||||
|
||||
private destroyFish(fish: FishBase) {
|
||||
if (!this.fishPool[fish.fishType - 1]) {
|
||||
this.fishPool[fish.fishType - 1] = new NodePool()
|
||||
}
|
||||
this.fishPool[fish.fishType - 1].put(fish.node)
|
||||
}
|
||||
public killFish(fish: FishBase) {
|
||||
let index: number = this.fishList.indexOf(fish)
|
||||
if (index >= 0) {
|
||||
// console.log("鱼挂了")
|
||||
GameMusicHelper.playFishDead(fish.fishType)
|
||||
fish.node.getPosition(this._fishPosCache)
|
||||
let vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
|
||||
ScoreManager.instance.addScore(fish.fishInfo.blood, vec2)
|
||||
this.fishList.splice(index, 1)
|
||||
this.destroyFish(fish)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
|
||||
public playFishMap() {
|
||||
this.isFishMap = true
|
||||
for (let i = this.fishList.length - 1; i >= 0; i--) {
|
||||
let fish: FishBase = this.fishList[i]
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
}
|
||||
}
|
||||
private destroyFish(fish: FishBase) {
|
||||
if (!this.fishPool[fish.fishType - 1]) {
|
||||
this.fishPool[fish.fishType - 1] = new NodePool()
|
||||
}
|
||||
this.fishPool[fish.fishType - 1].put(fish.node)
|
||||
}
|
||||
|
||||
public startFishMap() {
|
||||
// this.playFishMap();
|
||||
// this.fishList = [];
|
||||
public playFishMap() {
|
||||
this.isFishMap = true
|
||||
for (let i = this.fishList.length - 1; i >= 0; i--) {
|
||||
let fish: FishBase = this.fishList[i]
|
||||
this.destroyFish(fish)
|
||||
this.fishList.splice(i, 1)
|
||||
}
|
||||
}
|
||||
|
||||
let map: FishMap = FishPathConfig.randomFishMap()
|
||||
let fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
|
||||
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
|
||||
for (let i = 0; i < fishMapInfoList.length; i++) {
|
||||
let fishMapInfo: FishMapInfo = fishMapInfoList[i]
|
||||
let fish: FishBase = this.createFishByType(fishMapInfo.fishType)
|
||||
fish.node.angle = 0
|
||||
// fish.node.setScale(fishMapInfo.scale);
|
||||
this.fishContainer.addChild(fish.node)
|
||||
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
|
||||
this.fishList.push(fish)
|
||||
}
|
||||
}
|
||||
public startFishMap() {
|
||||
// this.playFishMap();
|
||||
// this.fishList = [];
|
||||
|
||||
onDestroy() {
|
||||
FishManager.instance = null
|
||||
}
|
||||
let map: FishMap = FishPathConfig.randomFishMap()
|
||||
let fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
|
||||
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
|
||||
for (let i = 0; i < fishMapInfoList.length; i++) {
|
||||
let fishMapInfo: FishMapInfo = fishMapInfoList[i]
|
||||
let fish: FishBase = this.createFishByType(fishMapInfo.fishType)
|
||||
fish.node.angle = 0
|
||||
// fish.node.setScale(fishMapInfo.scale);
|
||||
this.fishContainer.addChild(fish.node)
|
||||
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
|
||||
this.fishList.push(fish)
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,45 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Prefab,
|
||||
NodePool,
|
||||
Vec2,
|
||||
instantiate,
|
||||
Vec3,
|
||||
Node,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import FishNetBase from '../../../fish/script/FishNetBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishNetManager')
|
||||
export default class FishNetManager extends Component {
|
||||
public static instance: FishNetManager = null
|
||||
@property({ type: [Prefab] })
|
||||
private netPrefabList: Prefab[] = []
|
||||
private fishNetPool: Array<NodePool> = []
|
||||
onLoad() {
|
||||
FishNetManager.instance = this
|
||||
}
|
||||
public static instance: FishNetManager = null
|
||||
@property({ type: [Prefab] })
|
||||
private netPrefabList: Prefab[] | [] = []
|
||||
private fishNetPool: Array<NodePool> = []
|
||||
|
||||
public addFishNet(netType: number, p: Vec2) {
|
||||
let fishNet: FishNetBase = this.createFishNet(netType)
|
||||
this.node.addChild(fishNet.node)
|
||||
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
fishNet.playMv()
|
||||
}
|
||||
onLoad() {
|
||||
FishNetManager.instance = this
|
||||
}
|
||||
|
||||
private createFishNet(netType: number) {
|
||||
let fishNetNode: Node
|
||||
if (this.fishNetPool[netType] && this.fishNetPool[netType].size() > 0) {
|
||||
fishNetNode = this.fishNetPool[netType].get()
|
||||
} else {
|
||||
fishNetNode = instantiate(this.netPrefabList[netType])
|
||||
}
|
||||
fishNetNode.getComponent(FishNetBase).netType = netType
|
||||
return fishNetNode.getComponent(FishNetBase)
|
||||
}
|
||||
public addFishNet(netType: number, p: Vec2) {
|
||||
let fishNet: FishNetBase = this.createFishNet(netType)
|
||||
this.node.addChild(fishNet.node)
|
||||
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
fishNet.playMv()
|
||||
}
|
||||
|
||||
public destroyFishNet(fishNet: FishNetBase) {
|
||||
if (!this.fishNetPool[fishNet.netType]) {
|
||||
this.fishNetPool[fishNet.netType] = new NodePool()
|
||||
}
|
||||
this.fishNetPool[fishNet.netType].put(fishNet.node)
|
||||
}
|
||||
private createFishNet(netType: number) {
|
||||
let fishNetNode: Node
|
||||
if (this.fishNetPool[netType] && this.fishNetPool[netType].size() > 0) {
|
||||
fishNetNode = this.fishNetPool[netType].get()
|
||||
} else {
|
||||
fishNetNode = instantiate(this.netPrefabList[netType])
|
||||
}
|
||||
fishNetNode.getComponent(FishNetBase).netType = netType
|
||||
return fishNetNode.getComponent(FishNetBase)
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishNetManager.instance = null
|
||||
}
|
||||
public destroyFishNet(fishNet: FishNetBase) {
|
||||
if (!this.fishNetPool[fishNet.netType]) {
|
||||
this.fishNetPool[fishNet.netType] = new NodePool()
|
||||
}
|
||||
this.fishNetPool[fishNet.netType].put(fishNet.node)
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishNetManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,51 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Prefab,
|
||||
NodePool,
|
||||
Vec2,
|
||||
instantiate,
|
||||
Node,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
|
||||
import ScorePrefab from '../prefab/ScorePrefab'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ScoreManager')
|
||||
export default class ScoreManager extends Component {
|
||||
public static instance: ScoreManager = null
|
||||
@property({ type: Prefab })
|
||||
private scrorePrefab: Prefab | null = null
|
||||
private scorePool: NodePool
|
||||
onLoad() {
|
||||
ScoreManager.instance = this
|
||||
this.scorePool = new NodePool()
|
||||
}
|
||||
public static instance: ScoreManager = null
|
||||
@property({ type: Prefab })
|
||||
private scrorePrefab: Prefab | null = null
|
||||
private scorePool: NodePool
|
||||
|
||||
public addScore(score: number, p: Vec2) {
|
||||
let scorePrefab: ScorePrefab = this.createScore(score)
|
||||
this.node.addChild(scorePrefab.node)
|
||||
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
scorePrefab.init(score)
|
||||
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
|
||||
this.destroyScore(scorePrefab)
|
||||
FishUI.instance.jf_score += score
|
||||
FishUI.instance.refreshScore()
|
||||
})
|
||||
}
|
||||
onLoad() {
|
||||
ScoreManager.instance = this
|
||||
this.scorePool = new NodePool()
|
||||
}
|
||||
|
||||
private createScore(score: number): ScorePrefab {
|
||||
let scoreNode: Node
|
||||
if (this.scorePool && this.scorePool.size() > 0) {
|
||||
scoreNode = this.scorePool.get()
|
||||
} else {
|
||||
scoreNode = instantiate(this.scrorePrefab)
|
||||
}
|
||||
return scoreNode.getComponent(ScorePrefab)
|
||||
}
|
||||
public addScore(score: number, p: Vec2) {
|
||||
let scorePrefab: ScorePrefab = this.createScore(score)
|
||||
this.node.addChild(scorePrefab.node)
|
||||
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
scorePrefab.init(score)
|
||||
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
|
||||
this.destroyScore(scorePrefab)
|
||||
FishUI.instance.jf_score += score
|
||||
FishUI.instance.refreshScore()
|
||||
})
|
||||
}
|
||||
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
private createScore(score: number): ScorePrefab {
|
||||
let scoreNode: Node
|
||||
if (this.scorePool && this.scorePool.size() > 0) {
|
||||
scoreNode = this.scorePool.get()
|
||||
} else {
|
||||
scoreNode = instantiate(this.scrorePrefab)
|
||||
}
|
||||
return scoreNode.getComponent(ScorePrefab)
|
||||
}
|
||||
|
||||
onDisable() {}
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
}
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user