832 lines
34 KiB
JavaScript
832 lines
34 KiB
JavaScript
"use strict";
|
||
cc._RF.push(module, 'b0432BA295DjIOcuitdGKO1', 'GameManager');
|
||
// Script/GameManager.ts
|
||
|
||
"use strict";
|
||
var __extends = (this && this.__extends) || (function () {
|
||
var extendStatics = function (d, b) {
|
||
extendStatics = Object.setPrototypeOf ||
|
||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||
return extendStatics(d, b);
|
||
};
|
||
return function (d, b) {
|
||
extendStatics(d, b);
|
||
function __() { this.constructor = d; }
|
||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||
};
|
||
})();
|
||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||
};
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
var Block_1 = require("./Block");
|
||
// 主游戏控制类
|
||
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
|
||
var GameManager = /** @class */ (function (_super) {
|
||
__extends(GameManager, _super);
|
||
function GameManager() {
|
||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||
_this.Map = null;
|
||
_this.Block = null;
|
||
_this.Time = null;
|
||
_this.Countdown = null;
|
||
return _this;
|
||
}
|
||
GameManager.prototype.onLoad = function () {
|
||
};
|
||
GameManager.prototype.start = function () {
|
||
this.fit();
|
||
this.init();
|
||
};
|
||
//初始化数据
|
||
GameManager.prototype.init = function () {
|
||
this.initMap();
|
||
this.countTime = cc.fx.GameConfig.TIME_INFO.totalTime;
|
||
this.waterTime = cc.fx.GameConfig.TIME_INFO.waterTime[cc.fx.GameConfig.GM_INFO.level];
|
||
var head = this.node.getChildByName("Top").getChildByName("head");
|
||
var progress = this.node.getChildByName("Top").getChildByName("progress").getComponent(cc.Sprite);
|
||
head.runAction(cc.moveTo(this.waterTime, cc.v2(310, head.y)));
|
||
this.waterTween = cc.tween(progress)
|
||
.to(this.waterTime, { fillRange: 1 })
|
||
.start();
|
||
this.schedule(this.updateWaterTime, 1);
|
||
this.schedule(this.updateCountDownTime, 1);
|
||
};
|
||
//初始化地图`
|
||
GameManager.prototype.initMap = function () {
|
||
this.block_Array = [];
|
||
this.path_Array = [];
|
||
this.water_Array = [];
|
||
this.map_Array = [];
|
||
this.plan_over = false;
|
||
this.map_Hight = 0;
|
||
this.map_Width = 0;
|
||
var number = 10; //9
|
||
number = Math.floor(Math.random() * cc.fx.GameConfig.LEVEL_INFO[cc.fx.GameConfig.GM_INFO.level].length);
|
||
// number = 1;
|
||
var arr = cc.fx.GameConfig.LEVEL_INFO[cc.fx.GameConfig.GM_INFO.level][number].map;
|
||
debugger;
|
||
this.node.getChildByName("Top").getChildByName("id").getComponent(cc.Label).string =
|
||
cc.fx.GameConfig.LEVEL_INFO[cc.fx.GameConfig.GM_INFO.level][number].id;
|
||
//将地图x,y轴切换
|
||
this.map_Array = arr[0].map(function (item, i) {
|
||
return arr.map(function (val) { return val[i]; });
|
||
});
|
||
this.map_Width = this.map_Array.length;
|
||
this.map_Hight = this.map_Array[0].length;
|
||
this.Map.x = (6 - this.map_Array.length) * 48;
|
||
this.Map.y = (this.map_Array[0].length - 6.5) * 48;
|
||
for (var i = 0; i < this.map_Array.length; i++) {
|
||
for (var j = 0; j < this.map_Array[i].length; j++) {
|
||
var block = cc.instantiate(this.Block);
|
||
block.parent = this.Map;
|
||
block.getComponent("Block").initData(this.map_Array[i][j], cc.v2(i, j), cc.v2(this.map_Width, this.map_Hight));
|
||
if (this.map_Array[i][j] == cc.Enum(Block_1.BlockType).Start) {
|
||
this.path_Array.push(cc.v3(i, j, cc.Enum(Block_1.BlockType).Nomal));
|
||
// this.water_Array.push(cc.v3(i,j,cc.Enum(BlockType).Nomal));
|
||
}
|
||
block.setPosition(cc.v2(-block.width * 2.5 + i * block.width, block.height * 4 - j * block.height));
|
||
this.block_Array.push(block);
|
||
}
|
||
}
|
||
};
|
||
//开始后,按玩家操作,将路径中地图块放入数组中
|
||
GameManager.prototype.setMap = function (data) {
|
||
for (var i = 0; i < data.length; i++) {
|
||
var start = this.path_Array[this.path_Array.length - 1];
|
||
switch (data[i]) {
|
||
case "up":
|
||
this.path_Array.push(cc.v3(start.x, start.y - 1, cc.Enum(Block_1.BlockType).Nomal));
|
||
break;
|
||
case "down":
|
||
this.path_Array.push(cc.v3(start.x, start.y + 1, cc.Enum(Block_1.BlockType).Nomal));
|
||
break;
|
||
case "left":
|
||
this.path_Array.push(cc.v3(start.x - 1, start.y, cc.Enum(Block_1.BlockType).Nomal));
|
||
break;
|
||
case "right":
|
||
this.path_Array.push(cc.v3(start.x + 1, start.y, cc.Enum(Block_1.BlockType).Nomal));
|
||
break;
|
||
case "reinforce":
|
||
this.path_Array.push(cc.v3(start.x, start.y, cc.Enum(Block_1.BlockType).Reinforce));
|
||
break;
|
||
case "soil":
|
||
this.path_Array.push(cc.v3(start.x, start.y, cc.Enum(Block_1.BlockType).Xi_Soil));
|
||
break;
|
||
}
|
||
}
|
||
this.runRoad(0);
|
||
};
|
||
//开始执行洪峰来了的动画
|
||
GameManager.prototype.runRoad = function (order) {
|
||
var _this = this;
|
||
order = parseInt(order);
|
||
if (order > 0) {
|
||
if (this.path_Array[order - 1].z == 0) {
|
||
console.log("1正常放入", this.path_Array[order - 1].x, this.path_Array[order - 1].y, this.path_Array[order - 1].z);
|
||
this.changeWater(cc.v3(this.path_Array[order - 1].x, this.path_Array[order - 1].y, 0));
|
||
// console.log(this.water_Array);
|
||
// debugger;
|
||
if (order == this.path_Array.length - 1) {
|
||
this.changeWater(cc.v3(this.path_Array[order].x, this.path_Array[order].y, 0));
|
||
console.log("最后放入", this.path_Array[order].x, this.path_Array[order].y);
|
||
// console.log(this.water_Array);
|
||
}
|
||
}
|
||
else {
|
||
console.log("2插入", this.path_Array[order].x, this.path_Array[order].y, this.path_Array[order].z);
|
||
this.changeWater(cc.v3(this.path_Array[order].x, this.path_Array[order].y, 0));
|
||
}
|
||
}
|
||
if (order <= this.path_Array.length - 1) {
|
||
var i = this.path_Array[order].x * this.map_Array[0].length + this.path_Array[order].y;
|
||
var direction = "";
|
||
var circulate = true;
|
||
//最后一步结束
|
||
if (order == this.path_Array.length - 1) {
|
||
circulate = false;
|
||
direction = "End";
|
||
setTimeout(function () {
|
||
if (!_this.plan_over) {
|
||
console.log("准备出水");
|
||
_this.plan_over = true;
|
||
var head = _this.node.getChildByName("Top").getChildByName("head");
|
||
var progress = _this.node.getChildByName("Top").getChildByName("progress").getComponent(cc.Sprite);
|
||
head.stopAllActions();
|
||
head.setPosition(310, head.y);
|
||
_this.waterTween.stop();
|
||
progress.fillRange = 1;
|
||
_this.runWater(0);
|
||
}
|
||
}, 500);
|
||
}
|
||
else {
|
||
if (this.path_Array[order].z == 6 && order + 1 < this.path_Array.length) {
|
||
direction = "Reinforce";
|
||
i = this.path_Array[order + 1].x * this.map_Array[0].length + this.path_Array[order + 1].y;
|
||
}
|
||
else if (order + 1 < this.path_Array.length) {
|
||
if (this.path_Array[order + 1].z == 5) {
|
||
direction = "Xi_Soil";
|
||
}
|
||
else if (this.path_Array[order + 1].z == 6 && order == 0) {
|
||
direction = "Reinforce";
|
||
}
|
||
else {
|
||
direction = this.getDirection(order, this.path_Array);
|
||
}
|
||
}
|
||
else {
|
||
direction = this.getDirection(order, this.path_Array);
|
||
}
|
||
}
|
||
// console.log(order,this.path_Array[order].x,this.path_Array[order].y,i);
|
||
// console.log("步骤:",order,"方向",direction);
|
||
var jg = this.getBoundary(order, this.path_Array[order].x, this.path_Array[order].y, direction, this.path_Array);
|
||
if (direction == "" || jg == false)
|
||
return;
|
||
var target = this.block_Array[i].getComponent("Block");
|
||
target.setPath(direction);
|
||
if (order > 0 && order < this.path_Array.length - 1) {
|
||
if (this.path_Array[order + 1].z == 5) {
|
||
this.set_Soil(order + 1, this.path_Array, "road");
|
||
circulate = false;
|
||
return;
|
||
}
|
||
else if (order == 1 && this.path_Array[order].z == 5) {
|
||
this.set_Soil(order, this.path_Array, "road");
|
||
circulate = false;
|
||
return;
|
||
}
|
||
}
|
||
var pos = cc.v2();
|
||
if (direction == "End" && this.path_Array[order - 1].z == 0) {
|
||
pos = cc.v2(this.path_Array[order - 1].x, this.path_Array[order - 1].y);
|
||
}
|
||
var data = {
|
||
order: order,
|
||
time: cc.fx.GameConfig.TIME_INFO.waterSpeed[cc.fx.GameConfig.GM_INFO.level],
|
||
type: this.path_Array[order].z,
|
||
circulate: circulate,
|
||
last: pos
|
||
};
|
||
target.runRoad(data);
|
||
}
|
||
};
|
||
//判断边界。或者撞山,或者湿地没有加固
|
||
GameManager.prototype.getBoundary = function (order, x, y, direction, road) {
|
||
var jg = true;
|
||
if (x < 0 || x >= this.map_Width || y < 0 || y >= this.map_Hight) {
|
||
jg = false;
|
||
console.log("超过边界,游戏结束");
|
||
alert("超过边界,游戏结束");
|
||
}
|
||
else {
|
||
var i = road[order].x * this.map_Array[0].length + road[order].y;
|
||
var target = this.block_Array[i].getComponent("Block");
|
||
if (target.block_Type == 3) {
|
||
jg = false;
|
||
console.log("修筑山峰,游戏结束");
|
||
alert("修筑山峰,游戏结束");
|
||
}
|
||
else if (target.block_Type == 2 && direction != "Reinforce") {
|
||
jg = false;
|
||
console.log("修筑未加固湿地,游戏结束");
|
||
alert("修筑未加固湿地,游戏结束");
|
||
}
|
||
}
|
||
return jg;
|
||
};
|
||
//开始执行洪峰来了的动画
|
||
GameManager.prototype.runWater = function (order) {
|
||
order = parseInt(order);
|
||
if (order <= this.water_Array.length - 1) {
|
||
var i = this.water_Array[order].x * this.map_Array[0].length + this.water_Array[order].y;
|
||
var direction = "";
|
||
var circulate = true;
|
||
//最后一步结束
|
||
if (order == this.water_Array.length - 1) {
|
||
circulate = false;
|
||
direction = "End";
|
||
}
|
||
else {
|
||
if (this.water_Array[order].z == 6 && order + 1 < this.water_Array.length) {
|
||
direction = "Reinforce";
|
||
i = this.water_Array[order + 1].x * this.map_Array[0].length + this.water_Array[order + 1].y;
|
||
}
|
||
else if (order + 1 < this.water_Array.length) {
|
||
if (this.water_Array[order + 1].z == 5) {
|
||
direction = "Xi_Soil";
|
||
}
|
||
else if (this.water_Array[order + 1].z == 6 && order == 0) {
|
||
direction = "Reinforce";
|
||
}
|
||
else {
|
||
direction = this.getDirection(order, this.water_Array);
|
||
}
|
||
}
|
||
else {
|
||
direction = this.getDirection(order, this.water_Array);
|
||
}
|
||
}
|
||
// console.log(order,this.path_Array[order].x,this.path_Array[order].y,i);
|
||
var jg = this.getBoundary(order, this.water_Array[order].x, this.water_Array[order].y, direction, this.water_Array);
|
||
console.log("步骤:", order, "方向", direction);
|
||
if (direction == "" || jg == false) {
|
||
return;
|
||
}
|
||
var target = this.block_Array[i].getComponent("Block");
|
||
target.setPath(direction);
|
||
if (order > 0 && order < this.water_Array.length - 1) {
|
||
if (this.water_Array[order + 1].z == 5) {
|
||
this.set_Soil(order + 1, this.water_Array, "water");
|
||
circulate = false;
|
||
return;
|
||
}
|
||
else if (order == 1 && this.water_Array[order].z == 5) {
|
||
this.set_Soil(order, this.water_Array, "water");
|
||
circulate = false;
|
||
return;
|
||
}
|
||
}
|
||
var data = {
|
||
order: order,
|
||
time: cc.fx.GameConfig.TIME_INFO.waterSpeed[cc.fx.GameConfig.GM_INFO.level],
|
||
type: this.water_Array[order].z,
|
||
circulate: circulate
|
||
};
|
||
target.runWater(data);
|
||
}
|
||
};
|
||
//获取息壤的格子的方向
|
||
GameManager.prototype.getXi_Soil = function (order, road) {
|
||
var direction = null;
|
||
//如果息壤后面还有下一步的话
|
||
if (order + 1 < road.length) {
|
||
direction = this.getDirection(order, road);
|
||
if (direction == "up" || direction == "right_up" || direction == "left_up") {
|
||
direction = "up";
|
||
}
|
||
else if (direction == "down" || direction == "left_down" || direction == "right_down") {
|
||
direction = "down";
|
||
}
|
||
else if (direction == "left" || direction == "up_left" || direction == "down_left") {
|
||
direction = "left";
|
||
}
|
||
else if (direction == "right" || direction == "up_right" || direction == "down_right") {
|
||
direction = "right";
|
||
}
|
||
}
|
||
return direction;
|
||
};
|
||
//设置息壤
|
||
GameManager.prototype.set_Soil = function (order, road, name) {
|
||
var direction = this.getXi_Soil(order, road);
|
||
var length = 0;
|
||
if (direction == "right") {
|
||
length = this.map_Width - 1;
|
||
for (var i = road[order].x; i <= length; i++) {
|
||
var n = i * this.map_Array[0].length + road[order].y;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (target.block_Type == 3 || target.block_Type == 4) {
|
||
length = i - 1;
|
||
if (target.block_Type == 4) {
|
||
length += 1;
|
||
}
|
||
i = 10000;
|
||
break;
|
||
}
|
||
}
|
||
this.scheduleOnce;
|
||
}
|
||
else if (direction == "left") {
|
||
length = 0;
|
||
for (var i = road[order].x; i >= length; i--) {
|
||
var n = i * this.map_Array[0].length + road[order].y;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (target.block_Type == 3 || target.block_Type == 4) {
|
||
length = i + 1;
|
||
if (target.block_Type == 4) {
|
||
length -= 1;
|
||
}
|
||
i = -1;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else if (direction == "up") {
|
||
length = 0;
|
||
for (var i = road[order].y; i >= length; i--) {
|
||
var n = road[order].x * this.map_Array[0].length + i;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (target.block_Type == 3 || target.block_Type == 4) {
|
||
length = i + 1;
|
||
if (target.block_Type == 4) {
|
||
length -= 1;
|
||
}
|
||
i = -1;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else if (direction == "down") {
|
||
length = this.map_Hight - 1;
|
||
for (var i = road[order].y; i <= length; i++) {
|
||
var n = road[order].x * this.map_Array[0].length + i;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (target.block_Type == 3 || target.block_Type == 4) {
|
||
length = i - 1;
|
||
if (target.block_Type == 4) {
|
||
length += 1;
|
||
}
|
||
i = 10000;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
this.soil_Find(direction, order, length, road, name);
|
||
};
|
||
//查找息壤蛮遗憾路径
|
||
GameManager.prototype.soil_Find = function (direction, order, length, road, name) {
|
||
var start = road[order].x;
|
||
if (direction == "right") {
|
||
for (var i = start; i <= length; i++) {
|
||
var n = i * this.map_Array[0].length + road[order].y;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (i == start) {
|
||
target.set_Xi_SoilType(this.getDirection(order, road), null, name);
|
||
var value = cc.v3(this.path_Array[order].x, this.path_Array[order].y, 0);
|
||
if (this.water_Array[this.water_Array.length - 1] != value) {
|
||
console.log("特别插入:", this.path_Array[order].x, this.path_Array[order].y);
|
||
this.changeWater(value);
|
||
}
|
||
}
|
||
else {
|
||
var jg = null;
|
||
if (i == length) {
|
||
var number = i - start - 1;
|
||
this.changePath(order, number, false, road);
|
||
jg = order;
|
||
}
|
||
target.set_Xi_SoilType(direction, jg, name);
|
||
}
|
||
}
|
||
}
|
||
else if (direction == "left") {
|
||
for (var i = start; i >= length; i--) {
|
||
var n = i * this.map_Array[0].length + road[order].y;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (i == start) {
|
||
target.set_Xi_SoilType(this.getDirection(order, road), null, name);
|
||
var value = cc.v3(this.path_Array[order].x, this.path_Array[order].y, 0);
|
||
if (this.water_Array[this.water_Array.length - 1] != value) {
|
||
console.log("特别插入:", this.path_Array[order].x, this.path_Array[order].y);
|
||
this.changeWater(value);
|
||
}
|
||
}
|
||
else {
|
||
var jg = null;
|
||
if (i == length) {
|
||
var number = i - start + 1;
|
||
this.changePath(order, number, false, road);
|
||
jg = order;
|
||
}
|
||
target.set_Xi_SoilType(direction, jg, name);
|
||
}
|
||
}
|
||
}
|
||
else if (direction == "up") {
|
||
start = road[order].y;
|
||
for (var i = start; i >= length; i--) {
|
||
var n = road[order].x * this.map_Array[0].length + i;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (i == start) {
|
||
target.set_Xi_SoilType(this.getDirection(order, road), null, name);
|
||
var value = cc.v3(this.path_Array[order].x, this.path_Array[order].y, 0);
|
||
if (this.water_Array[this.water_Array.length - 1] != value) {
|
||
console.log("特别插入:", this.path_Array[order].x, this.path_Array[order].y);
|
||
this.changeWater(value);
|
||
}
|
||
}
|
||
else {
|
||
var jg = null;
|
||
if (i == length) {
|
||
var number = i - start + 1;
|
||
this.changePath(order, number, true, road);
|
||
jg = order;
|
||
}
|
||
console.log("想上息壤插入:", this.path_Array[order].x, i);
|
||
target.set_Xi_SoilType(direction, jg, name);
|
||
}
|
||
}
|
||
}
|
||
else if (direction == "down") {
|
||
start = road[order].y;
|
||
for (var i = start; i <= length; i++) {
|
||
var n = road[order].x * this.map_Array[0].length + i;
|
||
var target = this.block_Array[n].getComponent("Block");
|
||
if (i == start) {
|
||
target.set_Xi_SoilType(this.getDirection(order, road), null, name);
|
||
var value = cc.v3(this.path_Array[order].x, this.path_Array[order].y, 0);
|
||
if (this.water_Array[this.water_Array.length - 1] != value) {
|
||
console.log("特别插入:", this.path_Array[order].x, this.path_Array[order].y);
|
||
this.changeWater(value);
|
||
}
|
||
}
|
||
else {
|
||
var jg = null;
|
||
if (i == length) {
|
||
var number = i - start - 1;
|
||
this.changePath(order, number, true, road);
|
||
jg = order;
|
||
}
|
||
target.set_Xi_SoilType(direction, jg, name);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
//改变水流地图
|
||
GameManager.prototype.changeWater = function (value) {
|
||
var jg = true;
|
||
if (this.water_Array.length > 0) {
|
||
if (this.water_Array[this.water_Array.length - 1].x == value.x && this.water_Array[this.water_Array.length - 1].y == value.y) {
|
||
jg = false;
|
||
}
|
||
}
|
||
if (jg)
|
||
this.water_Array.push(value);
|
||
};
|
||
//息壤过后改变修筑路径
|
||
GameManager.prototype.changePath = function (order, number, direction, road) {
|
||
for (var i = (order + 1); i < road.length; i++) {
|
||
if (!direction) {
|
||
road[i].x += (number);
|
||
}
|
||
else {
|
||
road[i].y += (number);
|
||
}
|
||
}
|
||
if (direction) {
|
||
if (number < 0) {
|
||
for (var n = -number; n > 0; n--) {
|
||
this.changeWater(cc.v3(this.path_Array[order + 1].x, this.path_Array[order + 1].y + n, 0));
|
||
console.log("1特殊放入:", this.path_Array[order + 1].x, this.path_Array[order + 1].y + n);
|
||
}
|
||
}
|
||
else {
|
||
for (var n = number; n > 0; n--) {
|
||
this.changeWater(cc.v3(this.path_Array[order + 1].x, this.path_Array[order + 1].y - n, 0));
|
||
console.log("2特殊放入:", this.path_Array[order + 1].x, this.path_Array[order + 1].y - n);
|
||
}
|
||
}
|
||
}
|
||
else {
|
||
if (number < 0) {
|
||
for (var m = -number; m > 0; m--) {
|
||
this.changeWater(cc.v3(this.path_Array[order + 1].x + m, this.path_Array[order + 1].y, 0));
|
||
console.log("3特殊放入:", this.path_Array[order + 1].x + m, this.path_Array[order + 1].y);
|
||
}
|
||
}
|
||
else {
|
||
for (var m = number; m > 0; m--) {
|
||
this.changeWater(cc.v3(this.path_Array[order + 1].x - m, this.path_Array[order + 1].y, 0));
|
||
console.log("4特殊放入:", this.path_Array[order + 1].x - m, this.path_Array[order + 1].y);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
GameManager.prototype.changeMap = function (data) {
|
||
};
|
||
//获取洪峰方向
|
||
GameManager.prototype.getDirection = function (order, road) {
|
||
var name = "";
|
||
//入海口比较复杂单独判断
|
||
if (order == 0) {
|
||
var nextX = road[order + 1].x - road[order].x;
|
||
var nextY = road[order].y - road[order + 1].y;
|
||
//在底边
|
||
if (road[order].y == this.map_Array[0].length - 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 (road[order].y == 0) {
|
||
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 (road[order].x == 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 (road[order].x == this.map_Array.length - 1) {
|
||
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";
|
||
}
|
||
}
|
||
//不是第一步,已经走过一步
|
||
else if (order > 0) {
|
||
var next = 1;
|
||
if (order + 2 < road.length) {
|
||
if (road[order + 1].z == 6)
|
||
next = 2;
|
||
}
|
||
//用于判断此点的上一个点,是为了判断当前方块洪水七点,以及下一个移动方向,判断洪终点方向
|
||
var nextX = road[order + next].x - road[order].x;
|
||
var nextY = road[order].y - road[order + next].y;
|
||
var previousX = road[order].x - road[order - 1].x;
|
||
var previousY = road[order - 1].y - road[order].y;
|
||
if (previousX == 0 && previousY == 0) {
|
||
if (order > 1) {
|
||
previousX = road[order].x - road[order - 2].x;
|
||
previousY = road[order - 2].y - road[order].y;
|
||
}
|
||
else if (order + 1 < road.length) {
|
||
previousX = road[order + 1].x - road[order].x;
|
||
previousY = road[order].y - road[order + 1].y;
|
||
// console.log("息壤,上下坐标差距",previousX,previousY);
|
||
}
|
||
}
|
||
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;
|
||
};
|
||
//根据是否全面屏,做独立适配方面
|
||
GameManager.prototype.fit = function () {
|
||
var jg = this.setFit();
|
||
if (!jg) {
|
||
this.Map.scale = 1.2;
|
||
}
|
||
else {
|
||
this.Map.scale = 1;
|
||
}
|
||
};
|
||
//判断全面屏
|
||
GameManager.prototype.getSetScreenResolutionFlag = function () {
|
||
var size = cc.winSize;
|
||
var width = size.width;
|
||
var height = size.height;
|
||
if ((height / width) > (16.2 / 9))
|
||
return false;
|
||
return true;
|
||
};
|
||
//判断全面屏适配
|
||
GameManager.prototype.setFit = function () {
|
||
var flag = this.getSetScreenResolutionFlag();
|
||
if (flag) {
|
||
}
|
||
else {
|
||
}
|
||
return flag;
|
||
};
|
||
//返回首页
|
||
GameManager.prototype.backScene = function () {
|
||
cc.director.loadScene("LoadScene");
|
||
};
|
||
//下一关,或者重新开始,或者返回上一关,根据level决定
|
||
GameManager.prototype.reStart = function (type) {
|
||
};
|
||
//获取时间戳
|
||
GameManager.prototype.getTime = function () {
|
||
var timestamp = new Date().getTime();
|
||
return timestamp;
|
||
};
|
||
//获胜
|
||
GameManager.prototype.passLevel = function () {
|
||
};
|
||
//失败
|
||
GameManager.prototype.loseLevel = function (type) {
|
||
//1: 1649
|
||
//2: 3646
|
||
//3: 5546
|
||
//4: 2600
|
||
//5: 694
|
||
};
|
||
//开始游戏
|
||
GameManager.prototype.startGame = function (data) {
|
||
this.setMap(data);
|
||
};
|
||
GameManager.prototype.updateWaterTime = function () {
|
||
var _this = this;
|
||
if (this.waterTime > 0) {
|
||
this.waterTime -= 1;
|
||
this.Countdown.string = cc.fx.GameTool.getTimeMargin(this.waterTime);
|
||
if (this.waterTime <= 0) {
|
||
this.unschedule(this.updateWaterTime);
|
||
if (!this.plan_over) {
|
||
this.plan_over = true;
|
||
setTimeout(function () {
|
||
_this.runWater(0);
|
||
}, 500);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
//如果是倒计时 调用此方法
|
||
GameManager.prototype.updateCountDownTime = function () {
|
||
if (this.countTime > 0) {
|
||
this.countTime -= 1;
|
||
this.Time.string = cc.fx.GameTool.getTimeMargin(this.countTime);
|
||
if (this.countTime < 5) {
|
||
var 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);
|
||
}
|
||
}
|
||
};
|
||
//上传每次操作数据
|
||
GameManager.prototype.setData = function () {
|
||
cc.fx.GameTool.setGameData();
|
||
};
|
||
//上传排行榜数据
|
||
GameManager.prototype.gameOver = function (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(function () {
|
||
cc.director.loadScene("OverScene");
|
||
})
|
||
.start();
|
||
};
|
||
GameManager.prototype.clickSun = function (data) {
|
||
};
|
||
GameManager.prototype.addEnd = function (data) {
|
||
};
|
||
GameManager.prototype.nextWater = function () {
|
||
};
|
||
GameManager.prototype.onEnable = function () {
|
||
cc.fx.Notifications.on(cc.fx.Message.control, this.clickSun, this);
|
||
cc.fx.Notifications.on(cc.fx.Message.next, this.runRoad, this);
|
||
cc.fx.Notifications.on(cc.fx.Message.nextWater, this.runWater, this);
|
||
cc.fx.Notifications.on(cc.fx.Message.startGame, this.startGame, this);
|
||
cc.fx.Notifications.on(cc.fx.Message.changePath, this.changePath, this);
|
||
cc.fx.Notifications.on(cc.fx.Message.changeMap, this.changeMap, this);
|
||
cc.fx.Notifications.on(cc.fx.Message.addEnd, this.addEnd, this);
|
||
};
|
||
GameManager.prototype.onDisable = function () {
|
||
cc.fx.Notifications.off(cc.fx.Message.control, this.clickSun);
|
||
cc.fx.Notifications.off(cc.fx.Message.next, this.runRoad);
|
||
cc.fx.Notifications.off(cc.fx.Message.nextWater, this.runWater);
|
||
cc.fx.Notifications.off(cc.fx.Message.startGame, this.startGame);
|
||
cc.fx.Notifications.off(cc.fx.Message.changePath, this.changePath);
|
||
cc.fx.Notifications.off(cc.fx.Message.changeMap, this.changeMap);
|
||
cc.fx.Notifications.off(cc.fx.Message.addEnd, this.addEnd);
|
||
};
|
||
GameManager.prototype.update = function (dt) {
|
||
};
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "Map", void 0);
|
||
__decorate([
|
||
property(cc.Prefab)
|
||
], GameManager.prototype, "Block", void 0);
|
||
__decorate([
|
||
property(cc.Label)
|
||
], GameManager.prototype, "Time", void 0);
|
||
__decorate([
|
||
property(cc.Label)
|
||
], GameManager.prototype, "Countdown", void 0);
|
||
GameManager = __decorate([
|
||
ccclass
|
||
], GameManager);
|
||
return GameManager;
|
||
}(cc.Component));
|
||
exports.default = GameManager;
|
||
|
||
cc._RF.pop(); |