284 lines
11 KiB
JavaScript
284 lines
11 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 _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.Btn_New = null;
|
||
_this.Btn_Hear = null;
|
||
_this.Btn_See = null;
|
||
_this.Btn_Firewood = null;
|
||
_this.Plant = null;
|
||
_this.timeNode = null;
|
||
_this.FoodPlist = null;
|
||
return _this;
|
||
}
|
||
GameManager.prototype.onLoad = function () { };
|
||
GameManager.prototype.start = function () {
|
||
this.fit();
|
||
this.init();
|
||
this.startGame();
|
||
};
|
||
//初始化数据
|
||
GameManager.prototype.init = function () {
|
||
this.touchable = false;
|
||
this.result = false;
|
||
this.foodAudioArray = [];
|
||
this.foodPicArray = [];
|
||
this.timeTween = null;
|
||
this.voiceSpriteFrame = this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame;
|
||
this.btnReset();
|
||
};
|
||
//开始游戏
|
||
GameManager.prototype.startGame = function () {
|
||
var _this = this;
|
||
cc.tween(this.node.getChildByName("Begin"))
|
||
.to(0.1, { opacity: 0 })
|
||
.to(0.5, { opacity: 255 })
|
||
.delay(1)
|
||
.to(0.5, { opacity: 0 })
|
||
.call(function () {
|
||
_this.createCustom();
|
||
})
|
||
.start();
|
||
};
|
||
//根据是否全面屏,做独立适配方面
|
||
GameManager.prototype.fit = function () {
|
||
var jg = cc.fx.GameTool.setFit();
|
||
if (!jg) {
|
||
this.Btn_Hear.y = -330;
|
||
this.Btn_See.y = -460;
|
||
this.Btn_Firewood.y = -600;
|
||
}
|
||
};
|
||
//创建关卡
|
||
GameManager.prototype.createCustom = function () {
|
||
var _this = this;
|
||
this.Plant.opacity = 0;
|
||
this.timeNode.getComponent(cc.Sprite).fillRange = 0;
|
||
var customData = cc.fx.GameConfig.LEVEL_INFO[cc.fx.GameConfig.GM_INFO.custom].custom[cc.fx.GameConfig.GM_INFO.level];
|
||
var name = customData.item;
|
||
if (customData.type == 1) {
|
||
this.Plant.getChildByName("name").getComponent(cc.Label).string = cc.fx.GameTool.getFoodName(name);
|
||
name = "prop_" + name;
|
||
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.FoodPlist["_spriteFrames"][name];
|
||
this.now_Food = name;
|
||
}
|
||
else {
|
||
this.Plant.getChildByName("name").getComponent(cc.Label).string = "";
|
||
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.voiceSpriteFrame;
|
||
this.now_Food = name;
|
||
}
|
||
//关卡+1
|
||
cc.fx.GameConfig.GM_INFO.level += 1;
|
||
cc.tween(this.Plant)
|
||
.to(0.2, { opacity: 255 })
|
||
.call(function () {
|
||
_this.startTime = cc.fx.GameTool.getTime();
|
||
_this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = true;
|
||
_this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = true;
|
||
_this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = true;
|
||
_this.timeTween =
|
||
cc.tween(_this.timeNode.getComponent(cc.Sprite))
|
||
.to(2.5, { fillRange: 1 })
|
||
.call(function () {
|
||
_this.timeTween = null;
|
||
_this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
_this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
_this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
_this.nextLevel();
|
||
})
|
||
.start();
|
||
})
|
||
.start();
|
||
};
|
||
//新植物按钮
|
||
GameManager.prototype.click_Choice = function (customData, data) {
|
||
//关掉计时器
|
||
this.timeTween.stop();
|
||
this.timeTween = null;
|
||
//判断是否正确,并把出现的物品存入数组
|
||
this.result = this.judgingResult();
|
||
if (data == "Btn_New")
|
||
this.result = !this.result;
|
||
//设置按钮状态
|
||
this.setBtnState(this[data]);
|
||
//获取反应时间
|
||
this.setTimeData();
|
||
//进行下一关
|
||
this.nextLevel();
|
||
};
|
||
//判断是否有过的结果 type只为new hear see 三选一
|
||
GameManager.prototype.judgingResult = function () {
|
||
var result = false;
|
||
var arrayTemp = this.foodPicArray;
|
||
if (this.now_Food.substring(0, 4) != "prop") {
|
||
arrayTemp = [];
|
||
arrayTemp = this.foodAudioArray;
|
||
}
|
||
if (arrayTemp.length > 0) {
|
||
for (var i = 0; i < arrayTemp.length; i++) {
|
||
if (this.now_Food == arrayTemp[i]) {
|
||
result = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
//判断后放进数组
|
||
arrayTemp.push(this.now_Food);
|
||
return result;
|
||
};
|
||
//计算反应时间
|
||
GameManager.prototype.setTimeData = function () {
|
||
this.overTime = cc.fx.GameTool.getTime();
|
||
var time = this.overTime - this.startTime;
|
||
cc.fx.GameConfig.CLICK_DATA.stepTimeList.push(time);
|
||
};
|
||
//设置按钮状态
|
||
GameManager.prototype.setBtnState = function (node) {
|
||
if (this.result == false) {
|
||
node.getChildByName("err").active = true;
|
||
node.getChildByName("correct").active = false;
|
||
}
|
||
else {
|
||
node.getChildByName("err").active = false;
|
||
node.getChildByName("correct").active = true;
|
||
}
|
||
node.getChildByName("nomal").active = false;
|
||
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
};
|
||
//下一轮 首先重置按钮状态
|
||
GameManager.prototype.nextLevel = function () {
|
||
var _this = this;
|
||
cc.tween(this.Plant)
|
||
.delay(1)
|
||
.call(function () {
|
||
_this.btnReset();
|
||
})
|
||
.to(0.5, { opacity: 0 })
|
||
.call(function () {
|
||
_this.createCustom();
|
||
})
|
||
.start();
|
||
};
|
||
GameManager.prototype.btnReset = function () {
|
||
this.Btn_New.getChildByName("nomal").active = true;
|
||
this.Btn_New.getChildByName("err").active = false;
|
||
this.Btn_New.getChildByName("correct").active = false;
|
||
this.Btn_Hear.getChildByName("nomal").active = true;
|
||
this.Btn_Hear.getChildByName("err").active = false;
|
||
this.Btn_Hear.getChildByName("correct").active = false;
|
||
this.Btn_See.getChildByName("nomal").active = true;
|
||
this.Btn_See.getChildByName("err").active = false;
|
||
this.Btn_See.getChildByName("correct").active = false;
|
||
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
|
||
};
|
||
//返回首页
|
||
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) {
|
||
};
|
||
//如果是倒计时 调用此方法
|
||
GameManager.prototype.startCountDownTime = function () {
|
||
this.timeNode.getComponent(cc.Sprite).fillRange = 0;
|
||
cc.tween(this.timeNode.getComponent(cc.Sprite))
|
||
.to(2, { fillRange: 1 })
|
||
.start();
|
||
};
|
||
//上传每次操作数据
|
||
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.onEnable = function () {
|
||
// cc.fx.Notifications.on("clickSun", this.clickSun, this);
|
||
};
|
||
GameManager.prototype.onDisable = function () {
|
||
// cc.fx.Notifications.off("clickSun", this.clickSun);
|
||
};
|
||
GameManager.prototype.update = function (dt) {
|
||
};
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "Btn_New", void 0);
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "Btn_Hear", void 0);
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "Btn_See", void 0);
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "Btn_Firewood", void 0);
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "Plant", void 0);
|
||
__decorate([
|
||
property(cc.Node)
|
||
], GameManager.prototype, "timeNode", void 0);
|
||
__decorate([
|
||
property(cc.SpriteAtlas)
|
||
], GameManager.prototype, "FoodPlist", void 0);
|
||
GameManager = __decorate([
|
||
ccclass
|
||
], GameManager);
|
||
return GameManager;
|
||
}(cc.Component));
|
||
exports.default = GameManager;
|
||
|
||
cc._RF.pop(); |