app2.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. var GD = GD || {};
  2. GD.GAME_STATE = {
  3. HOME: 0,
  4. PLAY: 1,
  5. OVER: 2
  6. };
  7. GD.UNIT_TAG = {
  8. ENEMY: 100,
  9. PLAYER: 1E3,
  10. PET: 1010,
  11. BLOOD: 1020
  12. };
  13. GD.ACTIVE_PETS = 0;
  14. GD.ACTIVE_ENEMIES = 0;
  15. GD.CONTAINER = {
  16. ENEMIES: [],
  17. BLOOD: [],
  18. BACKSKYS: [],
  19. HitMo: [],
  20. PET: [],
  21. BACKTILEMAPS: []
  22. };
  23. GD.LIFE = 5;
  24. GD.PETKIND = 0;
  25. GD.SHOWLEVEL = 0;
  26. GD.SCORE = 0;
  27. GD.NUM = 0;
  28. var winSize, centerPos;
  29. GD.word = ["0", "1"];
  30. var BitNumLayer = cc.Layer.extend({
  31. timeLabel: null,
  32. scoreLabel: null,
  33. time: null,
  34. timeAction: null,
  35. ctor: function() {
  36. this._super()
  37. },
  38. step: function(a) {
  39. this.time += a
  40. },
  41. init: function() {
  42. this._super();
  43. trace("res.num_png");
  44. var a = cc.Sprite.create("#time.png");
  45. this.timeLabel = cc.LabelAtlas.create("0", res.num_png, 36, 67, "0");
  46. this.timeLabel._textAlign = cc.TEXT_ALIGNMENT_LEFT;
  47. a.x = 0.1 * winSize.width;
  48. this.timeLabel.anchorX = 0.5;
  49. this.timeLabel.x = 0.3 * winSize.width;
  50. this.timeLabel.y = -110 + winSize.height;
  51. var b = cc.Sprite.create("#quan.png");
  52. this.addChild(b);
  53. b.x = 0.4 * winSize.width;
  54. b.y = -77 + winSize.height;
  55. a.y = -77 + winSize.height;
  56. this.scoreLabel = cc.LabelAtlas.create("0", res.num_png, 36, 67, "0");
  57. this.addChild(this.scoreLabel);
  58. this.scoreLabel.anchorX = 0.6;
  59. this.scoreLabel.x = 0.6 * winSize.width;
  60. this.scoreLabel.y = -130 + winSize.height;
  61. a = cc.ScaleBy.create(0.1, 1.1);
  62. this.scoreLabel.scale = 1.2;
  63. this.timeAction = cc.Sequence.create(a, a.reverse())
  64. },
  65. setNum: function(a, b) {
  66. GD.SCORE += a + b;
  67. GD.NUM += a;
  68. this.scoreLabel.scale = 1;
  69. trace(GD.NUM);
  70. this.scoreLabel.setString(GD.NUM +
  71. "");
  72. this.scoreLabel.scale = 1.2
  73. },
  74. setTimeNum: function(a) {
  75. this.timeLabel.setString(a + '"')
  76. }
  77. });
  78. BitNumLayer.create = function() {
  79. var a = new BitNumLayer;
  80. a.init();
  81. return a
  82. };
  83. var Fire = cc.Node.extend({
  84. _bgs: null,
  85. _start: null,
  86. _list: [],
  87. _lfire: null,
  88. _lfireA: null,
  89. _rfire: null,
  90. _lefttx: -350,
  91. _fid: 0,
  92. _bid: 0,
  93. _foot: null,
  94. _foot2: null,
  95. _kind: 0,
  96. _x: 0,
  97. _action: null,
  98. _showspeed: 0,
  99. _isPassed: !1,
  100. ctor: function(a) {
  101. this._super()
  102. },
  103. step: function(a) {
  104. this.time += a
  105. },
  106. init: function() {
  107. this._super();
  108. this._lfire = new cc.Sprite.create;
  109. this._foot = new cc.Sprite.create("#mfire.png");
  110. this._foot2 = new cc.Sprite.create("#mfire2.png");
  111. this._foot2.x = this._foot.x = 80;
  112. this._foot2.y = -230;
  113. this._foot.y = -180;
  114. this._lfire.addChild(this._foot,
  115. 0);
  116. this._foot.visible = !1;
  117. this._lfire.addChild(this._foot2, 0);
  118. this._foot2.visible = !1;
  119. for (var a = [], b = 1; 3 >= b; b++) {
  120. var c = "lfire000" + b + ".png",
  121. c = cc.spriteFrameCache.getSpriteFrame(c);
  122. a.push(c)
  123. }
  124. this._lfireA = new cc.Sprite.create;
  125. this._action = cc.RepeatForever.create(cc.Animate.create(cc.Animation.create(a, 0.1)));
  126. this._lfireA.runAction(this._action);
  127. this._lfire.addChild(this._lfireA);
  128. this._rfire = new cc.Sprite.create("#rfire0001.png");
  129. a = [];
  130. for (b = 1; 3 >= b; b++) c = "rfire000" + b + ".png", c = cc.spriteFrameCache.getSpriteFrame(c),
  131. a.push(c);
  132. a = cc.RepeatForever.create(cc.Animate.create(cc.Animation.create(a, 0.1)));
  133. this._rfire.runAction(a)
  134. },
  135. setKind: function(a) {
  136. this._kind = a;
  137. 0 == a ? (this._foot.visible = !0, this._foot2.visible = !1, this._lfire.y = this._rfire.y = winSize.height / 2 + 20) : (this._foot.visible = !1, this._foot2.visible = !0, this._lfire.y = this._rfire.y = winSize.height / 2 + 130);
  138. this._lfire.y += 1
  139. },
  140. setX: function(a) {
  141. this._x = a;
  142. this._lfire.x = a;
  143. this._rfire.x = a + 134
  144. },
  145. update: function() {
  146. this._lfire.x = this._x;
  147. this._rfire.x = this._x + 130
  148. }
  149. });
  150. Fire.create = function() {
  151. var a = new Fire;
  152. a.init();
  153. return a
  154. };
  155. var Helo = cc.Sprite.extend({
  156. eID: 0,
  157. active: !0,
  158. direct: 1,
  159. zOrder: 30,
  160. hurtAction: null,
  161. standAction: null,
  162. attactActionList: [],
  163. lock: !1,
  164. potList: [
  165. [-20, 19],
  166. [-80, 32],
  167. [-20, 40],
  168. [0, 0],
  169. [12, -6]
  170. ],
  171. frameObj: {},
  172. frameActionObj: null,
  173. frameList: [],
  174. state: "no",
  175. isAim: !1,
  176. dx: 0,
  177. dy: 0,
  178. oriy: 0,
  179. _isDouble: !1,
  180. powerx: 10,
  181. actiondata: [
  182. [
  183. [1, 2, 3, 4, 5, 6], "run"
  184. ],
  185. [
  186. [7, 8], "up"
  187. ],
  188. [
  189. [9, 9, 10, 10], "jump"
  190. ],
  191. [
  192. [15, 15, 16, 16, 16, 17, 17], "jump2"
  193. ],
  194. [
  195. [12, 12, 13, 14], "down"
  196. ],
  197. [
  198. [21, 22, 23, 24, 25, 26, 27, 28], "ready"
  199. ],
  200. [
  201. [23, 24, 25, 26, 27, 28], "die"
  202. ]
  203. ],
  204. ctor: function() {
  205. this._super("#role0021.png");
  206. this.install();
  207. this.anchorX = 0.5;
  208. this.anchorY = 0;
  209. this.g = 0.5;
  210. this.t = this.time = 0;
  211. this.lock = !0;
  212. this.state = "ready";
  213. this.runAction(this.frameObj.ready)
  214. },
  215. install: function() {
  216. var a = "",
  217. b = this.actiondata;
  218. this.frameObj = {};
  219. this.frameActionObj = {};
  220. for (var c = [], f, d = 0; d < b.length; d++) {
  221. for (var c = [], e = b[d][0], g = 0; g < e.length; g++) a = e[g], a = 10 > a ? "00" + a : 100 > a ? "0" + a : a, a = "role0" + a + ".png", a = cc.spriteFrameCache.getSpriteFrame(a), c.push(a);
  222. e = b[d][1];
  223. this.frameActionObj[e] = cc.Animation.create(c, 0.1);
  224. "run" == e ? f = cc.RepeatForever.create(cc.Animate.create(this.frameActionObj[e])) :
  225. "jump" == e || "jump2" == e ? f = cc.Sequence.create(cc.Animate.create(this.frameActionObj[e]), cc.CallFunc.create(this.jumpHigh, this)) : "ready" == e ? f = cc.Sequence.create(cc.Animate.create(this.frameActionObj[e]), cc.CallFunc.create(this.readyMove, this)) : "up" == e ? (this.frameActionObj.up = cc.Animation.create(c, 0.05), f = cc.Sequence.create(cc.Animate.create(this.frameActionObj[e]), cc.CallFunc.create(this.upHorse, this))) : "down" == e ? f = cc.Sequence.create(cc.Animate.create(this.frameActionObj[e]), cc.CallFunc.create(this.jumpEnd,
  226. this)) : "die" == e && (f = cc.Sequence.create(cc.Animate.create(this.frameActionObj[e]), cc.CallFunc.create(this.dieEnd, this)));
  227. this.frameObj[e] = f
  228. }
  229. },
  230. upHorse: function() {
  231. this.stopAllActions();
  232. this._isDouble ? (this.state = "jump2", this.runAction(this.frameObj.jump2)) : (this.state = "jump", this.runAction(this.frameObj.jump))
  233. },
  234. readyMove: function() {
  235. "ready" == this.state && (this.lock = !1, g_sharedGameLayer.toRun(), this.run())
  236. },
  237. speedUp: function(a) {
  238. if (0 == a % 5) {
  239. a = Math.floor(a / 5);
  240. a = 13 < a ? 13 : a;
  241. this.powerx = a + 10;
  242. a = 1 - 0.04 * a;
  243. for (var b =
  244. 0; b < this.actiondata.length; b++) {
  245. var c = this.actiondata[b][1];
  246. this.frameActionObj[c].setDelayPerUnit(this.frameActionObj[c].getDelayPerUnit() * a);
  247. "run" == c ? action = cc.RepeatForever.create(cc.Animate.create(this.frameActionObj[c])) : "jump" == c || "jump2" == c ? action = cc.Sequence.create(cc.Animate.create(this.frameActionObj[c]), cc.CallFunc.create(this.jumpHigh, this)) : "ready" == c ? action = cc.Sequence.create(cc.Animate.create(this.frameActionObj[c]), cc.CallFunc.create(this.readyMove, this)) : "up" == c ? action = cc.Sequence.create(cc.Animate.create(this.frameActionObj[c]),
  248. cc.CallFunc.create(this.upHorse, this)) : "down" == c ? action = cc.Sequence.create(cc.Animate.create(this.frameActionObj[c]), cc.CallFunc.create(this.jumpEnd, this)) : "die" == c && (action = cc.Sequence.create(cc.Animate.create(this.frameActionObj[c]), cc.CallFunc.create(this.dieEnd, this)));
  249. this.frameObj[c] = action
  250. }
  251. }
  252. },
  253. jumpHigh: function() {
  254. this.state = "down";
  255. this.runAction(this.frameObj.down)
  256. },
  257. jumpEnd: function() {
  258. this._isDouble = !1;
  259. this.run();
  260. g_sharedGameLayer.toJump()
  261. },
  262. dieEnd: function() {
  263. g_sharedGameLayer.onGameOver()
  264. },
  265. update: function(a) {
  266. this.lock || (this.dx = this.powerx)
  267. },
  268. run: function() {
  269. this.state = "run";
  270. this.stopAllActions();
  271. this.runAction(this.frameObj.run)
  272. },
  273. toJump: function(a) {
  274. this._isDouble = 0 == a ? !1 : !0;
  275. this.stopAllActions();
  276. this.state = "up";
  277. this.runAction(this.frameObj.up)
  278. },
  279. touch: function(a) {
  280. "run" == this.state && this.toJump(a)
  281. },
  282. toDie: function() {
  283. this.stopAllActions();
  284. this.state = "die";
  285. this.runAction(this.frameObj.die)
  286. },
  287. destroy: function() {
  288. this.active = this.visible = !1;
  289. this.attactActionList = [];
  290. this.stopAllActions()
  291. },
  292. attactRect: function() {
  293. return cc.rect(this.x, -1, 130, -1)
  294. },
  295. collideRect: function(a, b) {
  296. return cc.rect(this.x, -1, 20, -1)
  297. }
  298. });
  299. Helo.getOrCreateEnemy = function(a) {
  300. return this
  301. };
  302. Helo.create = function() {
  303. return new Helo
  304. };
  305. var BgLayer = cc.Layer.extend({
  306. _bgs: null,
  307. _start: null,
  308. _bglist: [],
  309. _bgfshow: [],
  310. _bgbshow: [],
  311. _lefttx: -350,
  312. _fid: 0,
  313. _imgw: 853,
  314. _bid: 0,
  315. ctor: function() {
  316. this._super()
  317. },
  318. step: function(a) {
  319. this.time += a
  320. },
  321. init: function() {
  322. this._super();
  323. this._lefttx = -this._imgw / 2;
  324. this._bgs = cc.Node.create();
  325. this.addChild(this._bgs);
  326. var a = [res.bg_png, res.bg_png];
  327. this._bgfshow = [];
  328. this._bglist = [];
  329. for (var b = 0; 2 > b; b++) {
  330. var c = cc.Sprite.create(a[b]);
  331. c.anchorY = 0;
  332. this._bgs.addChild(c);
  333. c.visible = !0;
  334. c.y = 0;
  335. this._bglist.push(c)
  336. }
  337. this._bgfshow.push(this._bglist[0]);
  338. this._bgfshow.push(this._bglist[1]);
  339. this._bgfshow[1].x = this._bgfshow[0].x + this._imgw - 1;
  340. this._fid = 1;
  341. for (b = 0; 1 >= b; b++) this._bgfshow[b].visible = !0
  342. },
  343. update: function(a, b) {
  344. for (var c = 0; 2 > c; c++) this._bgfshow[c].x += a;
  345. this._bgfshow[0].x < this._lefttx && (c = this._bgfshow.shift(), c.visible = !1, this._fid += 1, this._bgfshow.push(c), this._bgfshow[1].x = this._bgfshow[0].x + this._imgw - 1, this._bgfshow[1].visible = !0)
  346. },
  347. destroy: function() {
  348. this._bgs.removeAllChildren();
  349. this.removeAllChildren();
  350. this._bgfshow = [];
  351. this._bglist = []
  352. },
  353. setIndex: function(a, b) {}
  354. });
  355. BgLayer.create = function() {
  356. var a = new BgLayer;
  357. a.init();
  358. return a
  359. };
  360. var MenuLayer = cc.Layer.extend({
  361. menu: null,
  362. title: null,
  363. isIntro: !1,
  364. _bglayer: null,
  365. logo: null,
  366. ctor: function() {
  367. this._super()
  368. },
  369. init: function() {
  370. this._super();
  371. cc.spriteFrameCache.addSpriteFrames(res.game_plist);
  372. cc.spriteFrameCache.addSpriteFrames(res.cb_plist);
  373. centerPos = cc.p(winSize.width / 2, winSize.height / 2);
  374. this._bglayer = BgLayer.create();
  375. this.addChild(this._bglayer);
  376. this._bglayer.y = 200;
  377. this.logo = cc.Layer.create();
  378. this.logo.x = winSize.width / 2;
  379. this.logo.y = winSize.height;
  380. this.title = cc.Sprite.create("#title.png");
  381. this.addChild(this.title);
  382. this.title.x = winSize.width / 2;
  383. this.title.y = winSize.height;
  384. var a = cc.Sprite.create("#cb0001.png");
  385. a.x = this.title.width / 2 - 2;
  386. a.y = this.title.height / 2;
  387. a.anchorX = 0.5;
  388. this.title.addChild(a, -1);
  389. for (var b = [], c, f = 1; 19 >= f; f++) c = 10 > f ? "0" + f : f, c = "cb00" + c + ".png", c = cc.spriteFrameCache.getSpriteFrame(c), b.push(c);
  390. b = cc.RepeatForever.create(cc.Animate.create(cc.Animation.create(b, 0.06)));
  391. a.runAction(b);
  392. this.title.anchorX = 0.5;
  393. a = cc.MoveTo.create(0.3, cc.p(winSize.width / 2, 0.6 * winSize.height));
  394. this.title.runAction(a);
  395. a = cc.Sprite.create("#frontbg.png");
  396. a.anchorY = 0;
  397. a.x = winSize.width / 2;
  398. a.y = 0;
  399. this.addChild(a);
  400. this.menu = cc.Sprite.create("#start0001.png");
  401. this.menu.x = winSize.width / 2;
  402. this.addChild(this.menu, 1);
  403. this.menu.anchorY = 0;
  404. this.menu.y = 40;
  405. this.initEvent();
  406. a = cc.Sprite.create(cc.tglogotexture2d);
  407. a.y = 26;
  408. a.anchorX = 0.5;
  409. a.x = winSize.width / 2;
  410. this.addChild(a);
  411. this.scheduleUpdate()
  412. },
  413. update: function(a) {
  414. this._bglayer.update(-5)
  415. },
  416. setIntro: function() {
  417. var a = cc.Sprite.create(res.gameintro);
  418. this.addChild(a, 0);
  419. a.y = 0.5 * winSize.height;
  420. a.x = winSize.width / 2;
  421. this.isIntro = !0;
  422. cc.eventManager.removeAllListeners();
  423. this.removeChild(this.menu);
  424. this.menu = cc.Sprite.create("#ok0001.png");
  425. this.menu.x = winSize.width / 2;
  426. this.addChild(this.menu, 1);
  427. this.menu.anchorY = 0;
  428. this.menu.y = 100;
  429. this.initEvent()
  430. },
  431. initEvent: function() {
  432. var a = this,
  433. b = cc.EventListener.create({
  434. event: cc.EventListener.TOUCH_ONE_BY_ONE,
  435. swallowTouches: !1,
  436. onTouchBegan: function(c, b) {
  437. var d = b.getCurrentTarget(),
  438. e = d.convertToNodeSpace(c.getLocation()),
  439. d = d.getContentSize(),
  440. d = cc.rect(0, 0, d.width,
  441. d.height);
  442. return cc.rectContainsPoint(d, e) ? (a.menu.y -= 3, setTimeout(function() {
  443. a.onPlay()
  444. }, 20), !0) : !1
  445. },
  446. onTouchEnded: function(c, b) {
  447. a.menu.y += 3;
  448. return !1
  449. }
  450. });
  451. cc.eventManager.addListener(b, a.menu)
  452. },
  453. onPlay: function() {
  454. this.isIntro ? (GD.SOUND && (cc.audioEngine.playMusic(res.bgsound, !0), cc.audioEngine.setMusicVolume(0.6)), /*pgvSendClick && "function" == typeof pgvSendClick && pgvSendClick({
  455. hottag: "h5game.horsegame.start"
  456. }),*/ cc.director.runScene(cc.TransitionFade.create(0.3, GameScene.create()))) : (cc.spriteFrameCache.removeSpriteFramesFromFile(res.cb_plist),
  457. this.removeChild(this.title), this.setIntro())
  458. }
  459. }),
  460. MenuScene = cc.Scene.extend({
  461. onEnter: function() {
  462. this._super();
  463. var a = new MenuLayer;
  464. a.init();
  465. this.addChild(a)
  466. }
  467. });
  468. MenuScene.create = function() {
  469. var a = new MenuScene;
  470. return a && a.init() ? a : null
  471. };
  472. STATE_PLAYING = 0;
  473. STATE_GAMEOVER = 1;
  474. var g_sharedGameLayer, GameLayer = cc.Layer.extend({
  475. _size: 0,
  476. _helo: null,
  477. _heloB: null,
  478. _time: GD.MAXTIME,
  479. _midx: 0,
  480. _attactzone: [],
  481. _npcontainer: null,
  482. _introscene: null,
  483. _live: 0,
  484. _dataLayer: null,
  485. _state: STATE_PLAYING,
  486. _hitUI: null,
  487. numLayer: null,
  488. _hitNum: 0,
  489. _barRenderer: null,
  490. _time2: 0,
  491. _others: null,
  492. _bgs: null,
  493. _space: 60,
  494. _bgbg: null,
  495. _bglayer: null,
  496. isRun: !1,
  497. _oneHitBtn: null,
  498. _twoHiBtn: null,
  499. _locktime: 5,
  500. _firelist: [],
  501. clicked: !1,
  502. _isChecked: !1,
  503. ctor: function() {
  504. this._super()
  505. },
  506. init: function() {
  507. if (this._super()) {
  508. this._space = 40;
  509. GD.SCORE = 0;
  510. this._time = GD.NUM = 0;
  511. this._midx = winSize.width / 2;
  512. this._leftmidx = this._midx / 2 - 120;
  513. this._rightmidx = this._midx + 120;
  514. g_sharedGameLayer = this;
  515. this.initBg();
  516. this.initRoles();
  517. this.initData();
  518. this.initUserControl();
  519. var a = cc.Sprite.create(cc.tglogotexture2d);
  520. a.y = 26;
  521. a.anchorX = 0.5;
  522. a.x = winSize.width / 2;
  523. this._state = STATE_PLAYING;
  524. this.schedule(this.clockCounter2, 1);
  525. this.scheduleUpdate()
  526. }
  527. },
  528. toRun: function() {
  529. this.isRun = !0
  530. },
  531. toJump: function(a) {
  532. this._isChecked = !1
  533. },
  534. initRoles: function() {
  535. cc.spriteFrameCache.addSpriteFrames(res.role_plist);
  536. cc.spriteFrameCache.addSpriteFrames(res.rolef_plist);
  537. var a = cc.textureCache.addImage(res.role_png);
  538. this._heloB = cc.SpriteBatchNode.create(a);
  539. this._heloB.setBlendFunc(cc.SRC_ALPHA, cc.ONE);
  540. this.addChild(this._heloB);
  541. this._helo = Helo.create();
  542. this._heloB.addChild(this._helo, 1);
  543. this._helo.y = 0.3 * winSize.height;
  544. this._helo.x = winSize.width / 3;
  545. this._firelist = [];
  546. for (a = 0; 2 > a; a++) {
  547. var b = Fire.create();
  548. this._heloB.addChild(b._foot, 0);
  549. this._heloB.addChild(b._lfire, 0);
  550. this._heloB.addChild(b._rfire, 2);
  551. b._showspeed = winSize.width;
  552. b.setX(2 * winSize.width * (1 + 1 * a));
  553. this._firelist.push(b)
  554. }
  555. this._firelist[0].setKind(0);
  556. this._firelist[1].setKind(1);
  557. trace(this._firelist[1]._kind)
  558. },
  559. initData: function() {
  560. this._live = this._time = this._time2 = 0;
  561. this._dataLayer = BitNumLayer.create();
  562. this.addChild(this._dataLayer)
  563. },
  564. initUserControl: function() {
  565. var a = this,
  566. b = cc.EventListener.create({
  567. event: cc.EventListener.TOUCH_ONE_BY_ONE,
  568. swallowTouches: !1,
  569. onTouchBegan: function(b, f) {
  570. var d = f.getCurrentTarget(),
  571. e = d.convertToNodeSpace(b.getLocation()),
  572. g = d.getContentSize(),
  573. g = cc.rect(0, 0, g.width, g.height);
  574. return cc.rectContainsPoint(g, e) ? (d.y -= 2, d == a._oneHitBtn ? a._helo.touch(0) : d == a._twoHiBtn && a._helo.touch(1), !0) : !1
  575. },
  576. onTouchEnded: function(b, f) {
  577. a.processTouchEndEvent(f.getCurrentTarget());
  578. return !0
  579. }
  580. });
  581. cc.eventManager.addListener(b, this._oneHitBtn);
  582. cc.eventManager.addListener(b.clone(), this._twoHiBtn)
  583. },
  584. clickEvent: function() {
  585. this.clicked && (this.clicked = !1)
  586. },
  587. initBg: function() {
  588. cc.spriteFrameCache.addSpriteFrames(res.game_plist);
  589. this._bglayer = BgLayer.create();
  590. this.addChild(this._bglayer);
  591. this._bglayer.y = 200;
  592. var a = cc.Sprite.create("#frontbg.png");
  593. a.anchorY = 0;
  594. a.x = winSize.width / 2;
  595. a.y = 0;
  596. this.addChild(a);
  597. this._oneHitBtn = cc.Sprite.create("#left.png");
  598. this._oneHitBtn.anchorY = 0;
  599. this._oneHitBtn.x = winSize.width / 2 - 150;
  600. this._oneHitBtn.y = 40;
  601. this.addChild(this._oneHitBtn);
  602. this._twoHiBtn = cc.Sprite.create("#right.png");
  603. this._twoHiBtn.anchorY = 0;
  604. this._twoHiBtn.x = winSize.width / 2 + 150;
  605. this._twoHiBtn.y = 40;
  606. this.addChild(this._twoHiBtn)
  607. },
  608. addPet: function(a, b, c) {
  609. this._roles.addChild(a, b, c)
  610. },
  611. removePet: function(a) {
  612. this._roles.addChild(a)
  613. },
  614. clockCounter2: function() {
  615. this._state == STATE_PLAYING && (this._time2 += 1, this._helo.speedUp(this._time2))
  616. },
  617. processTouchEndEvent: function(a) {
  618. a == this._oneHitBtn ? this._oneHitBtn.y += 2 : this._twoHiBtn.y += 2
  619. },
  620. processTouchEvent: function(a) {},
  621. update: function(a) {
  622. this._state == STATE_PLAYING && (0 >= this._locktime ? this._locktime = 5 : this._locktime--, this.checkIsCollide(a), this.updateUI())
  623. },
  624. checkIsCollide: function(a) {
  625. if (this.isRun) {
  626. this._helo.update();
  627. var b = -this._helo.dx;
  628. this._bglayer.update(b);
  629. for (var c = 0; 2 > c; c++) {
  630. if (a =
  631. this._firelist[c]) a._x += b, a.update(b);
  632. if (!a._isPassed && !this._isChecked && -20 > a._x - this._helo.x)
  633. if (this._isChecked = !0, "jump2" == this._helo.state && 1 == a._kind || "jump" == this._helo.state && 0 == a._kind) a._isPassed = !0, this._dataLayer.setNum(1, a._kind);
  634. else {
  635. this.toDie();
  636. return
  637. }
  638. }
  639. a = this._firelist[0]; - 150 > a._x && (a._x = this._firelist[1]._x + a._showspeed * (1 * Math.random() + 1), a._isPassed = !1, b = Math.floor(2 * Math.random()), a.setKind(b), this._firelist.shift(), this._firelist.push(a))
  640. }
  641. },
  642. updateUI: function() {},
  643. clearEmeny: function() {
  644. for (i =
  645. 0; i < GD.CONTAINER.ENEMIES.length; i++) {
  646. var a = GD.CONTAINER.ENEMIES[i];
  647. a && this._roles.removeChild(a)
  648. }
  649. GD.CONTAINER.ENEMIES = []
  650. },
  651. toDie: function() {
  652. this._state = STATE_GAMEOVER;
  653. this._helo.toDie()
  654. },
  655. onGameOver: function() {
  656. this.isRun = !1;
  657. this._state = STATE_GAMEOVER;
  658. this.unschedule(this.clockCounter2, 0.1);
  659. this._bglayer.destroy();
  660. this._heloB.removeAllChildren();
  661. this._helo = null;
  662. cc.eventManager.removeAllListeners();
  663. cc.spriteFrameCache.removeSpriteFramesFromFile(res.rolef_plist);
  664. cc.spriteFrameCache.removeSpriteFramesFromFile(res.role_plist);
  665. cc.director.runScene(GameOverScene.create())
  666. },
  667. reStart: function() {
  668. this.init()
  669. }
  670. }),
  671. GameScene = cc.Scene.extend({
  672. onEnter: function() {
  673. this._super();
  674. var a = new GameLayer;
  675. a.init();
  676. this.addChild(a)
  677. }
  678. });
  679. GameScene.create = function() {
  680. var a = new GameScene;
  681. return a && a.init() ? a : null
  682. };
  683. var GameOverLayer = cc.Layer.extend({
  684. _time: null,
  685. _bg: null,
  686. _scoreLabel: null,
  687. _sharelayer: null,
  688. _viewB: null,
  689. sharemenu: null,
  690. againmenu: null,
  691. downmenu: null,
  692. _sharebg: null,
  693. isShare: !1,
  694. ctor: function() {
  695. this._super()
  696. },
  697. init: function() {
  698. cc.spriteFrameCache.addSpriteFrames(res.gameover_plist);
  699. this.initBg();
  700. this.initMenu();
  701. var a = cc.Sprite.create(cc.tglogotexture2d);
  702. a.y = 26;
  703. a.anchorX = 0.5;
  704. a.x = winSize.width / 2;
  705. this.createshare();
  706. this.hideShare()
  707. },
  708. initEvent: function() {
  709. var a = this,
  710. b = cc.EventListener.create({
  711. event: cc.EventListener.TOUCH_ONE_BY_ONE,
  712. swallowTouches: !1,
  713. onTouchBegan: function(b, f) {
  714. var d = f.getCurrentTarget(),
  715. e = d.convertToNodeSpace(b.getLocation()),
  716. g = d.getContentSize(),
  717. g = cc.rect(0, 0, g.width, g.height);
  718. if (cc.rectContainsPoint(g, e)) {
  719. trace("\x3d---" + a.isShare + d);
  720. if (!1 == a.isShare) {
  721. d.y -= 2;
  722. if (d == a.sharemenu) trace("shrae0"), a.onShare();
  723. else if (d == a.againmenu) a.onAgain();
  724. else if (d == a.downmenu) a.onDownLoad();
  725. return !0
  726. }
  727. d == a._sharebg && a.hideShare()
  728. }
  729. return !1
  730. },
  731. onTouchEnded: function(a, b) {
  732. var d = b.getCurrentTarget();
  733. d.y += 2
  734. }
  735. });
  736. cc.eventManager.addListener(b,
  737. this.sharemenu);
  738. cc.eventManager.addListener(b.clone(), this.againmenu);
  739. cc.eventManager.addListener(b.clone(), this.downmenu);
  740. cc.eventManager.addListener(b.clone(), this._sharebg)
  741. },
  742. initMenu: function() {
  743. var a = this;
  744. this.sharemenu = cc.Sprite.create("#sharebtn.png");
  745. this.againmenu = cc.Sprite.create("#again.png");
  746. this.downmenu = cc.Sprite.create("#get0001.png");
  747. this.addChild(this.sharemenu);
  748. this.addChild(this.againmenu);
  749. this.addChild(this.downmenu);
  750. this.downmenu.x = this.againmenu.x = this.sharemenu.x = winSize.width /
  751. 2;
  752. this.sharemenu.y = winSize.height / 2 - 20;
  753. this.downmenu.y = winSize.height / 2 - 160;
  754. this.againmenu.y = 100;
  755. setTimeout(function() {
  756. a.initEvent()
  757. }, 200)
  758. },
  759. initBg: function() {
  760. this._sharelayer = null;
  761. this._bg = cc.Sprite.create(res.bg_png);
  762. this.addChild(this._bg, 0);
  763. this._bg.anchorY = 0;
  764. this._bg.x = winSize.width / 2;
  765. this._bg.y = 200;
  766. this.addChild(this._bg);
  767. var a = cc.Sprite.create("#score.png");
  768. this.addChild(a);
  769. a.y = 0.6 * winSize.height;
  770. a.x = winSize.width / 2;
  771. a = cc.Sprite.create("#frontbg.png");
  772. a.anchorY = 0;
  773. a.x = winSize.width / 2;
  774. a.y = 0;
  775. this.addChild(a);
  776. this._scoreLabel = cc.LabelAtlas.create("0", res.num_png, 36, 65, "0");
  777. this.addChild(this._scoreLabel);
  778. this._scoreLabel.color = cc.color.RED;
  779. this._scoreLabel.anchorX = 0.5;
  780. this._scoreLabel.setString(GD.NUM);
  781. this._scoreLabel.x = 0.5 * winSize.width + 100;
  782. this._scoreLabel.y = 0.6 * winSize.height + 80;
  783. this._scoreLabel.scale = 1.5;
  784. a = cc.LabelTTF.create("", "Arial", 50);
  785. this.addChild(a);
  786. a.color = cc.color.RED;
  787. a.anchorX = 0.5;
  788. a.setString(GD.NUM);
  789. a.x = 0.5 * winSize.width + 30;
  790. a.y = 0.5 * winSize.height + 95
  791. },
  792. hideShare: function() {
  793. this.isShare = !1;
  794. this._sharebg && (this._sharebg.visible = !1)
  795. },
  796. showShare: function() {
  797. this.isShare = !0;
  798. this._sharebg.visible = !0
  799. },
  800. createshare: function() {
  801. trace("createshare");
  802. if (!this._sharebg) {
  803. this._sharebg = new cc.Layer.create;
  804. this.share = cc.Sprite.create("#share.png");
  805. this.share.anchorX = 1;
  806. this.share.anchorY = 1;
  807. this.share.x = winSize.width - 20;
  808. this.share.y = winSize.height - 10;
  809. var a = cc.DrawNode.create();
  810. a.drawRect(cc.p(-56, -10), cc.p(800, winSize.height + 20), cc.color(25, 25, 25, 180), 0, 0);
  811. this._sharebg.addChild(a);
  812. this._sharebg.addChild(this.share);
  813. this.addChild(this._sharebg)
  814. }
  815. },
  816. onAgain: function() {
  817. // pgvSendClick && "function" == typeof pgvSendClick && pgvSendClick({
  818. // hottag: "h5game.horsegame.again"
  819. // });
  820. cc.spriteFrameCache.removeSpriteFramesFromFile(res.npc_plist);
  821. cc.director.runScene(cc.TransitionFade.create(0.3, GameScene.create()))
  822. },
  823. onDownLoad: function() {
  824. // pgvSendClick && "function" == typeof pgvSendClick && pgvSendClick({
  825. // hottag: "h5game.horsegame.download"
  826. // });
  827. // window.open("http://dnf.qq.com/act/a20140918wxlucky/index.htm", "_blank")
  828. },
  829. onShare: function() {
  830. // pgvSendClick &&
  831. // "function" == typeof pgvSendClick && pgvSendClick({
  832. // hottag: "h5game.horsegame.sharebtn"
  833. // });
  834. this.showShare()
  835. },
  836. onOver: function() {}
  837. }),
  838. GameOverScene = cc.Scene.extend({
  839. onEnter: function() {
  840. this._super();
  841. var a = new GameOverLayer;
  842. a.init();
  843. this.addChild(a)
  844. }
  845. });
  846. GameOverScene.create = function() {
  847. var a = new GameOverScene;
  848. return a && a.init() ? a : null
  849. };
  850. cc.game.onStart = function() {
  851. cc.sys.isMobile ? cc.view.setDesignResolutionSize(640, 1008, cc.ResolutionPolicy.FIXED_HEIGHT) : cc.view.setDesignResolutionSize(640, 1008, cc.ResolutionPolicy.SHOW_ALL);
  852. winSize = cc.director.getWinSize();
  853. cc.LoaderScene.preload(g_mainmenu, function() {
  854. cc.director.runScene(MenuScene.create())
  855. }, this)
  856. }; /* |xGv00|95b26c12cfec2fb4c476231d744743c9 */