|
@@ -9,6 +9,9 @@ import { BuildEnemys } from './BuildEnemys';
|
|
|
import { autoBind } from '../extend/AutoBind';
|
|
|
import { BaseExp } from '../core/base/BaseExp';
|
|
|
import { PoolManager } from '../core/manager/PoolManager';
|
|
|
+import { uiMgr } from '../core/manager/UIManager';
|
|
|
+import { Constants } from '../data/Constants';
|
|
|
+import { Main } from './Main';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('Game')
|
|
@@ -45,35 +48,48 @@ export class Game extends BaseExp {
|
|
|
this.canvas.active = true;
|
|
|
this.map_pos.active = true;
|
|
|
//加载map
|
|
|
- this.loadMap(userIns.getCurLevelData().map);
|
|
|
+ this.loadMap();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 下一关
|
|
|
*/
|
|
|
public nextLevel(){
|
|
|
-
|
|
|
+ userIns.data.level += 1;
|
|
|
+ //加载新的map
|
|
|
+ this.loadMap();
|
|
|
+ //刷新新的任务
|
|
|
+ uiMgr.getPageComponent(Constants.mainUIs.main).loadData();
|
|
|
+ this.isGameOver = this.isPause = false;
|
|
|
+ //加载敌人
|
|
|
+ this.buildEnemys.loadLevelEnemys();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 重玩
|
|
|
*/
|
|
|
public restart(){
|
|
|
- //this.loadMap(userIns.getCurLevelData().map);
|
|
|
+ this.isGameOver = this.isPause = false;
|
|
|
+ //加载敌人
|
|
|
+ this.buildEnemys.loadLevelEnemys();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 加载map
|
|
|
*/
|
|
|
- public loadMap(name: string){
|
|
|
- if(Utils.isNull(name))return;
|
|
|
- if(this.map){
|
|
|
- if(this.map.name === name)return;
|
|
|
- PoolManager.putNode(this.map.node);
|
|
|
- this.map = null!;
|
|
|
+ public loadMap(){
|
|
|
+ const name: string = userIns.getCurLevelData().map;
|
|
|
+ if(Utils.isNull(name)
|
|
|
+ ||(this.map && this.map.name == name)){
|
|
|
+ return;
|
|
|
}
|
|
|
Logger.log(`加载地图:${name}`);
|
|
|
ResUtil.loadRes(`map/${name}`).then((map:Node)=>{
|
|
|
+ //把旧的地图回收
|
|
|
+ if(this.map){
|
|
|
+ PoolManager.putNode(this.map.node);
|
|
|
+ this.map = null!;
|
|
|
+ }
|
|
|
map.parent = this.map_pos.parent;
|
|
|
map.worldPosition = this.map_pos.worldPosition;
|
|
|
this.map = map.getComponent(GMap);
|
|
@@ -82,7 +98,7 @@ export class Game extends BaseExp {
|
|
|
//玩家组建
|
|
|
this.player = this.map.getComponentInChildren(Player);
|
|
|
//主角摄像机
|
|
|
- let cameraNode: Node = Utils.findName(map, 'mainCamera');
|
|
|
+ const cameraNode: Node = Utils.findName(map, 'mainCamera');
|
|
|
this.camera = cameraNode.getComponent(Camera);
|
|
|
});
|
|
|
}
|