12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148 |
- "use strict";
- cc._RF.push(module, '726051WgaxHep/G1I05lW4n', 'MainScene');
- // Script/MainScene.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 Global_1 = require("./Global");
- var MessManager_1 = require("./MessManager");
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
- var MainScene = /** @class */ (function (_super) {
- __extends(MainScene, _super);
- function MainScene() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.boli = null;
- _this.dici = null;
- _this.lvdai = null;
- _this.shandian = null;
- _this.tanhuang = null;
- _this.Opplvdai = null;
- _this.GD = null;
- _this.failure = null;
- _this.fuhuo = null;
- _this.Player = null;
- _this.FHolderNode = null;
- _this.Bg = null;
- _this.LifeDing = null;
- _this.LEFT = null;
- _this.RIGHT = null;
- _this.output = null;
- // LIFE-CYCLE CALLBACKS:
- /**
- * 上一个落脚点生成时间
- */
- _this.STime = 0;
- /**
- * 当前落脚点生成时间
- */
- _this.ETime = 0;
- /** Left*/
- _this.LkeyDown = false;
- /** Right*/
- _this.RkeyDown = false;
- /**the loght FootHolder F */
- _this.lightF = false;
- _this.moveFalg = "";
- _this.USERINFO = {
- userId: "",
- score: 0,
- };
- _this.fuhuoCount = 1;
- _this.once = false;
- return _this;
- }
- MainScene.prototype.onKeyDown = function (event) {
- if (event.keyCode == cc.macro.KEY.w) {
- console.error(1231);
- }
- };
- MainScene.prototype.onLoad = function () {
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
- MessManager_1.default.getInstance().initData();
- var time = cc.sys.localStorage.getItem("hfsj");
- if (time == null || time == undefined || time == "") {
- cc.sys.localStorage.setItem("hfsj", "99");
- }
- this.LifeDing.zIndex = 10;
- this.FHolderNode.zIndex = 9;
- Global_1.default.instance.setMN(this.node);
- this.STime = Date.now();
- var FHolder = cc.instantiate(this.GD);
- this.FHolderNode.addChild(FHolder, 10, "GD");
- FHolder.getComponent("GD").init(this, 1);
- FHolder.getComponent("GD").First = true;
- FHolder.y = -100;
- var FHolder2 = cc.instantiate(this.lvdai);
- this.FHolderNode.addChild(FHolder2, 10, "lvdai");
- FHolder2.getComponent("lvdai").init(this);
- FHolder2.y = -300;
- // let FHolder2 = cc.instantiate(this.dici);
- // this.FHolderNode.addChild(FHolder2, 10, "dici");
- // FHolder2.getComponent("dici").init(this);
- // FHolder2.y = -300;
- // let FHolder2 = cc.instantiate(this.tanhuang);
- // this.FHolderNode.addChild(FHolder2,10,"tanhuang");
- // FHolder2.getComponent("tanhuang").init(this);
- // FHolder2.y = -300;
- var FHolder3 = cc.instantiate(this.GD);
- this.FHolderNode.addChild(FHolder3, 10, "GD");
- FHolder3.getComponent("GD").init(this, 1);
- FHolder3.y = -450;
- // this.Player.active = false;
- this.Player.x = 0;
- // this.Player.y = FHolder.y+60;
- this.Player.zIndex = 11;
- for (var i = 0; i < this.LifeDing.children.length; i++) {
- if (this.LifeDing.children[i].name == "lifeBG") {
- if (!this.LifeDing.children[i].active) {
- this.LifeDing.children[i].active = true;
- }
- Global_1.default.instance.reLife.push(this.LifeDing.children[i]);
- }
- }
- cc.director.getCollisionManager().enabled = true;
- // cc.director.getCollisionManager().enabledDebugDraw = true;
- cc.director.getCollisionManager().enabledDrawBoundingBox = false;
- };
- MainScene.prototype.playtansound = function () {
- if (Global_1.default.instance.OverFlag == false) {
- cc.loader.loadRes("tan", cc.AudioClip, function (err, clip) {
- var audioID = cc.audioEngine.play(clip, false, 0.5);
- });
- }
- };
- MainScene.prototype.playdeadsound = function () {
- cc.loader.loadRes("dead", cc.AudioClip, function (err, clip) {
- var audioID = cc.audioEngine.play(clip, false, 0.5);
- });
- };
- MainScene.prototype.start = function () {
- };
- MainScene.prototype.update = function (dt) {
- // console.log(Global.instance.CollisionFlag);
- this.MoveBg();
- Global_1.default.instance.moveSpeed = 1;
- var FHolder;
- if ((this.ETime - this.STime) > (1200 - (180 * (Global_1.default.instance.FHFallSpeed - 2)))) { //控制落脚点之间的间距,间距144px
- this.STime = Date.now();
- if (!Global_1.default.instance.OverFlag) {
- FHolder = this.FootHoldGenerator(null);
- // this.Score();
- }
- }
- this.FHolder();
- this.reduceLife();
- if (Global_1.default.instance.CollisionFlag) { //左右传送带减速
- switch (Global_1.default.instance.KIND_FootHold) {
- case 3: {
- this.Player.x += 2;
- break;
- }
- case 4: {
- this.Player.x -= 2;
- break;
- }
- case 7: {
- if (Global_1.default.instance.LorR == 1) {
- this.Player.x--;
- }
- else {
- this.Player.x++;
- }
- break;
- }
- default: {
- break;
- }
- }
- }
- if (this.Player.x < -180) {
- this.Player.x = -180;
- }
- if (this.Player.x > 180) {
- this.Player.x = 180;
- }
- if (this.Player.y < (-560)) {
- this.Player.getComponent(cc.BoxCollider).enabled = false;
- this.pretreatmentGameover();
- }
- if (Global_1.default.instance.reLife.length == 0) {
- this.Player.getComponent(cc.BoxCollider).enabled = false;
- this.pretreatmentGameover();
- }
- this.ETime = Date.now();
- // let AllChildren = new Array();
- // let GDChildren = new Array();
- // AllChildren = this.node.getChildByName("BgNode").getChildByName("FHolder").children;
- // for (let i = 0; i < AllChildren.length; i++) {
- // if (AllChildren[i].name == "GD") {
- // GDChildren.push(AllChildren[i]);
- // }
- // }
- // cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
- //cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP,this.onKeyUp,this);
- this.Listener();
- };
- MainScene.prototype.Listener = function () {
- var _this = this;
- var btnClickArr = new Array(2);
- if (!this.LkeyDown) {
- this.RIGHT.node.on(cc.Node.EventType.TOUCH_START, this.BtnTurnRight, this);
- this.RIGHT.node.on(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnRight, this);
- this.RIGHT.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
- btnClickArr.push(this.RIGHT);
- this.RIGHT.node.on(cc.Node.EventType.TOUCH_END, function () {
- _this.onKeyUp;
- }, this);
- }
- else {
- this.RIGHT.node.off(cc.Node.EventType.TOUCH_START, this.BtnTurnRight, this);
- this.RIGHT.node.off(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnRight, this);
- this.RIGHT.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
- this.RIGHT.node.off(cc.Node.EventType.TOUCH_END, function () {
- _this.onKeyUp;
- }, this);
- }
- if (!this.RkeyDown) {
- this.LEFT.node.on(cc.Node.EventType.TOUCH_START, this.BtnTurnLeft, this);
- this.LEFT.node.on(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnLeft, this);
- this.LEFT.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
- // btnClickArr.push(this.LEFT);
- this.LEFT.node.on(cc.Node.EventType.TOUCH_END, function () {
- _this.onKeyUp;
- }, this);
- }
- else {
- this.LEFT.node.off(cc.Node.EventType.TOUCH_START, this.BtnTurnLeft, this);
- this.LEFT.node.off(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnLeft, this);
- this.LEFT.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
- this.LEFT.node.off(cc.Node.EventType.TOUCH_END, function () {
- _this.onKeyUp;
- }, this);
- }
- };
- MainScene.prototype.StopAni = function (self) {
- if (!Global_1.default.instance.AniFalg) {
- var FHolder = self.node.getChildByName("BgNode").getChildByName("FHolder").children;
- var Fname = void 0;
- for (var i = 0; FHolder.length; i++) {
- if (i == FHolder.length - 1) {
- Global_1.default.instance.AniFalg = true;
- return;
- }
- Fname = FHolder[i].name;
- FHolder[i].getComponent(Fname).enabled = false;
- }
- }
- };
- /**
- * player 移出落脚点
- */
- MainScene.prototype.FHolder = function () {
- var self = this;
- var FHArray = this.FHolderNode.children;
- var Ani; //the Animation of Player when player fall down
- var Anistate; //the state of Ani;
- for (var i = FHArray.length - 1; i >= 0; i--) {
- if (FHArray[i].isHold) {
- if (self.Player.x > (FHArray[i].x + 75)) {
- Global_1.default.instance.CollisionFlag = false;
- FHArray[i].isHold = false;
- }
- else if (self.Player.x < (FHArray[i].x - 75)) {
- Global_1.default.instance.CollisionFlag = false;
- FHArray[i].isHold = false;
- }
- else {
- Global_1.default.instance.CollisionFlag = true;
- FHArray[i].isHold = true;
- }
- }
- }
- };
- /**
- * 移动背景,初始移动速度200px/s
- */
- MainScene.prototype.MoveBg = function () {
- var Bg0 = this.Bg.getChildByName("Bg_0");
- var Bg1 = this.Bg.getChildByName("Bg_1");
- if (Global_1.default.instance.OverFlag) {
- }
- else {
- Bg0.y += Global_1.default.instance.FHFallSpeed + 1;
- Bg1.y += Global_1.default.instance.FHFallSpeed + 1;
- if (Bg0.y > 946) {
- Bg0.y = -946;
- }
- if (Bg1.y > 946) {
- Bg1.y = -946;
- }
- }
- };
- /**
- * 生成落脚点
- */
- MainScene.prototype.FootHoldGenerator = function (rtpe) {
- var self = this;
- var Magnification = 0;
- var f = parseInt(self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string);
- if (f < 20) {
- Magnification = 2;
- }
- else if (f < 40) {
- Magnification = 4;
- }
- else if (f < 60) {
- Magnification = 6;
- }
- else if (f < 80) {
- Magnification = 8;
- }
- else {
- Magnification = 8;
- }
- var KindHolder = Math.ceil(Math.random() * Magnification);
- // KindHolder = 7;
- var FHolder;
- // KindHolder = Math.ceil(Math.random()*7);
- if (KindHolder == 3 || KindHolder == 4) {
- var va = Math.random() * 10;
- if (va >= 1 && va < 4) {
- KindHolder = 7;
- }
- else if (va >= 4 && va < 10) {
- KindHolder = 5;
- }
- //KindHolder = 5;
- console.log("KindHolder gb: " + KindHolder);
- }
- if (rtpe != null) {
- KindHolder = rtpe;
- console.log("KindHolder gb2: " + KindHolder);
- }
- this.ETime = Date.now();
- switch (KindHolder) {
- case 1: {
- FHolder = cc.instantiate(self.GD);
- self.FHolderNode.addChild(FHolder, 5, "GD");
- FHolder.getComponent("GD").init(self, 1);
- FHolder.isHold = false;
- // console.log("产生第一种落脚点");
- break;
- }
- case 2: {
- FHolder = cc.instantiate(self.GD);
- self.FHolderNode.addChild(FHolder, 5, "GD");
- FHolder.getComponent("GD").init(self, 7);
- FHolder.isHold = false;
- break;
- }
- case 3: {
- FHolder = cc.instantiate(self.lvdai);
- self.FHolderNode.addChild(FHolder, 5, "lvdai");
- FHolder.getComponent("lvdai").init(self);
- FHolder.isHold = false;
- // console.log("产生第二种落脚点");
- console.log(" 创建滚动 ");
- break;
- }
- case 4: {
- FHolder = cc.instantiate(self.lvdai);
- self.FHolderNode.addChild(FHolder, 5, "lvdai");
- FHolder.getComponent("lvdai").init(self);
- FHolder.isHold = false;
- // console.log("产生第五种落脚点");
- console.log(" 创建滚动1 ");
- break;
- }
- case 5: {
- FHolder = cc.instantiate(self.boli);
- self.FHolderNode.addChild(FHolder, 5, "boli");
- FHolder.getComponent("boli").init(self);
- FHolder.isHold = false;
- // console.log("产生第三种落脚点");
- break;
- }
- case 6: {
- FHolder = cc.instantiate(self.dici);
- self.FHolderNode.addChild(FHolder, 5, "dici");
- FHolder.getComponent("dici").init(self);
- FHolder.isHold = false;
- // console.log("产生第四种落脚点");
- break;
- }
- case 7: {
- // FHolder = cc.instantiate(self.GD);
- // self.FHolderNode.addChild(FHolder, 5, "GD");
- // FHolder.getComponent("GD").init(self, 7);
- // FHolder.isHold = false;
- // break;
- }
- case 8: {
- if (self.lightF) {
- self.lightF = false;
- self.FootHoldGenerator(null);
- break;
- }
- FHolder = cc.instantiate(self.shandian);
- self.FHolderNode.addChild(FHolder, 5, "shandian");
- FHolder.getComponent("shandian").init(self);
- FHolder.isHold = false;
- self.lightF = true;
- break;
- }
- // default:{
- // FHolder = cc.instantiate(self.GD);
- // self.FHolderNode.addChild(FHolder,5,"GD");
- // FHolder.getComponent("GD").init(self);
- // FHolder.getComponent("GD").enabled = true;
- // FHolder.getComponent("MoveGD").init(self);
- // FHolder.getComponent("MoveGD").enabled = false;
- // FHolder.isHold = false;
- // // console.log("默认产生第一种落脚点");
- // }
- // break;
- }
- return FHolder;
- };
- /**
- * 按钮触发,向左,长按事件
- */
- MainScene.prototype.BtnTurnLeft = function (event) {
- var self = this;
- if (self.RkeyDown) {
- return;
- }
- else {
- self.LkeyDown = true;
- self.RkeyDown = false;
- this.BtnLorR(event);
- }
- };
- /**
- * 按钮触发,向右,长按事件,长按响应未解决
- */
- MainScene.prototype.BtnTurnRight = function (event) {
- var self = this;
- if (self.LkeyDown) {
- return;
- }
- else {
- self.LkeyDown = false;
- self.RkeyDown = true;
- this.BtnLorR(event);
- }
- };
- /**
- * btn触发事件
- * @param event 按钮触发事件
- */
- MainScene.prototype.BtnLorR = function (event) {
- var self = this;
- Global_1.default.instance.moveSpeed = 1;
- var schedule = cc.director.getScheduler();
- var stand = self.Player.getChildByName("stand");
- var runRight = self.Player.getChildByName("runRight");
- var run = self.Player.getChildByName("run");
- var Ani; //the animation of player
- var Anistate; //the Ani's state
- var Anistring; //the name of Ani
- var moveByTime = 1;
- var scheduleState = false; //the schedule's state
- var schedulePause = true;
- var target = null; //the target which is binged to schedule
- var moveByDes = Global_1.default.instance.moveSpeed * 120 + 40;
- if (self.LkeyDown) {
- target = self.LEFT;
- moveByTime = 1;
- moveByDes = -moveByDes;
- scheduleState = schedule.isScheduled(func, target);
- // self.output.getComponent(cc.Label).string = Anistring;
- schedulePause = schedule.isTargetPaused(target);
- Ani = run.getComponent(cc.Animation);
- Anistring = "run";
- stand.active = false;
- runRight.active = false;
- run.active = true;
- // self.output.getComponent(cc.Label).string = Anistring;
- if (!Global_1.default.instance.CollisionFlag) {
- moveByTime = 1;
- }
- else {
- switch (Global_1.default.instance.KIND_FootHold) {
- case 2: {
- moveByTime = 4.1;
- self.output.getComponent(cc.Label).string = Global_1.default.instance.KIND_FootHold + "2";
- break;
- }
- case 5: {
- moveByTime = 3.9;
- // self.output.getComponent(cc.Label).string = Global.instance.KIND_FootHold+"5";
- break;
- }
- }
- ;
- }
- }
- if (self.RkeyDown) {
- target = self.RIGHT;
- moveByTime = 1;
- moveByDes = moveByDes;
- scheduleState = schedule.isScheduled(func, target);
- // self.output.getComponent(cc.Label).string = Anistring;
- schedulePause = schedule.isTargetPaused(target);
- Ani = runRight.getComponent(cc.Animation);
- Anistring = "runR";
- stand.active = false;
- runRight.active = true;
- run.active = false;
- // self.output.getComponent(cc.Label).string = Anistring;
- if (!Global_1.default.instance.CollisionFlag) {
- moveByTime = 1;
- }
- else {
- switch (Global_1.default.instance.KIND_FootHold) {
- case 2: {
- moveByTime = 4.1;
- // self.output.getComponent(cc.Label).string = Global.instance.KIND_FootHold+"2";
- break;
- }
- case 5: {
- moveByTime = 3.9;
- // self.output.getComponent(cc.Label).string = Global.instance.KIND_FootHold+"5";
- break;
- }
- }
- ;
- }
- }
- var funcFlag = false;
- switch (event.type) {
- case "touchstart": {
- if (!(self.moveFalg.length == 0)) {
- break;
- }
- self.moveFalg = "touchstart";
- if (!scheduleState) {
- // self.output.getComponent(cc.Label).string = movefalg;
- schedule.schedule(func, target, 0);
- }
- ;
- if (schedulePause) {
- schedule.resumeTarget(target);
- }
- ;
- break;
- }
- case "touchmove": {
- if (!(self.moveFalg.length == 0)) {
- break;
- }
- self.moveFalg = "touchmove";
- // self.output.getComponent(cc.Label).string = movefalg;
- if (!scheduleState) {
- schedule.schedule(func, target, 0);
- }
- ;
- if (schedulePause) {
- schedule.resumeTarget(target);
- }
- ;
- break;
- }
- case "touchcancel": {
- break;
- }
- case "touchend": {
- // self.output.getComponent(cc.Label).string = "touchend";
- schedule.pauseTarget(target);
- self.Player.stopAllActions();
- Ani.stop(Anistring);
- moveByTime = 1;
- moveByDes = Global_1.default.instance.moveSpeed * 120 + 40;
- switch (Anistring) {
- case "run": {
- run.active = false;
- runRight.active = false;
- stand.active = true;
- self.LkeyDown = false;
- self.RkeyDown = false;
- moveByDes = Global_1.default.instance.moveSpeed / 2;
- break;
- }
- case "runR": {
- run.active = false;
- runRight.active = false;
- stand.active = true;
- self.LkeyDown = false;
- self.RkeyDown = false;
- moveByDes = Global_1.default.instance.moveSpeed / 2;
- break;
- }
- }
- funcFlag = false;
- self.moveFalg = "";
- break;
- }
- }
- function func() {
- if (funcFlag) {
- return;
- }
- if (Global_1.default.instance.CollisionFlag) {
- moveByTime = 1;
- }
- var spawn = cc.spawn(cc.callFunc(function () {
- self.Player.runAction(cc.moveBy(moveByTime, moveByDes, 0));
- }), cc.callFunc(function () {
- Anistate = Ani.play(Anistring);
- Anistate.speed = 1;
- Anistate.repeatCount = 100;
- Anistate = Ani.playAdditive(Anistring);
- }));
- self.Player.runAction(spawn);
- funcFlag = true;
- }
- };
- /**
- * 返回键监听
- * @param event 按下返回键退出游戏
- */
- MainScene.prototype.AniPlayer = function (Ani, Anistate, moveByTime, moveByDes, Key, AniName, self) {
- Ani = Key.getComponent(cc.Animation);
- var spawn = cc.spawn(cc.callFunc(function () {
- self.Player.runAction(cc.moveBy(moveByTime, moveByDes, 0));
- }), cc.callFunc(function () {
- Anistate = Ani.play(AniName);
- Anistate.speed = 2;
- Anistate.repeatCount = 100;
- }));
- self.Player.runAction(spawn);
- if (!Ani.state) {
- var spawn2 = cc.spawn(cc.callFunc(function () {
- self.Player.runAction(cc.moveBy(moveByTime, moveByDes, 0));
- }), cc.callFunc(function () {
- Anistate = Ani.play(AniName);
- Anistate.speed = 2;
- Anistate.repeatCount = 100;
- }));
- self.Player.runAction(spawn2);
- }
- };
- /**
- * 抬起动画停止
- * @param event 抬起左右键触发
- */
- MainScene.prototype.onKeyUp = function (event) {
- var self = this;
- self.LkeyDown = false;
- this.RkeyDown = false;
- self.Player.stopAllActions();
- var stand = this.Player.getChildByName("stand");
- var runRight = this.Player.getChildByName("runRight");
- var run = this.Player.getChildByName("run");
- stand.active = true;
- run.active = false;
- runRight.active = false;
- };
- MainScene.prototype.pretreatmentGameover = function () {
- var _this = this;
- if (!Global_1.default.instance.OverFlag && this.once == false) {
- this.once = true;
- MessManager_1.default.getInstance().getUserSore(function (res) {
- console.error('收到正常消息一次');
- // console.error(res);
- if (_this.fuhuoCount-- > 0) {
- _this.showFail(res.data.thirty_score, res.data.one_hundred_score);
- }
- else {
- _this.gameOver(res.data.thirty_score, res.data.one_hundred_score);
- _this.once = false;
- }
- }, function () {
- console.error('收到失败消息一次');
- _this.gameOver();
- _this.once = false;
- });
- }
- };
- MainScene.prototype.showFailPnael = function () {
- var failure = cc.instantiate(this.failure);
- var ReStartBtnreGame = failure.getChildByName("reset").getComponent(cc.Button);
- var reGameEventHandler = new cc.Component.EventHandler();
- reGameEventHandler.target = this.node;
- reGameEventHandler.component = "MainScene";
- reGameEventHandler.handler = "restart";
- reGameEventHandler.customEventData = null;
- ReStartBtnreGame.clickEvents.push(reGameEventHandler);
- };
- MainScene.prototype.showFail = function (score1, score2) {
- if (score1 === void 0) { score1 = 0; }
- if (score2 === void 0) { score2 = 0; }
- var self = this;
- var failure;
- var Score;
- failure = cc.instantiate(self.failure);
- var ReStartBtnreGame = failure.getChildByName("reset").getComponent(cc.Button);
- var fuhuo = failure.getChildByName("fuhuo").getComponent(cc.Button);
- failure.getChildByName("fuhuo").active = true;
- this.init2Btn(fuhuo, ReStartBtnreGame);
- if (!Global_1.default.instance.OverFlag) {
- Global_1.default.instance.OverFlag = true;
- this.Player.active = false;
- failure.y = -20;
- self.node.addChild(failure);
- Score = failure.getChildByName("cj").getChildByName("Score");
- Score.getComponent(cc.Label).string = self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string;
- if (parseInt(Score.getComponent(cc.Label).string) >= 100) {
- failure.getChildByName("fuhuo").active = false;
- }
- else {
- failure.getChildByName("fuhuo").active = true;
- }
- var TipSNode = failure.getChildByName("sb");
- this.initFailStr(Score, TipSNode, failure, score1, score2);
- }
- else {
- return;
- }
- };
- /**
- *
- */
- MainScene.prototype.gameOver = function (score1, score2) {
- if (score1 === void 0) { score1 = 0; }
- if (score2 === void 0) { score2 = 0; }
- var self = this;
- self.Player.stopAllActions();
- Global_1.default.instance.CollisionFlag = false;
- // self.Player.getComponent(cc.BoxCollider).enabled = false;
- self.Player.getComponent("Playcontroler").enabled = false;
- try {
- self.Player.getComponent(cc.Animation).stop();
- }
- catch (error) {
- self.node.getChildByName("output").getComponent(cc.Label).string = error;
- }
- self.Player.getChildByName("stand").active = true;
- self.Player.getChildByName("runRight").active = false;
- self.Player.getChildByName("run").active = false;
- self.Player.y -= Global_1.default.instance.InitSpeed;
- var AllFH = self.node.getChildByName("BgNode").getChildByName("FHolder").children;
- for (var i = 0; i < AllFH.length; i++) {
- var FHNA = AllFH[i].name;
- AllFH[i].getComponent(FHNA).enabled = false;
- AllFH[i].isHold = false;
- if (FHNA == "GD") {
- AllFH[i].getChildByName("gd").getComponent("CliGD").enabled = false;
- }
- }
- self.StopAni(self);
- for (var i = 0; i < this.LifeDing.children.length; i++) {
- if (this.LifeDing.children[i].name == "lifeBG") {
- this.LifeDing.children[i].active = false;
- }
- }
- self.LEFT.node.active = false;
- self.RIGHT.node.active = false;
- self.playdeadsound();
- var failure;
- var Score;
- failure = cc.instantiate(self.failure);
- var ReStartBtnreGame = failure.getChildByName("reset").getComponent(cc.Button);
- var fuhuo = failure.getChildByName("fuhuo").getComponent(cc.Button);
- failure.getChildByName("fuhuo").active = false;
- this.init2Btn(fuhuo, ReStartBtnreGame);
- if (!Global_1.default.instance.OverFlag) {
- Global_1.default.instance.OverFlag = true;
- this.Player.active = false;
- failure.y = -20;
- self.node.addChild(failure);
- Score = failure.getChildByName("cj").getChildByName("Score");
- Score.getComponent(cc.Label).string = self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string;
- var TipSNode = failure.getChildByName("sb");
- this.initFailStr(Score, TipSNode, failure, score1, score2);
- }
- else {
- return;
- }
- console.log("游戏结束!!!");
- };
- MainScene.prototype.init2Btn = function (fuhuo, reset) {
- var FuhupEventHandler = new cc.Component.EventHandler();
- FuhupEventHandler.target = this.node;
- FuhupEventHandler.component = "MainScene";
- FuhupEventHandler.handler = "fuhuoOnce";
- FuhupEventHandler.customEventData = null;
- fuhuo.clickEvents.push(FuhupEventHandler);
- var reGameEventHandler = new cc.Component.EventHandler();
- reGameEventHandler.target = this.node;
- reGameEventHandler.component = "MainScene";
- reGameEventHandler.handler = "restart";
- reGameEventHandler.customEventData = null;
- reset.clickEvents.push(reGameEventHandler);
- };
- MainScene.prototype.initFailStr = function (CurrentScore, tipsNode, failure, score1, score2) {
- if (parseInt(CurrentScore.getComponent(cc.Label).string) >= 100) {
- tipsNode.getComponent(cc.Label).string = "成功";
- }
- else {
- tipsNode.getComponent(cc.Label).string = "失败";
- }
- failure.getChildByName("tips").active = false;
- failure.getChildByName("tips").getComponent(cc.Label).string = "\u4ECA\u65E5\u53EF\u83B7\u5F97\u5956\u52B1\n60\u5C42\u8FC7\u5173\u5956\u52B1: " + score1 + "/90 \u79EF\u5206\n100\u5C42\u901A\u5173\u5956\u52B1: " + score2 + "/100\u79EF\u5206";
- failure.getChildByName("tips").active = true;
- };
- MainScene.prototype.fuhuoOnce = function (a, b, c) {
- var _this = this;
- var once = function () {
- Global_1.default.instance.OverFlag = false;
- var AllFH = _this.node.getChildByName("BgNode").getChildByName("FHolder").children;
- for (var i = 0; i < AllFH.length; i++) {
- AllFH[i].destroy();
- }
- for (var i = 0; i < _this.LifeDing.children.length; i++) {
- if (_this.LifeDing.children[i].name == "lifeBG") {
- if (!_this.LifeDing.children[i].active) {
- _this.LifeDing.children[i].active = true;
- }
- Global_1.default.instance.reLife.push(_this.LifeDing.children[i]);
- }
- }
- _this.Player.getComponent(cc.BoxCollider).enabled = false;
- _this.Player.y = 300;
- _this.scheduleOnce(function () {
- Global_1.default.instance.CollisionFlag = false;
- _this.Player.active = true;
- _this.Player.getComponent(cc.BoxCollider).enabled = true;
- }, 0.1);
- a.target.parent.destroy();
- _this.FootHoldGenerator(1).y = -380;
- _this.FootHoldGenerator(1).y = -220;
- _this.FootHoldGenerator(1).y = -100;
- _this.once = false;
- };
- if (CC_DEBUG) {
- once();
- return;
- }
- MessManager_1.default.getInstance().changeScore(-10, function () {
- once();
- }, function () {
- once();
- });
- };
- /**
- * 复活按钮的回调函数:打开排行榜
- */
- MainScene.prototype.FBtnCB_Rank = function (self) {
- this.destroy();
- cc.director.loadScene("EndScene");
- };
- /**
- * 复活按钮的回调函数:立即复活
- */
- MainScene.prototype.FBtnCB_rePlay = function () {
- cc.sys.localStorage.setItem("hfsj", "99");
- var self = this;
- Global_1.default.instance.OverFlag = false;
- Global_1.default.instance.AniFalg = false;
- Global_1.default.instance.LorR = 0;
- Global_1.default.instance.InitSpeed = Global_1.default.instance.ConstInitSpeed;
- Global_1.default.instance.moveSpeed = 1;
- // Global.instance.FHFallSpeed = 2;
- Global_1.default.instance.CollisionFlag = false;
- Global_1.default.instance.CollisionWithDing = false;
- Global_1.default.instance.TheHolder = null;
- Global_1.default.instance.KIND_FootHold = 0;
- // this.RIGHT.node.off(cc.Node.EventType.TOUCH_START,this.BtnTurnRight,this);
- // this.RIGHT.node.off(cc.Node.EventType.TOUCH_MOVE,this.BtnTurnRight,this);
- // this.RIGHT.node.off(cc.Node.EventType.TOUCH_CANCEL,this.onKeyUp,this);
- this.LEFT.node.active = true;
- this.RIGHT.node.active = true;
- this.LkeyDown = false;
- this.RkeyDown = false;
- this.moveFalg = "";
- this.Player.y = 300;
- this.Player.x = 0;
- this.Player.getComponent("Playcontroler").enabled = true;
- this.Player.getComponent(cc.BoxCollider).enabled = true;
- var AllFH = this.node.getChildByName("BgNode").getChildByName("FHolder").children;
- this.node.getChildByName("SB").destroy();
- // this.node.getChildByName("fuhuo1").destroy();
- for (var i = 0; i < this.LifeDing.children.length; i++) {
- //for(let i=0;i<2;i++){
- if (this.LifeDing.children[i].name == "lifeBG") {
- if (!this.LifeDing.children[i].active) {
- this.LifeDing.children[i].active = true;
- }
- Global_1.default.instance.reLife.push(this.LifeDing.children[i]);
- }
- }
- this.Player.getComponent(cc.BoxCollider).enabled = false;
- for (var i = 0; i < AllFH.length; i++) {
- AllFH[i].destroy();
- }
- var F = this.FootHoldGenerator(1);
- F.y = -380;
- this.scheduleOnce(function () {
- self.Player.getComponent(cc.BoxCollider).enabled = true;
- }, 0.5);
- };
- /**
- * restart
- */
- MainScene.prototype.restart = function () {
- this.destroy();
- cc.director.loadScene("MainScene");
- cc.director.resume();
- Global_1.default.instance.OverFlag = false;
- Global_1.default.instance.AniFalg = false;
- Global_1.default.instance.LorR = 0;
- Global_1.default.instance.InitSpeed = Global_1.default.instance.ConstInitSpeed;
- Global_1.default.instance.moveSpeed = 1;
- Global_1.default.instance.FHFallSpeed = 2;
- Global_1.default.instance.CollisionFlag = false;
- Global_1.default.instance.CollisionWithDing = false;
- Global_1.default.instance.TheHolder = null;
- Global_1.default.instance.KIND_FootHold = 0;
- // this.RIGHT.node.off(cc.Node.EventType.TOUCH_START,this.BtnTurnRight,this);
- // this.RIGHT.node.off(cc.Node.EventType.TOUCH_MOVE,this.BtnTurnRight,this);
- // this.RIGHT.node.off(cc.Node.EventType.TOUCH_CANCEL,this.onKeyUp,this);
- this.LEFT.node.active = true;
- this.RIGHT.node.active = true;
- this.LkeyDown = false;
- this.RkeyDown = false;
- // this.moveFalg = "";
- this.Player.y = 300;
- // this.Score();
- };
- /**
- * 受到伤害,命数减一
- */
- MainScene.prototype.reduceLife = function () {
- var self = this;
- var Ls = new Array();
- var reLCount = 0;
- var FHolder = self.node.getChildByName("BgNode").getChildByName("FHolder").children;
- for (var i = 0; i < FHolder.length; i++) {
- if (FHolder[i].isHold) {
- if (!Global_1.default.instance.CollisionFlag) {
- FHolder[i].isHold = false;
- var box = FHolder[i].getComponent(cc.BoxCollider);
- box.enabled = false;
- }
- }
- }
- //
- for (var i = self.LifeDing.children.length - 1; i >= 0; i--) {
- if (self.LifeDing.children[i].name == "lifeBG") {
- if (Global_1.default.instance.Injured || Global_1.default.instance.CollisionWithDing) {
- if (self.LifeDing.children[i].active) {
- self.LifeDing.children[i].active = false;
- Global_1.default.instance.Injured = false;
- Global_1.default.instance.CollisionFlag = false;
- Global_1.default.instance.CollisionWithDing = false;
- }
- }
- Ls.push(self.LifeDing.children[i]);
- }
- }
- Global_1.default.instance.reLife = [];
- for (var i = 0; i < Ls.length; i++) {
- if (Ls[i].active) {
- Global_1.default.instance.reLife.push(Ls[i]); //player剩余的命数
- }
- }
- //
- var time = cc.sys.localStorage.getItem("hfsj");
- //console.log( time + "当前血 : " + Global.instance.reLife.length);
- if (Global_1.default.instance.reLife.length < 3) {
- if (time == 99) {
- var time_1 = Math.floor(Date.now() / 1000);
- cc.sys.localStorage.setItem("hfsj", time_1);
- }
- else {
- var time_2 = Math.floor(Date.now() / 1000);
- var timlod = parseInt(cc.sys.localStorage.getItem("hfsj"));
- var sub = time_2 - timlod;
- if (sub >= 20) {
- var sizes = Global_1.default.instance.reLife.length + 2;
- Global_1.default.instance.reLife = [];
- for (var i = 0; i < sizes; i++) {
- if (this.LifeDing.children[i].name == "lifeBG") {
- if (!this.LifeDing.children[i].active) {
- this.LifeDing.children[i].active = true;
- }
- Global_1.default.instance.reLife.push(this.LifeDing.children[i]);
- // console.log("push --------------" + i);
- }
- }
- cc.sys.localStorage.setItem("hfsj", time_2);
- // console.log(sizes + "恢复血+1---------------------------------------" + Global.instance.reLife.length);
- }
- }
- }
- else {
- cc.sys.localStorage.setItem("hfsj", "99");
- }
- };
- /**
- * 每下落一层,分数加一。
- */
- MainScene.prototype.Score = function () {
- var _this = this;
- var self = this.node;
- var scLabel = this.LifeDing.getChildByName("Floor").getComponent(cc.Label);
- var sc = parseInt(scLabel.string);
- if (!Global_1.default.instance.OverFlag) {
- sc = sc + 1;
- }
- this.playtansound();
- console.log("打印一下");
- scLabel.string = sc.toString();
- if (sc == 60) {
- MessManager_1.default.getInstance().questServer(30, null, null);
- }
- if (sc == 100) {
- MessManager_1.default.getInstance().questServer(100, function () {
- _this.pretreatmentGameover();
- }, null);
- ///
- }
- var lv = Math.ceil(sc / 25);
- if (lv > Global_1.default.instance.LevelAddFlag) {
- Global_1.default.instance.LevelAddFlag = lv;
- Global_1.default.instance.InitSpeed += 0.5; //每下落50层,player下落速度加0.25
- Global_1.default.instance.FHFallSpeed += 1; //没下落50层,落脚点下落速度加快0.5.
- if (sc == 50) {
- Global_1.default.instance.InitSpeed += 1; //每下落50层,player下落速度加0.25
- Global_1.default.instance.FHFallSpeed += 2; //没下落50层,落脚点下落速度加快0.5.
- }
- if (sc == 70) {
- Global_1.default.instance.InitSpeed += 2; //每下落50层,player下落速度加0.25
- Global_1.default.instance.FHFallSpeed += 4; //没下落50层,落脚点下落速度加快0.5.
- }
- }
- };
- /**
- * 本地分数存储
- */
- MainScene.prototype.StoregeScore = function () {
- var self = this;
- var localS = Global_1.default.instance.getLocalScore(); //the temp of local score;
- var CurrentScore = parseInt(this.LifeDing.getChildByName("Floor").getComponent(cc.Label).string);
- Global_1.default.instance.getLocalScore().CurrentScore = CurrentScore;
- if (CurrentScore > localS.ThirdScore) {
- if (CurrentScore > localS.SecondScore) {
- if (CurrentScore > localS.BestScore) {
- localS.BestScore = CurrentScore;
- return;
- }
- localS.SecondScore = CurrentScore;
- }
- localS.ThirdScore = CurrentScore;
- }
- };
- /**
- * upload the best score
- */
- MainScene.prototype.UpLoadScore = function () {
- var self = this;
- var tmp = Global_1.default.instance.GetUSer();
- /* Http.sendRequest("/updateScore",tmp,function(msg){
- let x = msg;
- if(msg.code!=0){
- Global.instance.NetStatus = false;
- }
- let ux = {
- userId:'',
- }
- console.log(x);
- ux.userId = Global.instance.GetUSer().userId;
- Http.sendRequest("/rank",ux,function(mmsg){
- console.log("------------------3");
- let MM = JSON.parse(mmsg.msg);
- console.log(MM);
- if(Global.instance.GetR()==null||Global.instance.GetR().rank==undefined||Global.instance.GetR().rank<MM.my.rank){
- Global.instance.SetR(MM.my.rank);
- Global.instance.setRemoteScore(MM.other);
- }
- });
- });*/
- };
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "boli", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "dici", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "lvdai", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "shandian", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "tanhuang", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "Opplvdai", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "GD", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "failure", void 0);
- __decorate([
- property(cc.Prefab)
- ], MainScene.prototype, "fuhuo", void 0);
- __decorate([
- property(cc.Node)
- ], MainScene.prototype, "Player", void 0);
- __decorate([
- property(cc.Node)
- ], MainScene.prototype, "FHolderNode", void 0);
- __decorate([
- property(cc.Node)
- ], MainScene.prototype, "Bg", void 0);
- __decorate([
- property(cc.Node)
- ], MainScene.prototype, "LifeDing", void 0);
- __decorate([
- property(cc.Button)
- ], MainScene.prototype, "LEFT", void 0);
- __decorate([
- property(cc.Button)
- ], MainScene.prototype, "RIGHT", void 0);
- __decorate([
- property(cc.Label)
- ], MainScene.prototype, "output", void 0);
- MainScene = __decorate([
- ccclass
- ], MainScene);
- return MainScene;
- }(cc.Component));
- exports.default = MainScene;
- cc._RF.pop();
|