import { BlockType } from "./Block"; // 主游戏控制类 const {ccclass, property} = cc._decorator; @ccclass export default class GameManager extends cc.Component { @property(cc.Node) Map: cc.Node = null; @property(cc.Prefab) Block: cc.Prefab = null; countTime: number; block_Array: any; path_Array: any; map_Array: any; onLoad () { } start () { this.fit(); this.init(); } //初始化数据 init(){ this.initMap(); } //初始化地图 initMap(){ this.block_Array = []; this.path_Array = []; this.map_Array = []; this.map_Array = cc.fx.GameConfig.LEVEL_INFO[0][0].map; //将地图x,y轴切换 for(let m=0;m 0){ //用于判断此点的上一个点,是为了判断当前方块洪水七点,以及下一个移动方向,判断洪终点方向 let nextX = this.path_Array[order+1].x - this.path_Array[order].x; let nextY = this.path_Array[order].y - this.path_Array[order+1].y let previousX = this.path_Array[order].x - this.path_Array[order-1].x; let previousY = this.path_Array[order-1].y - this.path_Array[order].y; if(previousX == 0 && previousY == 1){ if(nextX == 0){ if(nextY == 1)name = "up"; else if(nextY == -1) name = "err"; } else if(nextX == 1) name = "up_right"; else if(nextX == -1) name = "up_left"; } else if(previousX == 0 && previousY == -1){ if(nextX == 0){ if(nextY == 1)name = "err"; else if(nextY == -1) name = "down"; } else if(nextX == 1) name = "down_right"; else if(nextX == -1) name = "down_left"; } else if(previousX == 1 && previousY == 0){ if(nextX == 0){ if(nextY == 1)name = "right_up"; else if(nextY == -1) name = "right_down"; } else if(nextX == 1) name = "right"; else if(nextX == -1) name = "err"; } else if(previousX == -1 && previousY == 0){ if(nextX == 0){ if(nextY == 1)name = "left_up"; else if(nextY == -1) name = "left_down"; } else if(nextX == 1) name = "err"; else if(nextX == -1) name = "left"; } } return name ; } //根据是否全面屏,做独立适配方面 fit(){ var jg = this.setFit(); if(!jg){ } } //判断全面屏 getSetScreenResolutionFlag () { let size = cc.winSize; let width = size.width; let height = size.height; if ((height / width) > (16.2 / 9)) return false; return true; } //判断全面屏适配 setFit () { let flag = this.getSetScreenResolutionFlag(); if (flag) { } else { } return flag; } //返回首页 backScene(){ cc.director.loadScene("LoadScene"); } //下一关,或者重新开始,或者返回上一关,根据level决定 reStart(type){ } //获取时间戳 getTime(){ const timestamp = new Date().getTime(); return timestamp; } //获胜 passLevel(){ } //失败 loseLevel(type){ //1: 1649 //2: 3646 //3: 5546 //4: 2600 //5: 694 } //开始游戏 startGame(data){ this.setMap(data); } //如果是倒计时 调用此方法 updateCountDownTime () { if (this.countTime > 0) { this.countTime -= 1; // this.time.string = cc.fx.GameTool.getTimeMargin(this.countTime); if(this.countTime < 5){ let over = this.node.getChildByName("Over"); cc.tween(over) .to(0.2,{opacity:255}) .delay(0.1) .to(0.2,{opacity:0}) .start(); } if(this.countTime <= 0){ this.unschedule(this.updateCountDownTime); var time = 0; this.gameOver(time); } } } //上传每次操作数据 setData(){ cc.fx.GameTool.setGameData(); } //上传排行榜数据 gameOver(time){ cc.fx.GameTool.setRank(time); this.node.getChildByName("GameOver").active = true; this.node.getChildByName("GameOver").opacity = 0; cc.tween(this.node.getChildByName("GameOver")) .to(0.4,{opacity:255}) .delay(2) .to(0.4,{opacity:50}) .call(() =>{ cc.director.loadScene("OverScene"); }) .start() } clickSun(data){ } nextWater(){ } onEnable () { cc.fx.Notifications.on(cc.fx.Message.control, this.clickSun, this); cc.fx.Notifications.on(cc.fx.Message.next, this.runWater, this); cc.fx.Notifications.on(cc.fx.Message.startGame, this.startGame, this); } onDisable () { cc.fx.Notifications.off(cc.fx.Message.control, this.clickSun); cc.fx.Notifications.off(cc.fx.Message.next, this.runWater); cc.fx.Notifications.off(cc.fx.Message.startGame, this.startGame); } update (dt) { } }