BattleManager.ts
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { SaveDataManager } from "../../component/SaveDataManager";
import { PhysicsControl } from "../physics/PhysicsControl";
import { Battle } from "./Battle";
import { BattleEvent, getGlobalNode } from "./BattleConst";
export class BattleManager extends cc.Component {
private static _ins: BattleManager;
static get ins(): BattleManager {
if (this._ins == null) {
this._ins = getGlobalNode().addComponent(BattleManager);
getGlobalNode().addChild(this._ins.eventNode);
// this._ins.eventNode.event
}
return this._ins;
}
private _curBattle: Battle;
get curBattle(): Battle { return this._curBattle; }
private _eventNode: cc.Node = new cc.Node("battleManagerEventNode");
/**事件节点,BattleEvent的派发和监听都在此节点进行 */
get eventNode(): cc.Node { return this._eventNode; }
private _paused: boolean = false;
get paused(): boolean { return this._paused; }
set paused(value: boolean) {
this._paused = value;
if (this.curBattle && this.curBattle.roundRunning) {
// PhysicsControl.ins.setPhysicsEnable(!value);
}
}
/**是否可以滑动控制发射指示器 */
shootTouchEnable: boolean = false;
// private _prefabCollection:cc.Prefab
startBattle(levelId: number, callBack: Function, thisObj: any, prefab: cc.Prefab) {
this.shootTouchEnable = false;
this._paused = false;
if (this.curBattle) {
//销毁
this._curBattle.destroy();
this._curBattle = null;
}
this._curBattle = new Battle();
this._curBattle.init(levelId, () => {
callBack.call(thisObj);
}, this, prefab);
this.eventNode.emit(BattleEvent.BATTLE_START);
}
/**直接离开战斗,不会触发战斗结算 */
leaveBattle() {
//#region 恢复试用数据
SaveDataManager.ins.runtimeData.ballSkinTry = 0;
SaveDataManager.ins.runtimeData.goldenAimTry = false;
SaveDataManager.ins.saveData();
//#endregion
this._curBattle.destroy();
this._curBattle = null;
}
protected update(dt: number): void {
// super.update(dt);
if (this._curBattle && !this._paused) {
this._curBattle.update(dt);
}
}
}