import { _decorator,Camera,Node} from 'cc'; import { GMap } from './GMap'; import { Player } from './Player'; import { Utils } from '../utils/Utils'; import { Logger } from '../extend/Logger'; import { ResUtil } from '../utils/ResUtil'; import { userIns } from '../data/UserData'; import { BuildEnemys } from './BuildEnemys'; import { autoBind } from '../extend/AutoBind'; import { BaseExp } from '../core/base/BaseExp'; import { PoolManager } from '../core/manager/PoolManager'; const { ccclass, property } = _decorator; @ccclass('Game') export class Game extends BaseExp { public static I: Game; @autoBind({type: Node,tooltip: "map节点的位置"}) public map_pos: Node = null!; /*是否暂停游戏*/ public isPause: boolean = false; /**是否游戏结束*/ public _isGameOver: boolean = false; public set isGameOver(value: boolean) { if(value){this.gameEnd();} this._isGameOver = value; } public get isGameOver(){ return this._isGameOver; } //当前地图场景 public map: GMap = null!; //创建敌人的组建 public buildEnemys: BuildEnemys = null!; //玩家组建 public player: Player = null!; //主角摄像机 public camera: Camera = null!; //Canvas2D节点 public canvas: Node = null!; start() { Game.I = this; this.canvas = this.node.parent.getChildByName('Canvas') this.canvas.active = true; this.map_pos.active = true; //加载map this.loadMap(userIns.getCurLevelData().map); } /** * 加载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!; } Logger.log(`加载地图:${name}`); ResUtil.loadRes(`map/${name}`).then((map:Node)=>{ map.parent = this.map_pos.parent; map.worldPosition = this.map_pos.worldPosition; this.map = map.getComponent(GMap); //创建敌人的组建 this.buildEnemys = this.map.getComponent(BuildEnemys); //玩家组建 this.player = this.map.getComponentInChildren(Player); //主角摄像机 let cameraNode: Node = Utils.findName(map, 'mainCamera'); this.camera = cameraNode.getComponent(Camera); }); } /** * 游戏结束回收 */ public gameEnd(){ this.buildEnemys.recycle(); } }