72605d56-81ac-477a-9fc6-d48d39956e27.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. "use strict";
  2. cc._RF.push(module, '726051WgaxHep/G1I05lW4n', 'MainScene');
  3. // Script/MainScene.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. 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;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var Global_1 = require("./Global");
  26. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  27. var MainScene = /** @class */ (function (_super) {
  28. __extends(MainScene, _super);
  29. function MainScene() {
  30. var _this = _super !== null && _super.apply(this, arguments) || this;
  31. _this.boli = null;
  32. _this.dici = null;
  33. _this.lvdai = null;
  34. _this.shandian = null;
  35. _this.tanhuang = null;
  36. _this.Opplvdai = null;
  37. _this.GD = null;
  38. _this.failure = null;
  39. _this.fuhuo = null;
  40. _this.Player = null;
  41. _this.FHolderNode = null;
  42. _this.Bg = null;
  43. _this.LifeDing = null;
  44. _this.LEFT = null;
  45. _this.RIGHT = null;
  46. _this.output = null;
  47. // LIFE-CYCLE CALLBACKS:
  48. /**
  49. * 上一个落脚点生成时间
  50. */
  51. _this.STime = 0;
  52. /**
  53. * 当前落脚点生成时间
  54. */
  55. _this.ETime = 0;
  56. /** Left*/
  57. _this.LkeyDown = false;
  58. /** Right*/
  59. _this.RkeyDown = false;
  60. /**the loght FootHolder F */
  61. _this.lightF = false;
  62. _this.moveFalg = "";
  63. _this.USERINFO = {
  64. userId: "",
  65. score: 0,
  66. };
  67. return _this;
  68. }
  69. MainScene.prototype.onLoad = function () {
  70. var time = cc.sys.localStorage.getItem("hfsj");
  71. if (time == null || time == undefined || time == "") {
  72. cc.sys.localStorage.setItem("hfsj", "99");
  73. }
  74. this.LifeDing.zIndex = 10;
  75. this.FHolderNode.zIndex = 9;
  76. Global_1.default.instance.setMN(this.node);
  77. this.STime = Date.now();
  78. var FHolder = cc.instantiate(this.GD);
  79. this.FHolderNode.addChild(FHolder, 10, "GD");
  80. FHolder.getComponent("GD").init(this, 1);
  81. FHolder.y = -150;
  82. var FHolder2 = cc.instantiate(this.lvdai);
  83. this.FHolderNode.addChild(FHolder2, 10, "lvdai");
  84. FHolder2.getComponent("lvdai").init(this);
  85. FHolder2.y = -300;
  86. // let FHolder2 = cc.instantiate(this.tanhuang);
  87. // this.FHolderNode.addChild(FHolder2,10,"tanhuang");
  88. // FHolder2.getComponent("tanhuang").init(this);
  89. // FHolder2.y = -300;
  90. var FHolder3 = cc.instantiate(this.GD);
  91. this.FHolderNode.addChild(FHolder3, 10, "GD");
  92. FHolder3.getComponent("GD").init(this, 1);
  93. FHolder3.y = -450;
  94. // this.Player.active = false;
  95. this.Player.x = FHolder.x;
  96. // this.Player.y = FHolder.y+60;
  97. this.Player.zIndex = 11;
  98. for (var i = 0; i < this.LifeDing.children.length; i++) {
  99. if (this.LifeDing.children[i].name == "lifeBG") {
  100. if (!this.LifeDing.children[i].active) {
  101. this.LifeDing.children[i].active = true;
  102. }
  103. Global_1.default.instance.reLife.push(this.LifeDing.children[i]);
  104. }
  105. }
  106. cc.director.getCollisionManager().enabled = true;
  107. // cc.director.getCollisionManager().enabledDebugDraw = true;
  108. cc.director.getCollisionManager().enabledDrawBoundingBox = false;
  109. };
  110. MainScene.prototype.playtansound = function () {
  111. if (Global_1.default.instance.OverFlag == false) {
  112. cc.loader.loadRes("tan", cc.AudioClip, function (err, clip) {
  113. var audioID = cc.audioEngine.play(clip, false, 0.5);
  114. });
  115. }
  116. };
  117. MainScene.prototype.playdeadsound = function () {
  118. cc.loader.loadRes("dead", cc.AudioClip, function (err, clip) {
  119. var audioID = cc.audioEngine.play(clip, false, 0.5);
  120. });
  121. };
  122. MainScene.prototype.start = function () {
  123. };
  124. MainScene.prototype.update = function (dt) {
  125. // console.log(Global.instance.CollisionFlag);
  126. this.MoveBg();
  127. Global_1.default.instance.moveSpeed = 1;
  128. var FHolder;
  129. if ((this.ETime - this.STime) > (1200 - (180 * (Global_1.default.instance.FHFallSpeed - 2)))) { //控制落脚点之间的间距,间距144px
  130. this.STime = Date.now();
  131. if (!Global_1.default.instance.OverFlag) {
  132. FHolder = this.FootHoldGenerator(null);
  133. // this.Score();
  134. }
  135. }
  136. this.FHolder();
  137. this.reduceLife();
  138. if (Global_1.default.instance.CollisionFlag) { //左右传送带减速
  139. switch (Global_1.default.instance.KIND_FootHold) {
  140. case 3: {
  141. this.Player.x += 2;
  142. break;
  143. }
  144. case 4: {
  145. this.Player.x -= 2;
  146. break;
  147. }
  148. case 7: {
  149. if (Global_1.default.instance.LorR == 1) {
  150. this.Player.x--;
  151. }
  152. else {
  153. this.Player.x++;
  154. }
  155. break;
  156. }
  157. default: {
  158. break;
  159. }
  160. }
  161. }
  162. if (this.Player.x < -180) {
  163. this.Player.x = -180;
  164. }
  165. if (this.Player.x > 180) {
  166. this.Player.x = 180;
  167. }
  168. if (this.Player.y < (-510)) {
  169. for (var i = 0; i < this.LifeDing.children.length; i++) {
  170. if (this.LifeDing.children[i].name == "lifeBG") {
  171. this.LifeDing.children[i].active = false;
  172. }
  173. }
  174. this.gameOver();
  175. }
  176. if (Global_1.default.instance.reLife.length == 0) {
  177. this.gameOver();
  178. }
  179. this.ETime = Date.now();
  180. var AllChildren = new Array();
  181. var GDChildren = new Array();
  182. AllChildren = this.node.getChildByName("BgNode").getChildByName("FHolder").children;
  183. for (var i = 0; i < AllChildren.length; i++) {
  184. if (AllChildren[i].name == "GD") {
  185. GDChildren.push(AllChildren[i]);
  186. }
  187. }
  188. // cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,this.onKeyDown,this);
  189. //cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP,this.onKeyUp,this);
  190. this.Listener();
  191. };
  192. MainScene.prototype.Listener = function () {
  193. var _this = this;
  194. var btnClickArr = new Array(2);
  195. if (!this.LkeyDown) {
  196. this.RIGHT.node.on(cc.Node.EventType.TOUCH_START, this.BtnTurnRight, this);
  197. this.RIGHT.node.on(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnRight, this);
  198. this.RIGHT.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
  199. btnClickArr.push(this.RIGHT);
  200. this.RIGHT.node.on(cc.Node.EventType.TOUCH_END, function () {
  201. _this.onKeyUp;
  202. }, this);
  203. }
  204. else {
  205. this.RIGHT.node.off(cc.Node.EventType.TOUCH_START, this.BtnTurnRight, this);
  206. this.RIGHT.node.off(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnRight, this);
  207. this.RIGHT.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
  208. this.RIGHT.node.off(cc.Node.EventType.TOUCH_END, function () {
  209. _this.onKeyUp;
  210. }, this);
  211. }
  212. if (!this.RkeyDown) {
  213. this.LEFT.node.on(cc.Node.EventType.TOUCH_START, this.BtnTurnLeft, this);
  214. this.LEFT.node.on(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnLeft, this);
  215. this.LEFT.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
  216. // btnClickArr.push(this.LEFT);
  217. this.LEFT.node.on(cc.Node.EventType.TOUCH_END, function () {
  218. _this.onKeyUp;
  219. }, this);
  220. }
  221. else {
  222. this.LEFT.node.off(cc.Node.EventType.TOUCH_START, this.BtnTurnLeft, this);
  223. this.LEFT.node.off(cc.Node.EventType.TOUCH_MOVE, this.BtnTurnLeft, this);
  224. this.LEFT.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onKeyUp, this);
  225. this.LEFT.node.off(cc.Node.EventType.TOUCH_END, function () {
  226. _this.onKeyUp;
  227. }, this);
  228. }
  229. };
  230. MainScene.prototype.StopAni = function (self) {
  231. if (!Global_1.default.instance.AniFalg) {
  232. var FHolder = self.node.getChildByName("BgNode").getChildByName("FHolder").children;
  233. var Fname = void 0;
  234. for (var i = 0; FHolder.length; i++) {
  235. if (i == FHolder.length - 1) {
  236. Global_1.default.instance.AniFalg = true;
  237. return;
  238. }
  239. Fname = FHolder[i].name;
  240. FHolder[i].getComponent(Fname).enabled = false;
  241. }
  242. }
  243. };
  244. /**
  245. * player 移出落脚点
  246. */
  247. MainScene.prototype.FHolder = function () {
  248. var self = this;
  249. var FHArray = this.FHolderNode.children;
  250. var Ani; //the Animation of Player when player fall down
  251. var Anistate; //the state of Ani;
  252. for (var i = FHArray.length - 1; i >= 0; i--) {
  253. if (FHArray[i].isHold) {
  254. // let nameNode:string = FHArray[i].name;
  255. if (self.Player.x > (FHArray[i].x + 75)) {
  256. Global_1.default.instance.CollisionFlag = false;
  257. FHArray[i].isHold = false;
  258. // this.Score();
  259. }
  260. else if (self.Player.x < (FHArray[i].x - 75)) {
  261. Global_1.default.instance.CollisionFlag = false;
  262. FHArray[i].isHold = false;
  263. // this.Score();
  264. }
  265. else {
  266. Global_1.default.instance.CollisionFlag = true;
  267. FHArray[i].isHold = true;
  268. }
  269. }
  270. }
  271. };
  272. /**
  273. * 移动背景,初始移动速度200px/s
  274. */
  275. MainScene.prototype.MoveBg = function () {
  276. var Bg0 = this.Bg.getChildByName("Bg_0");
  277. var Bg1 = this.Bg.getChildByName("Bg_1");
  278. if (Global_1.default.instance.OverFlag) {
  279. }
  280. else {
  281. Bg0.y += Global_1.default.instance.FHFallSpeed + 1;
  282. Bg1.y += Global_1.default.instance.FHFallSpeed + 1;
  283. if (Bg0.y > 946) {
  284. Bg0.y = -946;
  285. }
  286. if (Bg1.y > 946) {
  287. Bg1.y = -946;
  288. }
  289. }
  290. };
  291. /**
  292. * 生成落脚点
  293. */
  294. MainScene.prototype.FootHoldGenerator = function (rtpe) {
  295. var self = this;
  296. var Magnification = 0;
  297. var f = parseInt(self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string);
  298. if (f < 20) {
  299. Magnification = 2;
  300. }
  301. else if (f < 40) {
  302. Magnification = 4;
  303. }
  304. else if (f < 60) {
  305. Magnification = 6;
  306. }
  307. else if (f < 80) {
  308. Magnification = 8;
  309. }
  310. else {
  311. Magnification = 8;
  312. }
  313. var KindHolder = Math.ceil(Math.random() * Magnification);
  314. // KindHolder = 7;
  315. var FHolder;
  316. // KindHolder = Math.ceil(Math.random()*7);
  317. if (KindHolder == 3 || KindHolder == 4) {
  318. var va = Math.random() * 10;
  319. if (va >= 1 && va < 4) {
  320. KindHolder = 7;
  321. }
  322. else if (va >= 4 && va < 10) {
  323. KindHolder = 5;
  324. }
  325. //KindHolder = 5;
  326. console.log("KindHolder gb: " + KindHolder);
  327. }
  328. if (rtpe != null) {
  329. KindHolder = rtpe;
  330. console.log("KindHolder gb2: " + KindHolder);
  331. }
  332. this.ETime = Date.now();
  333. switch (KindHolder) {
  334. case 1: {
  335. FHolder = cc.instantiate(self.GD);
  336. self.FHolderNode.addChild(FHolder, 5, "GD");
  337. FHolder.getComponent("GD").init(self, 1);
  338. FHolder.isHold = false;
  339. // console.log("产生第一种落脚点");
  340. break;
  341. }
  342. case 2: {
  343. FHolder = cc.instantiate(self.GD);
  344. self.FHolderNode.addChild(FHolder, 5, "GD");
  345. FHolder.getComponent("GD").init(self, 7);
  346. FHolder.isHold = false;
  347. /*self.FootHoldGenerator();
  348. FHolder = cc.instantiate(self.tanhuang);
  349. self.FHolderNode.addChild(FHolder,5,"tanhuang");
  350. FHolder.getComponent("tanhuang").init(self);
  351. FHolder.isHold = false;
  352. // // console.log("产生第五种落脚点");
  353. // break;*/
  354. break;
  355. }
  356. case 3: {
  357. FHolder = cc.instantiate(self.lvdai);
  358. self.FHolderNode.addChild(FHolder, 5, "lvdai");
  359. FHolder.getComponent("lvdai").init(self);
  360. FHolder.isHold = false;
  361. // console.log("产生第二种落脚点");
  362. console.log(" 创建滚动 ");
  363. break;
  364. }
  365. case 4: {
  366. FHolder = cc.instantiate(self.lvdai);
  367. self.FHolderNode.addChild(FHolder, 5, "lvdai");
  368. FHolder.getComponent("lvdai").init(self);
  369. FHolder.isHold = false;
  370. // console.log("产生第五种落脚点");
  371. console.log(" 创建滚动1 ");
  372. break;
  373. }
  374. case 5: {
  375. FHolder = cc.instantiate(self.boli);
  376. self.FHolderNode.addChild(FHolder, 5, "boli");
  377. FHolder.getComponent("boli").init(self);
  378. FHolder.isHold = false;
  379. // console.log("产生第三种落脚点");
  380. break;
  381. }
  382. case 6: {
  383. FHolder = cc.instantiate(self.dici);
  384. self.FHolderNode.addChild(FHolder, 5, "dici");
  385. FHolder.getComponent("dici").init(self);
  386. FHolder.isHold = false;
  387. // console.log("产生第四种落脚点");
  388. break;
  389. }
  390. case 7: {
  391. FHolder = cc.instantiate(self.GD);
  392. self.FHolderNode.addChild(FHolder, 5, "GD");
  393. FHolder.getComponent("GD").init(self, 7);
  394. FHolder.isHold = false;
  395. break;
  396. }
  397. case 8: {
  398. if (self.lightF) {
  399. self.lightF = false;
  400. self.FootHoldGenerator(null);
  401. break;
  402. }
  403. FHolder = cc.instantiate(self.shandian);
  404. self.FHolderNode.addChild(FHolder, 5, "shandian");
  405. FHolder.getComponent("shandian").init(self);
  406. FHolder.isHold = false;
  407. self.lightF = true;
  408. break;
  409. }
  410. // default:{
  411. // FHolder = cc.instantiate(self.GD);
  412. // self.FHolderNode.addChild(FHolder,5,"GD");
  413. // FHolder.getComponent("GD").init(self);
  414. // FHolder.getComponent("GD").enabled = true;
  415. // FHolder.getComponent("MoveGD").init(self);
  416. // FHolder.getComponent("MoveGD").enabled = false;
  417. // FHolder.isHold = false;
  418. // // console.log("默认产生第一种落脚点");
  419. // }
  420. // break;
  421. }
  422. return FHolder;
  423. };
  424. /**
  425. * 按钮触发,向左,长按事件
  426. */
  427. MainScene.prototype.BtnTurnLeft = function (event) {
  428. var self = this;
  429. if (self.RkeyDown) {
  430. return;
  431. }
  432. else {
  433. self.LkeyDown = true;
  434. self.RkeyDown = false;
  435. this.BtnLorR(event);
  436. }
  437. };
  438. /**
  439. * 按钮触发,向右,长按事件,长按响应未解决
  440. */
  441. MainScene.prototype.BtnTurnRight = function (event) {
  442. var self = this;
  443. if (self.LkeyDown) {
  444. return;
  445. }
  446. else {
  447. self.LkeyDown = false;
  448. self.RkeyDown = true;
  449. this.BtnLorR(event);
  450. }
  451. };
  452. /**
  453. * btn触发事件
  454. * @param event 按钮触发事件
  455. */
  456. MainScene.prototype.BtnLorR = function (event) {
  457. var self = this;
  458. Global_1.default.instance.moveSpeed = 1;
  459. var schedule = cc.director.getScheduler();
  460. var stand = self.Player.getChildByName("stand");
  461. var runRight = self.Player.getChildByName("runRight");
  462. var run = self.Player.getChildByName("run");
  463. var Ani; //the animation of player
  464. var Anistate; //the Ani's state
  465. var Anistring; //the name of Ani
  466. var moveByTime = 1;
  467. var scheduleState = false; //the schedule's state
  468. var schedulePause = true;
  469. var target = null; //the target which is binged to schedule
  470. var moveByDes = Global_1.default.instance.moveSpeed * 120 + 40;
  471. if (self.LkeyDown) {
  472. target = self.LEFT;
  473. moveByTime = 1;
  474. moveByDes = -moveByDes;
  475. scheduleState = schedule.isScheduled(func, target);
  476. // self.output.getComponent(cc.Label).string = Anistring;
  477. schedulePause = schedule.isTargetPaused(target);
  478. Ani = run.getComponent(cc.Animation);
  479. Anistring = "run";
  480. stand.active = false;
  481. runRight.active = false;
  482. run.active = true;
  483. // self.output.getComponent(cc.Label).string = Anistring;
  484. if (!Global_1.default.instance.CollisionFlag) {
  485. moveByTime = 1;
  486. }
  487. else {
  488. switch (Global_1.default.instance.KIND_FootHold) {
  489. case 2: {
  490. moveByTime = 4.1;
  491. self.output.getComponent(cc.Label).string = Global_1.default.instance.KIND_FootHold + "2";
  492. break;
  493. }
  494. case 5: {
  495. moveByTime = 3.9;
  496. // self.output.getComponent(cc.Label).string = Global.instance.KIND_FootHold+"5";
  497. break;
  498. }
  499. }
  500. ;
  501. }
  502. }
  503. if (self.RkeyDown) {
  504. target = self.RIGHT;
  505. moveByTime = 1;
  506. moveByDes = moveByDes;
  507. scheduleState = schedule.isScheduled(func, target);
  508. // self.output.getComponent(cc.Label).string = Anistring;
  509. schedulePause = schedule.isTargetPaused(target);
  510. Ani = runRight.getComponent(cc.Animation);
  511. Anistring = "runR";
  512. stand.active = false;
  513. runRight.active = true;
  514. run.active = false;
  515. // self.output.getComponent(cc.Label).string = Anistring;
  516. if (!Global_1.default.instance.CollisionFlag) {
  517. moveByTime = 1;
  518. }
  519. else {
  520. switch (Global_1.default.instance.KIND_FootHold) {
  521. case 2: {
  522. moveByTime = 4.1;
  523. // self.output.getComponent(cc.Label).string = Global.instance.KIND_FootHold+"2";
  524. break;
  525. }
  526. case 5: {
  527. moveByTime = 3.9;
  528. // self.output.getComponent(cc.Label).string = Global.instance.KIND_FootHold+"5";
  529. break;
  530. }
  531. }
  532. ;
  533. }
  534. }
  535. var funcFlag = false;
  536. switch (event.type) {
  537. case "touchstart": {
  538. if (!(self.moveFalg.length == 0)) {
  539. break;
  540. }
  541. self.moveFalg = "touchstart";
  542. if (!scheduleState) {
  543. // self.output.getComponent(cc.Label).string = movefalg;
  544. schedule.schedule(func, target, 0);
  545. }
  546. ;
  547. if (schedulePause) {
  548. schedule.resumeTarget(target);
  549. }
  550. ;
  551. break;
  552. }
  553. case "touchmove": {
  554. if (!(self.moveFalg.length == 0)) {
  555. break;
  556. }
  557. self.moveFalg = "touchmove";
  558. // self.output.getComponent(cc.Label).string = movefalg;
  559. if (!scheduleState) {
  560. schedule.schedule(func, target, 0);
  561. }
  562. ;
  563. if (schedulePause) {
  564. schedule.resumeTarget(target);
  565. }
  566. ;
  567. break;
  568. }
  569. case "touchcancel": {
  570. break;
  571. }
  572. case "touchend": {
  573. // self.output.getComponent(cc.Label).string = "touchend";
  574. schedule.pauseTarget(target);
  575. self.Player.stopAllActions();
  576. Ani.stop(Anistring);
  577. moveByTime = 1;
  578. moveByDes = Global_1.default.instance.moveSpeed * 120 + 40;
  579. switch (Anistring) {
  580. case "run": {
  581. run.active = false;
  582. runRight.active = false;
  583. stand.active = true;
  584. self.LkeyDown = false;
  585. self.RkeyDown = false;
  586. moveByDes = Global_1.default.instance.moveSpeed / 2;
  587. break;
  588. }
  589. case "runR": {
  590. run.active = false;
  591. runRight.active = false;
  592. stand.active = true;
  593. self.LkeyDown = false;
  594. self.RkeyDown = false;
  595. moveByDes = Global_1.default.instance.moveSpeed / 2;
  596. break;
  597. }
  598. }
  599. funcFlag = false;
  600. self.moveFalg = "";
  601. break;
  602. }
  603. }
  604. function func() {
  605. if (funcFlag) {
  606. return;
  607. }
  608. if (Global_1.default.instance.CollisionFlag) {
  609. moveByTime = 1;
  610. }
  611. var spawn = cc.spawn(cc.callFunc(function () {
  612. self.Player.runAction(cc.moveBy(moveByTime, moveByDes, 0));
  613. }), cc.callFunc(function () {
  614. Anistate = Ani.play(Anistring);
  615. Anistate.speed = 1;
  616. Anistate.repeatCount = 100;
  617. Anistate = Ani.playAdditive(Anistring);
  618. }));
  619. self.Player.runAction(spawn);
  620. funcFlag = true;
  621. }
  622. };
  623. /**
  624. * 返回键监听
  625. * @param event 按下返回键退出游戏
  626. */
  627. MainScene.prototype.AniPlayer = function (Ani, Anistate, moveByTime, moveByDes, Key, AniName, self) {
  628. Ani = Key.getComponent(cc.Animation);
  629. var spawn = cc.spawn(cc.callFunc(function () {
  630. self.Player.runAction(cc.moveBy(moveByTime, moveByDes, 0));
  631. }), cc.callFunc(function () {
  632. Anistate = Ani.play(AniName);
  633. Anistate.speed = 2;
  634. Anistate.repeatCount = 100;
  635. }));
  636. self.Player.runAction(spawn);
  637. if (!Ani.state) {
  638. var spawn2 = cc.spawn(cc.callFunc(function () {
  639. self.Player.runAction(cc.moveBy(moveByTime, moveByDes, 0));
  640. }), cc.callFunc(function () {
  641. Anistate = Ani.play(AniName);
  642. Anistate.speed = 2;
  643. Anistate.repeatCount = 100;
  644. }));
  645. self.Player.runAction(spawn2);
  646. }
  647. };
  648. /**
  649. * 抬起动画停止
  650. * @param event 抬起左右键触发
  651. */
  652. MainScene.prototype.onKeyUp = function (event) {
  653. var self = this;
  654. self.LkeyDown = false;
  655. this.RkeyDown = false;
  656. self.Player.stopAllActions();
  657. var stand = this.Player.getChildByName("stand");
  658. var runRight = this.Player.getChildByName("runRight");
  659. var run = this.Player.getChildByName("run");
  660. stand.active = true;
  661. run.active = false;
  662. runRight.active = false;
  663. };
  664. /**
  665. * gameover
  666. */
  667. MainScene.prototype.gameOver = function () {
  668. var self = this;
  669. self.Player.stopAllActions();
  670. Global_1.default.instance.CollisionFlag = false;
  671. // self.Player.getComponent(cc.BoxCollider).enabled = false;
  672. self.Player.getComponent("Playcontroler").enabled = false;
  673. try {
  674. self.Player.getComponent(cc.Animation).stop();
  675. }
  676. catch (error) {
  677. self.node.getChildByName("output").getComponent(cc.Label).string = error;
  678. }
  679. self.Player.getChildByName("stand").active = true;
  680. self.Player.getChildByName("runRight").active = false;
  681. self.Player.getChildByName("run").active = false;
  682. self.Player.y -= Global_1.default.instance.InitSpeed;
  683. var AllFH = self.node.getChildByName("BgNode").getChildByName("FHolder").children;
  684. for (var i = 0; i < AllFH.length; i++) {
  685. var FHNA = AllFH[i].name;
  686. AllFH[i].getComponent(FHNA).enabled = false;
  687. AllFH[i].isHold = false;
  688. if (FHNA == "GD") {
  689. AllFH[i].getChildByName("gd").getComponent("CliGD").enabled = false;
  690. }
  691. }
  692. self.StopAni(self);
  693. var failure;
  694. var Ani;
  695. var Anistate;
  696. var BestScore;
  697. var thisScore;
  698. var lessScore;
  699. var Score;
  700. // let fuhuo;
  701. var FAni;
  702. var FAnistate;
  703. self.LEFT.node.active = false;
  704. self.RIGHT.node.active = false;
  705. failure = cc.instantiate(self.failure);
  706. // fuhuo = cc.instantiate(self.fuhuo);
  707. // let fhuoBtnRank = fuhuo.getChildByName("cd").getChildByName("RankScene").getComponent(cc.Button);
  708. var fhuoBtnreGame = failure.getChildByName("reset").getComponent(cc.Button);
  709. // let fhuoBtnreGame = fuhuo.getChildByName("zl").getChildByName("rePlay").getComponent(cc.Button);
  710. // let fhuoBtnFhuo = fuhuo.getChildByName("fh").getChildByName("rePlay").getComponent(cc.Button);
  711. var RankEventHandler = new cc.Component.EventHandler();
  712. var reGameEventHandler = new cc.Component.EventHandler();
  713. var FhuoEventHandler = new cc.Component.EventHandler();
  714. //open the ranking
  715. // RankEventHandler.target = self.node;
  716. // RankEventHandler.component = "MainScene";
  717. // RankEventHandler.handler = "FBtnCB_Rank";
  718. // RankEventHandler.customEventData = null;
  719. // fhuoBtnRank.clickEvents.push(RankEventHandler);
  720. //replay
  721. reGameEventHandler.target = self.node;
  722. reGameEventHandler.component = "MainScene";
  723. reGameEventHandler.handler = "restart";
  724. reGameEventHandler.customEventData = null;
  725. fhuoBtnreGame.clickEvents.push(reGameEventHandler);
  726. //fh立即复活会有其他功能暂时用重新开始代替
  727. // FhuoEventHandler.target = self.node;
  728. // FhuoEventHandler.component = "MainScene";
  729. // FhuoEventHandler.handler = "FBtnCB_rePlay";
  730. // FhuoEventHandler.customEventData = null;
  731. // fhuoBtnFhuo.clickEvents.push(FhuoEventHandler);
  732. if (!Global_1.default.instance.OverFlag) {
  733. Global_1.default.instance.OverFlag = true;
  734. self.StoregeScore();
  735. // self.UpdateScore();
  736. failure.y = -20;
  737. // fuhuo.y = 0;
  738. thisScore = parseInt(self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string);
  739. // lessScore = failure.getChildByName("jl").getChildByName("LessScore");
  740. BestScore = Global_1.default.instance.getLocalScore().BestScore;
  741. Global_1.default.instance.GetUSer().score = BestScore;
  742. self.UpLoadScore();
  743. if (BestScore - thisScore <= 0) {
  744. failure.getChildByName("jl").active = false;
  745. }
  746. else {
  747. // lessScore.getComponent(cc.Label).string = (BestScore - thisScore).toString();
  748. }
  749. Score = failure.getChildByName("cj").getChildByName("Score");
  750. self.node.addChild(failure);
  751. // self.node.addChild(fuhuo);
  752. Score.getComponent(cc.Label).string = self.LifeDing.getChildByName("Floor").getComponent(cc.Label).string;
  753. // Ani = failure.getComponent(cc.Animation);//the animation of failure;
  754. // // FAni = fuhuo.getComponent(cc.Animation);
  755. // Anistate = Ani.play("shibai");//the state of Ani;
  756. // Anistate.speed = 1;
  757. // Anistate.repeatCount = 1;
  758. }
  759. else {
  760. return;
  761. }
  762. self.playdeadsound();
  763. console.log("游戏结束!!!");
  764. };
  765. /**
  766. * 复活按钮的回调函数:打开排行榜
  767. */
  768. MainScene.prototype.FBtnCB_Rank = function (self) {
  769. this.destroy();
  770. cc.director.loadScene("EndScene");
  771. };
  772. /**
  773. * 复活按钮的回调函数:立即复活
  774. */
  775. MainScene.prototype.FBtnCB_rePlay = function () {
  776. cc.sys.localStorage.setItem("hfsj", "99");
  777. var self = this;
  778. Global_1.default.instance.OverFlag = false;
  779. Global_1.default.instance.AniFalg = false;
  780. Global_1.default.instance.LorR = 0;
  781. Global_1.default.instance.InitSpeed = 8.5;
  782. Global_1.default.instance.moveSpeed = 1;
  783. // Global.instance.FHFallSpeed = 2;
  784. Global_1.default.instance.CollisionFlag = false;
  785. Global_1.default.instance.CollisionWithDing = false;
  786. Global_1.default.instance.TheHolder = null;
  787. Global_1.default.instance.KIND_FootHold = 0;
  788. // this.RIGHT.node.off(cc.Node.EventType.TOUCH_START,this.BtnTurnRight,this);
  789. // this.RIGHT.node.off(cc.Node.EventType.TOUCH_MOVE,this.BtnTurnRight,this);
  790. // this.RIGHT.node.off(cc.Node.EventType.TOUCH_CANCEL,this.onKeyUp,this);
  791. this.LEFT.node.active = true;
  792. this.RIGHT.node.active = true;
  793. this.LkeyDown = false;
  794. this.RkeyDown = false;
  795. this.moveFalg = "";
  796. this.Player.y = 300;
  797. this.Player.x = 0;
  798. this.Player.getComponent("Playcontroler").enabled = true;
  799. this.Player.getComponent(cc.BoxCollider).enabled = true;
  800. var AllFH = this.node.getChildByName("BgNode").getChildByName("FHolder").children;
  801. this.node.getChildByName("SB").destroy();
  802. this.node.getChildByName("fuhuo1").destroy();
  803. for (var i = 0; i < this.LifeDing.children.length; i++) {
  804. //for(let i=0;i<2;i++){
  805. if (this.LifeDing.children[i].name == "lifeBG") {
  806. if (!this.LifeDing.children[i].active) {
  807. this.LifeDing.children[i].active = true;
  808. }
  809. Global_1.default.instance.reLife.push(this.LifeDing.children[i]);
  810. }
  811. }
  812. this.Player.getComponent(cc.BoxCollider).enabled = false;
  813. for (var i = 0; i < AllFH.length; i++) {
  814. AllFH[i].destroy();
  815. }
  816. var F = this.FootHoldGenerator(1);
  817. F.y = -380;
  818. this.scheduleOnce(function () {
  819. self.Player.getComponent(cc.BoxCollider).enabled = true;
  820. }, 0.5);
  821. };
  822. /**
  823. * restart
  824. */
  825. MainScene.prototype.restart = function () {
  826. this.destroy();
  827. cc.director.loadScene("MainScene");
  828. cc.director.resume();
  829. Global_1.default.instance.OverFlag = false;
  830. Global_1.default.instance.AniFalg = false;
  831. Global_1.default.instance.LorR = 0;
  832. Global_1.default.instance.InitSpeed = 8.5;
  833. Global_1.default.instance.moveSpeed = 1;
  834. Global_1.default.instance.FHFallSpeed = 2;
  835. Global_1.default.instance.CollisionFlag = false;
  836. Global_1.default.instance.CollisionWithDing = false;
  837. Global_1.default.instance.TheHolder = null;
  838. Global_1.default.instance.KIND_FootHold = 0;
  839. // this.RIGHT.node.off(cc.Node.EventType.TOUCH_START,this.BtnTurnRight,this);
  840. // this.RIGHT.node.off(cc.Node.EventType.TOUCH_MOVE,this.BtnTurnRight,this);
  841. // this.RIGHT.node.off(cc.Node.EventType.TOUCH_CANCEL,this.onKeyUp,this);
  842. this.LEFT.node.active = true;
  843. this.RIGHT.node.active = true;
  844. this.LkeyDown = false;
  845. this.RkeyDown = false;
  846. // this.moveFalg = "";
  847. this.Player.y = 300;
  848. // this.Score();
  849. };
  850. /**
  851. * 受到伤害,命数减一
  852. */
  853. MainScene.prototype.reduceLife = function () {
  854. var self = this;
  855. var Ls = new Array();
  856. var reLCount = 0;
  857. var FHolder = self.node.getChildByName("BgNode").getChildByName("FHolder").children;
  858. for (var i = 0; i < FHolder.length; i++) {
  859. if (FHolder[i].isHold) {
  860. if (!Global_1.default.instance.CollisionFlag) {
  861. FHolder[i].isHold = false;
  862. var box = FHolder[i].getComponent(cc.BoxCollider);
  863. box.enabled = false;
  864. }
  865. }
  866. }
  867. //
  868. for (var i = self.LifeDing.children.length - 1; i >= 0; i--) {
  869. if (self.LifeDing.children[i].name == "lifeBG") {
  870. if (Global_1.default.instance.Injured || Global_1.default.instance.CollisionWithDing) {
  871. if (self.LifeDing.children[i].active) {
  872. self.LifeDing.children[i].active = false;
  873. Global_1.default.instance.Injured = false;
  874. Global_1.default.instance.CollisionFlag = false;
  875. Global_1.default.instance.CollisionWithDing = false;
  876. }
  877. }
  878. Ls.push(self.LifeDing.children[i]);
  879. }
  880. }
  881. Global_1.default.instance.reLife = [];
  882. for (var i = 0; i < Ls.length; i++) {
  883. if (Ls[i].active) {
  884. Global_1.default.instance.reLife.push(Ls[i]); //player剩余的命数
  885. }
  886. }
  887. //
  888. var time = cc.sys.localStorage.getItem("hfsj");
  889. //console.log( time + "当前血 : " + Global.instance.reLife.length);
  890. if (Global_1.default.instance.reLife.length < 3) {
  891. if (time == 99) {
  892. var time_1 = Math.floor(Date.now() / 1000);
  893. cc.sys.localStorage.setItem("hfsj", time_1);
  894. }
  895. else {
  896. var time_2 = Math.floor(Date.now() / 1000);
  897. var timlod = parseInt(cc.sys.localStorage.getItem("hfsj"));
  898. var sub = time_2 - timlod;
  899. if (sub >= 20) {
  900. var sizes = Global_1.default.instance.reLife.length + 2;
  901. Global_1.default.instance.reLife = [];
  902. for (var i = 0; i < sizes; i++) {
  903. if (this.LifeDing.children[i].name == "lifeBG") {
  904. if (!this.LifeDing.children[i].active) {
  905. this.LifeDing.children[i].active = true;
  906. }
  907. Global_1.default.instance.reLife.push(this.LifeDing.children[i]);
  908. // console.log("push --------------" + i);
  909. }
  910. }
  911. cc.sys.localStorage.setItem("hfsj", time_2);
  912. // console.log(sizes + "恢复血+1---------------------------------------" + Global.instance.reLife.length);
  913. }
  914. }
  915. }
  916. else {
  917. cc.sys.localStorage.setItem("hfsj", "99");
  918. }
  919. };
  920. /**
  921. * 每下落一层,分数加一。
  922. */
  923. MainScene.prototype.Score = function () {
  924. var self = this.node;
  925. var scLabel = this.LifeDing.getChildByName("Floor").getComponent(cc.Label);
  926. var sc = parseInt(scLabel.string);
  927. if (!Global_1.default.instance.OverFlag) {
  928. sc = sc + 1;
  929. }
  930. this.playtansound();
  931. console.log("打印一下");
  932. scLabel.string = sc.toString();
  933. var lv = Math.ceil(sc / 50);
  934. if (lv > Global_1.default.instance.LevelAddFlag) {
  935. Global_1.default.instance.LevelAddFlag = lv;
  936. Global_1.default.instance.InitSpeed += 0.25; //每下落50层,player下落速度加0.25
  937. Global_1.default.instance.FHFallSpeed += 1; //没下落50层,落脚点下落速度加快0.5.
  938. }
  939. };
  940. /**
  941. * 本地分数存储
  942. */
  943. MainScene.prototype.StoregeScore = function () {
  944. var self = this;
  945. var localS = Global_1.default.instance.getLocalScore(); //the temp of local score;
  946. var CurrentScore = parseInt(this.LifeDing.getChildByName("Floor").getComponent(cc.Label).string);
  947. Global_1.default.instance.getLocalScore().CurrentScore = CurrentScore;
  948. if (CurrentScore > localS.ThirdScore) {
  949. if (CurrentScore > localS.SecondScore) {
  950. if (CurrentScore > localS.BestScore) {
  951. localS.BestScore = CurrentScore;
  952. return;
  953. }
  954. localS.SecondScore = CurrentScore;
  955. }
  956. localS.ThirdScore = CurrentScore;
  957. }
  958. };
  959. /**
  960. * upload the best score
  961. */
  962. MainScene.prototype.UpLoadScore = function () {
  963. var self = this;
  964. var tmp = Global_1.default.instance.GetUSer();
  965. /* Http.sendRequest("/updateScore",tmp,function(msg){
  966. let x = msg;
  967. if(msg.code!=0){
  968. Global.instance.NetStatus = false;
  969. }
  970. let ux = {
  971. userId:'',
  972. }
  973. console.log(x);
  974. ux.userId = Global.instance.GetUSer().userId;
  975. Http.sendRequest("/rank",ux,function(mmsg){
  976. console.log("------------------3");
  977. let MM = JSON.parse(mmsg.msg);
  978. console.log(MM);
  979. if(Global.instance.GetR()==null||Global.instance.GetR().rank==undefined||Global.instance.GetR().rank<MM.my.rank){
  980. Global.instance.SetR(MM.my.rank);
  981. Global.instance.setRemoteScore(MM.other);
  982. }
  983. });
  984. });*/
  985. };
  986. __decorate([
  987. property(cc.Prefab)
  988. ], MainScene.prototype, "boli", void 0);
  989. __decorate([
  990. property(cc.Prefab)
  991. ], MainScene.prototype, "dici", void 0);
  992. __decorate([
  993. property(cc.Prefab)
  994. ], MainScene.prototype, "lvdai", void 0);
  995. __decorate([
  996. property(cc.Prefab)
  997. ], MainScene.prototype, "shandian", void 0);
  998. __decorate([
  999. property(cc.Prefab)
  1000. ], MainScene.prototype, "tanhuang", void 0);
  1001. __decorate([
  1002. property(cc.Prefab)
  1003. ], MainScene.prototype, "Opplvdai", void 0);
  1004. __decorate([
  1005. property(cc.Prefab)
  1006. ], MainScene.prototype, "GD", void 0);
  1007. __decorate([
  1008. property(cc.Prefab)
  1009. ], MainScene.prototype, "failure", void 0);
  1010. __decorate([
  1011. property(cc.Prefab)
  1012. ], MainScene.prototype, "fuhuo", void 0);
  1013. __decorate([
  1014. property(cc.Node)
  1015. ], MainScene.prototype, "Player", void 0);
  1016. __decorate([
  1017. property(cc.Node)
  1018. ], MainScene.prototype, "FHolderNode", void 0);
  1019. __decorate([
  1020. property(cc.Node)
  1021. ], MainScene.prototype, "Bg", void 0);
  1022. __decorate([
  1023. property(cc.Node)
  1024. ], MainScene.prototype, "LifeDing", void 0);
  1025. __decorate([
  1026. property(cc.Button)
  1027. ], MainScene.prototype, "LEFT", void 0);
  1028. __decorate([
  1029. property(cc.Button)
  1030. ], MainScene.prototype, "RIGHT", void 0);
  1031. __decorate([
  1032. property(cc.Label)
  1033. ], MainScene.prototype, "output", void 0);
  1034. MainScene = __decorate([
  1035. ccclass
  1036. ], MainScene);
  1037. return MainScene;
  1038. }(cc.Component));
  1039. exports.default = MainScene;
  1040. cc._RF.pop();