1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042 |
- "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 _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,
- };
- return _this;
- }
- MainScene.prototype.onLoad = function () {
- 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.y = -150;
- 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.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 = FHolder.x;
- // 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 < (-510)) {
- for (var i = 0; i < this.LifeDing.children.length; i++) {
- if (this.LifeDing.children[i].name == "lifeBG") {
- this.LifeDing.children[i].active = false;
- }
- }
- this.gameOver();
- }
- if (Global_1.default.instance.reLife.length == 0) {
- this.gameOver();
- }
- this.ETime = Date.now();
- var AllChildren = new Array();
- var GDChildren = new Array();
- AllChildren = this.node.getChildByName("BgNode").getChildByName("FHolder").children;
- for (var 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) {
- // let nameNode:string = FHArray[i].name;
- if (self.Player.x > (FHArray[i].x + 75)) {
- Global_1.default.instance.CollisionFlag = false;
- FHArray[i].isHold = false;
- // this.Score();
- }
- else if (self.Player.x < (FHArray[i].x - 75)) {
- Global_1.default.instance.CollisionFlag = false;
- FHArray[i].isHold = false;
- // this.Score();
- }
- 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;
- /*self.FootHoldGenerator();
- FHolder = cc.instantiate(self.tanhuang);
- self.FHolderNode.addChild(FHolder,5,"tanhuang");
- FHolder.getComponent("tanhuang").init(self);
- FHolder.isHold = false;
- // // console.log("产生第五种落脚点");
- // break;*/
- 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;
- };
- /**
- * gameover
- */
- MainScene.prototype.gameOver = function () {
- 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);
- var failure;
- var Ani;
- var Anistate;
- var BestScore;
- var thisScore;
- var lessScore;
- var Score;
- // let fuhuo;
- var FAni;
- var FAnistate;
- self.LEFT.node.active = false;
- self.RIGHT.node.active = false;
- failure = cc.instantiate(self.failure);
- // fuhuo = cc.instantiate(self.fuhuo);
- // let fhuoBtnRank = fuhuo.getChildByName("cd").getChildByName("RankScene").getComponent(cc.Button);
- var fhuoBtnreGame = failure.getChildByName("reset").getComponent(cc.Button);
- // let fhuoBtnreGame = fuhuo.getChildByName("zl").getChildByName("rePlay").getComponent(cc.Button);
- // let fhuoBtnFhuo = fuhuo.getChildByName("fh").getChildByName("rePlay").getComponent(cc.Button);
- var RankEventHandler = new cc.Component.EventHandler();
- var reGameEventHandler = new cc.Component.EventHandler();
- var FhuoEventHandler = new cc.Component.EventHandler();
- //open the ranking
- // RankEventHandler.target = self.node;
- // RankEventHandler.component = "MainScene";
- // RankEventHandler.handler = "FBtnCB_Rank";
- // RankEventHandler.customEventData = null;
- // fhuoBtnRank.clickEvents.push(RankEventHandler);
- //replay
- reGameEventHandler.target = self.node;
- reGameEventHandler.component = "MainScene";
- reGameEventHandler.handler = "restart";
- reGameEventHandler.customEventData = null;
- fhuoBtnreGame.clickEvents.push(reGameEventHandler);
- //fh立即复活会有其他功能暂时用重新开始代替
- // FhuoEventHandler.target = self.node;
- // FhuoEventHandler.component = "MainScene";
- // FhuoEventHandler.handler = "FBtnCB_rePlay";
- // FhuoEventHandler.customEventData = null;
- // fhuoBtnFhuo.clickEvents.push(FhuoEventHandler);
- if (!Global_1.default.instance.OverFlag) {
- Global_1.default.instance.OverFlag = true;
- self.StoregeScore();
- // self.UpdateScore();
- failure.y = -20;
- // fuhuo.y = 0;
- thisScore = parseInt(self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string);
- // lessScore = failure.getChildByName("jl").getChildByName("LessScore");
- BestScore = Global_1.default.instance.getLocalScore().BestScore;
- Global_1.default.instance.GetUSer().score = BestScore;
- self.UpLoadScore();
- if (BestScore - thisScore <= 0) {
- failure.getChildByName("jl").active = false;
- }
- else {
- // lessScore.getComponent(cc.Label).string = (BestScore - thisScore).toString();
- }
- Score = failure.getChildByName("cj").getChildByName("Score");
- self.node.addChild(failure);
- // self.node.addChild(fuhuo);
- Score.getComponent(cc.Label).string = self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string;
- // Ani = failure.getComponent(cc.Animation);//the animation of failure;
- // // FAni = fuhuo.getComponent(cc.Animation);
- // Anistate = Ani.play("shibai");//the state of Ani;
- // Anistate.speed = 1;
- // Anistate.repeatCount = 1;
- }
- else {
- return;
- }
- self.playdeadsound();
- console.log("游戏结束!!!");
- };
- /**
- * 复活按钮的回调函数:打开排行榜
- */
- 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 = 8.5;
- 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 = 8.5;
- 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 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();
- var lv = Math.ceil(sc / 50);
- if (lv > Global_1.default.instance.LevelAddFlag) {
- Global_1.default.instance.LevelAddFlag = lv;
- Global_1.default.instance.InitSpeed += 0.25; //每下落50层,player下落速度加0.25
- Global_1.default.instance.FHFallSpeed += 1; //没下落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();
|