215 lines
7.9 KiB
JavaScript
215 lines
7.9 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'e35abcX5VRAoItO6mgFcYyX', 'ControlManager');
|
|
// Script/ControlManager.ts
|
|
|
|
"use strict";
|
|
// Learn TypeScript:
|
|
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
|
|
// Learn Attribute:
|
|
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
|
|
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 _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
|
|
var NewClass = /** @class */ (function (_super) {
|
|
__extends(NewClass, _super);
|
|
function NewClass() {
|
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
_this.Map = null;
|
|
_this.tip = null;
|
|
_this.reinforce = null;
|
|
_this.soil = null;
|
|
return _this;
|
|
// update (dt) {}
|
|
}
|
|
// LIFE-CYCLE CALLBACKS:
|
|
// onLoad () {}
|
|
NewClass.prototype.start = function () {
|
|
this.tipArray = [];
|
|
this.controlArray = [];
|
|
this.canTouch = true;
|
|
this.Reinforce = false;
|
|
this.Soil = false;
|
|
this.mapHeight = 0;
|
|
};
|
|
NewClass.prototype.setPosition = function (tip) {
|
|
tip.setPosition(30, -25);
|
|
if (this.tipArray.length > 0) {
|
|
var length = this.tipArray.length + 1;
|
|
var posY = Math.ceil(length / 8) - 1;
|
|
var posX = length - Math.floor(posY) * 8 - 1;
|
|
tip.setPosition(30 + 48 * posX, -25 - 48 * posY + this.mapHeight);
|
|
}
|
|
};
|
|
//清空所有
|
|
NewClass.prototype.removeAllTip = function () {
|
|
if (!this.canTouch)
|
|
return;
|
|
if (this.tipArray.length > 0) {
|
|
cc.fx.AudioManager._instance.playEffect("qingkong", null);
|
|
for (var i = 0; i < this.tipArray.length; i++) {
|
|
var tip = this.tipArray[i];
|
|
tip.active = false;
|
|
tip.removeFromParent(this.Map);
|
|
tip = null;
|
|
}
|
|
this.tipArray = [];
|
|
this.controlArray = [];
|
|
var drawingReset = cc.fx.GameConfig.CLICK_DATA.drawingReset + 1;
|
|
cc.fx.GameConfig.CLICK_SET("drawingReset", drawingReset);
|
|
cc.fx.Notifications.emit(cc.fx.Message.removeTip, "remove");
|
|
this.mapHeight = 0;
|
|
}
|
|
};
|
|
//撤回一步
|
|
NewClass.prototype.back_Click = function () {
|
|
if (!this.canTouch)
|
|
return;
|
|
if (this.tipArray.length > 0) {
|
|
cc.fx.AudioManager._instance.playEffect("chehui", null);
|
|
var tip = this.tipArray[this.tipArray.length - 1];
|
|
tip.active = false;
|
|
tip.removeFromParent(this.Map);
|
|
tip = null;
|
|
this.tipArray.pop();
|
|
this.controlArray.pop();
|
|
var drawingBack = cc.fx.GameConfig.CLICK_DATA.drawingBack + 1;
|
|
cc.fx.GameConfig.CLICK_SET("drawingBack", drawingBack);
|
|
cc.fx.Notifications.emit(cc.fx.Message.removeTip, "back");
|
|
if (this.tipArray.length >= 24) {
|
|
if ((this.tipArray.length) % 8 == 0) {
|
|
this.mapMove(false);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
//点击事件
|
|
NewClass.prototype.btn_Click = function (target, data) {
|
|
var GameManager = this.node.parent.getComponent("GameManager");
|
|
if (GameManager.btnClick == true) {
|
|
GameManager.btnClick = false;
|
|
cc.fx.Notifications.emit(cc.fx.Message.guideNext);
|
|
}
|
|
cc.fx.Notifications.emit(cc.fx.Message.control, data);
|
|
if (!this.canTouch)
|
|
return;
|
|
var prefab = this.tip;
|
|
if (data == "reinforce" || data == "soil") {
|
|
prefab = this[data];
|
|
if (data == "reinforce") {
|
|
if (this.Reinforce) {
|
|
this.Reinforce = false;
|
|
this.back_Click();
|
|
return;
|
|
}
|
|
else {
|
|
cc.fx.AudioManager._instance.playEffect("jineng", null);
|
|
this.Reinforce = true;
|
|
this.Soil = false;
|
|
}
|
|
}
|
|
else if (data == "soil") {
|
|
if (this.Soil) {
|
|
this.Soil = false;
|
|
this.back_Click();
|
|
return;
|
|
}
|
|
else {
|
|
cc.fx.AudioManager._instance.playEffect("jineng", null);
|
|
this.Soil = true;
|
|
this.Reinforce = false;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
cc.fx.AudioManager._instance.playEffect("fangxiang", null);
|
|
this.Reinforce = false;
|
|
this.Soil = false;
|
|
}
|
|
var tip = cc.instantiate(prefab);
|
|
if (data == "up")
|
|
tip.angle = 180;
|
|
if (data == "left")
|
|
tip.angle = -90;
|
|
if (data == "right")
|
|
tip.angle = 90;
|
|
tip.parent = this.Map;
|
|
if (this.controlArray[this.controlArray.length - 1] == "reinforce" ||
|
|
this.controlArray[this.controlArray.length - 1] == "soil") {
|
|
if (data == "reinforce" || data == "soil") {
|
|
this.tipArray[this.tipArray.length - 1].removeFromParent();
|
|
this.tipArray[this.tipArray.length - 1] = null;
|
|
this.tipArray.pop();
|
|
this.controlArray.pop();
|
|
}
|
|
}
|
|
this.setPosition(tip);
|
|
this.tipArray.push(tip);
|
|
this.controlArray.push(data);
|
|
if (this.tipArray.length >= 25) {
|
|
if ((this.tipArray.length - 1) % 8 == 0) {
|
|
this.mapMove(true);
|
|
}
|
|
}
|
|
};
|
|
//地图放不下了上下移动
|
|
NewClass.prototype.mapMove = function (type) {
|
|
if (type)
|
|
this.mapHeight += 48;
|
|
else
|
|
this.mapHeight -= 48;
|
|
for (var i = 0; i < this.tipArray.length; i++) {
|
|
var tip = this.tipArray[i];
|
|
if (type)
|
|
tip.y += 48;
|
|
else
|
|
tip.y -= 48;
|
|
}
|
|
};
|
|
//点击开始 创建河道
|
|
NewClass.prototype.start_Click = function () {
|
|
if (!this.canTouch)
|
|
return;
|
|
this.canTouch = false;
|
|
cc.fx.AudioManager._instance.playEffect("build", null);
|
|
cc.fx.Notifications.emit(cc.fx.Message.startGame, this.controlArray);
|
|
};
|
|
__decorate([
|
|
property(cc.Node)
|
|
], NewClass.prototype, "Map", void 0);
|
|
__decorate([
|
|
property(cc.Prefab)
|
|
], NewClass.prototype, "tip", void 0);
|
|
__decorate([
|
|
property(cc.Prefab)
|
|
], NewClass.prototype, "reinforce", void 0);
|
|
__decorate([
|
|
property(cc.Prefab)
|
|
], NewClass.prototype, "soil", void 0);
|
|
NewClass = __decorate([
|
|
ccclass
|
|
], NewClass);
|
|
return NewClass;
|
|
}(cc.Component));
|
|
exports.default = NewClass;
|
|
|
|
cc._RF.pop(); |