Main.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. var 苦数据列表;
  2. var 苦舞台层;
  3. var 苦舞台索引 = 0;
  4. var 常移步 = 8;
  5. var 常移步慢 = 8;
  6. var 常移步快 = 12;
  7. var 苦值 = 3;
  8. var 苦停止标志;
  9. var 苦游戏主体;
  10. var 苦运行地图;
  11. var 苦运行角色;
  12. var 苦名人层;
  13. var 苦项目层;
  14. var 苦星控制;
  15. var bgmusic=new MusicObject("audio/bgmusic.mp3",true);
  16. var 苦加载数据 = [
  17. {name : "num_0",path : "images/num_0.png"},
  18. {name : "num_1",path : "images/num_1.png"},
  19. {name : "num_2",path : "images/num_2.png"},
  20. {name : "num_3",path : "images/num_3.png"},
  21. {name : "num_4",path : "images/num_4.png"},
  22. {name : "num_5",path : "images/num_5.png"},
  23. {name : "num_6",path : "images/num_6.png"},
  24. {name : "num_7",path : "images/num_7.png"},
  25. {name : "num_8",path : "images/num_8.png"},
  26. {name : "num_9",path : "images/num_9.png"},
  27. {name : "effect",path : "images/effect.png"},
  28. {name : "logo",path : "kaishi.jpg"},
  29. {name : "inputbox",path : "images/inputbox.png"},
  30. {name : "spiritEffect",path : "images/spiritEffect.png"},
  31. {name : "b_background",path : "beijing.jpg"},
  32. {name : "m_background",path : "images/m_background.png"},
  33. {name : "stage",path : "images/stage.png"},
  34. {name : "chara",path : "images/chara.png"},
  35. {name : "bird",path : "images/bird.png"},
  36. {name : "gui",path : "images/gui.png"},
  37. {name : "window",path : "shibai.jpg"},
  38. {name : "HP_bg",path : "images/hp_bg.png"},
  39. {name : "HP_value",path : "images/hp_value.png"},
  40. ];
  41. init(1000/30, "legend", 640, 1136, 主);
  42. function 主() {
  43. var protocol = location.protocol;
  44. if(LGlobal.mobile){
  45. LGlobal.stageScale = LStageScaleMode.NO_BORDER;
  46. LSystem.screen(LStage.FULL_SCREEN);
  47. }
  48. LGlobal.setDebug(true);
  49. LMouseEventContainer.set(LMouseEvent.MOUSE_DOWN,true);
  50. LMouseEventContainer.set(LMouseEvent.MOUSE_UP,true);
  51. LMouseEventContainer.set(LMouseEvent.MOUSE_MOVE,true);
  52. loadingLayer = new LoadingSample4();
  53. addChild(loadingLayer);
  54. LLoadManage.load(苦加载数据, function(progress) {
  55. loadingLayer.setProgress(progress);
  56. }, 当图片加载完);
  57. }
  58. function 当图片加载完(result){
  59. 苦数据列表 = result;
  60. removeChild(loadingLayer);
  61. loadingLayer = null;
  62. 苦舞台层 = new LSprite();
  63. addChild(苦舞台层);
  64. // 游戏开始();
  65. var logo = new 商标();
  66. 苦舞台层.addChild(logo);
  67. return;
  68. var fps = new FPS();
  69. addChild(fps);
  70. }
  71. function 游戏开始(){
  72. 苦舞台层.die();
  73. 苦舞台层.removeAllChild();
  74. LTweenLite.removeAll();
  75. 常移步 = 常移步慢;
  76. 苦停止标志 = false;
  77. 苦游戏主体 = new 游戏主体();
  78. 苦舞台层.addChild(苦游戏主体);
  79. return;
  80. //debug
  81. var sprite = new LSprite();
  82. addChild(sprite);
  83. sprite.graphics.加(function (){
  84. var c = LGlobal.canvas;
  85. var w = 32,h = 32;
  86. var l1 = LGlobal.width/w;
  87. var l2 = LGlobal.height/h;
  88. c.beginPath();
  89. c.strokeStyle = "#000000";
  90. for(var i=1;i<l1;i++){
  91. c.moveTo(w*i,0);
  92. c.lineTo(w*i,LGlobal.height);
  93. }
  94. for(var i=1;i<l2;i++){
  95. c.moveTo(0,h*i);
  96. c.lineTo(LGlobal.width,h*i);
  97. }
  98. c.stroke();
  99. });
  100. }
  101. ///////////////////////////////////////
  102. function 背景(){
  103. base(this,LSprite,[]);
  104. this.初始();
  105. }
  106. 背景.prototype.初始 = function(){
  107. var 俺 = this;
  108. 俺.back = new LBitmap(new LBitmapData(苦数据列表["b_background"],0,0,640,1136));//800,480
  109. 俺.backX = 0;
  110. 俺.addChild(俺.back);
  111. 俺.grass = new LBitmap(new LBitmapData(苦数据列表["m_background"]));
  112. 俺.grass.y = LGlobal.height - 俺.grass.getHeight();
  113. 俺.addChild(俺.grass);
  114. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  115. };
  116. 背景.prototype.心跳 = function(event){
  117. var 俺 = event.target;
  118. if(苦游戏主体.为停止())return;
  119. 俺.backX += 常移步*0.1;
  120. if(俺.backX > LGlobal.width){
  121. 俺.backX -= LGlobal.width;
  122. }
  123. 俺.back.bitmapData.setCoordinate(俺.backX,0);
  124. 俺.grass.x -= 常移步*0.5;
  125. if(俺.grass.x + 960 < 0){
  126. 俺.grass.x = LGlobal.width;
  127. }
  128. };
  129. ///////////////////////////////////////
  130. function 我(hp){
  131. base(this,LSprite,[]);
  132. this.初始(hp);
  133. }
  134. 我.走 = "走";
  135. 我.飞 = "飞";
  136. 我.伤 = "伤";
  137. 我.跳 = "跳";
  138. 我.prototype.初始 = function(hp){
  139. var 俺 = this;
  140. 俺.hp = hp;
  141. var effect = new LBitmap(new LBitmapData(苦数据列表["effect"]));
  142. effect.x = -180;
  143. effect.y = -70;
  144. 俺.addChild(effect);
  145. 俺.effect = effect;
  146. 俺.effect.visible = false;
  147. var data = new LBitmapData(苦数据列表["chara"],0,0,100,130);
  148. var list = LGlobal.divideCoordinate(400,520,4,4);
  149. 俺.action = 我.走;
  150. 俺.heroShadows = [new LBitmap(data),new LBitmap(data)];
  151. 俺.heroShadows[0].alpha = 0.7;
  152. 俺.heroShadows[1].alpha = 0.3;
  153. 俺.heroShadows[0].visible = false;
  154. 俺.heroShadows[1].visible = false;
  155. 俺.addChild(俺.heroShadows[0]);
  156. 俺.addChild(俺.heroShadows[1]);
  157. 俺.hero = new LAnimationTimeline(data,list);
  158. 俺.hero.setLabel(我.走,0,0);
  159. 俺.hero.setLabel(我.飞,1,0);
  160. 俺.hero.setLabel(我.伤,2,0);
  161. 俺.hero.setLabel(我.跳,3,0);
  162. 俺.hero.x = -48;
  163. 俺.hero.y = -120;
  164. 俺.hero.speed = 6;
  165. 俺.addChild(俺.hero);
  166. 俺.heroShadows[0].x = 俺.hero.x - 20;
  167. 俺.heroShadows[0].y = 俺.hero.y;
  168. 俺.heroShadows[1].x = 俺.hero.x - 40;
  169. 俺.heroShadows[1].y = 俺.hero.y;
  170. 俺.vy = 0;
  171. 俺.jumpCount = 0;
  172. 俺.distance = 0;
  173. 俺.spiritCount = 0;
  174. 俺.countValue = 常移步*5;
  175. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  176. };
  177. 我.prototype.阴影改变 = function(value){
  178. var 俺 = this;
  179. 俺.heroShadows[0].visible = value;
  180. 俺.heroShadows[1].visible = value;
  181. };
  182. 我.prototype.心灵结束 = function(){
  183. var 俺 = 苦运行角色;
  184. 俺.spiritCount = 0;
  185. 俺.hero.play();
  186. 俺.hero.onframe();
  187. 俺.阴影改变(true);
  188. };
  189. 我.prototype.心灵开始 = function(){
  190. var 俺 = this;
  191. if(俺.spiritCount <= 1){
  192. 苦运行角色.effect.alpha = 0;
  193. 苦运行角色.effect.visible = true;
  194. 常移步 = 常移步快;
  195. LTweenLite.to(苦运行角色.effect,1,{alpha:1,ease:LEasing.None,onComplete:俺.心灵结束});
  196. return;
  197. }
  198. 俺.spiritCount--;
  199. var spirit = new LSprite();
  200. var spiritBitmap = new LBitmap(new LBitmapData(苦数据列表["spiritEffect"]));
  201. spiritBitmap.x = -spiritBitmap.getWidth()*0.5;
  202. spiritBitmap.y = -spiritBitmap.getHeight()*0.5;
  203. spirit.addChild(spiritBitmap);
  204. spirit.scaleX = spirit.scaleY = 5;
  205. 俺.spirit = spirit;
  206. 俺.addChild(spirit);
  207. LTweenLite.to(spirit,0.5,{scaleX:0.1,scaleY:0.1,rotate:360,ease:LEasing.None,onComplete:function(){
  208. 俺.spirit.remove();
  209. 俺.心灵开始();
  210. }});
  211. };
  212. 我.prototype.置矩形 = function(){
  213. var 俺 = this;
  214. 俺.rect = new LRectangle(50 + 俺.hero.x,22 + 俺.hero.y,50,86);
  215. };
  216. 我.prototype.无敌 = function(){
  217. return this.effect.visible;
  218. };
  219. 我.prototype.心跳 = function(event){
  220. var 俺 = event.target;
  221. if(苦游戏主体.为停止()){
  222. if(俺.hero.mode != 0){
  223. 俺.hero.stop();
  224. }
  225. return;
  226. }else if(俺.hero.mode == 0){
  227. 俺.hero.play();
  228. }
  229. 俺.y += 俺.vy;
  230. 俺.vy += 苦值;
  231. if(俺.无敌()){
  232. 苦星控制.改值(-0.1);
  233. if(苦星控制.value <= 0){
  234. 俺.effect.visible = false;
  235. 俺.阴影改变(false);
  236. }
  237. }
  238. if(俺.vy > 32)俺.vy = 32;
  239. if(俺.y > LGlobal.height + 100){
  240. 俺.die();
  241. // MySoundPlayer.playSound("gameover");
  242. 俺.parent.游戏结束();
  243. return;
  244. }
  245. 俺.distance += 常移步;
  246. var countValue = 俺.distance / 俺.countValue >>> 0;
  247. if(俺.distanceObj && 俺.distanceObj.value < countValue){
  248. 俺.distanceObj.置值(countValue);
  249. }
  250. if(俺.action == 我.飞){
  251. 俺.hp.改值(-0.5);
  252. if(俺.hp.value <= 1){
  253. 俺.跳起来();
  254. }else{
  255. // MySoundPlayer.playSound("飞");
  256. 俺.vy = 0;
  257. 俺.y -= 4;
  258. if(俺.y < 64)俺.y = 64;
  259. }
  260. return;
  261. }else if(俺.action == 我.伤){
  262. if(俺.hertCount-- < 0){
  263. 俺.运行起来();
  264. }
  265. }else{
  266. 俺.hp.改值(0.05);
  267. }
  268. if(俺.vy < 0)return;
  269. var checkList = 苦运行地图.childList,child;
  270. for(var i=0,l=checkList.length;i<l;i++){
  271. child = checkList[i];
  272. if(child.检查碰撞点(俺.x,俺.y)){
  273. 俺.y = child.y;
  274. 俺.vy = 0;
  275. 俺.jumpCount = 0;
  276. 俺.运行起来();
  277. break;
  278. }
  279. }
  280. };
  281. 我.prototype.跳 = function(){
  282. var 俺 = this;
  283. if(俺.action == 我.伤)return;
  284. if(俺.jumpCount < 2){
  285. // MySoundPlayer.playSound("跳");
  286. 俺.vy = -30;
  287. 俺.jumpCount++;
  288. 俺.跳起来();
  289. }else if(俺.hp.value > 1){
  290. 俺.飞();
  291. }
  292. };
  293. 我.prototype.跳完 = function(){
  294. var 俺 = this;
  295. if(俺.action == 我.伤)return;
  296. 俺.跳起来();
  297. };
  298. 我.prototype.跳起来 = function(){
  299. var 俺 = this;
  300. if(俺.action == 我.跳)return;
  301. 俺.action = 我.跳;
  302. 俺.hero.gotoAndPlay(我.跳);
  303. };
  304. 我.prototype.飞 = function(){
  305. var 俺 = this;
  306. if(俺.action == 我.飞)return;
  307. 俺.action = 我.飞;
  308. 俺.hero.gotoAndPlay(我.飞);
  309. 俺.hero.onframe();
  310. };
  311. 我.prototype.运行起来 = function(){
  312. var 俺 = this;
  313. if(俺.action == 我.走)return;
  314. if(俺.action == 我.伤 && 俺.hertCount>=0)return;
  315. 俺.action = 我.走;
  316. 俺.hero.gotoAndPlay(我.走);
  317. 俺.hero.onframe();
  318. };
  319. 我.prototype.伤 = function(){
  320. var 俺 = this;
  321. if(俺.action == 我.伤)return;
  322. 俺.action = 我.伤;
  323. 俺.hero.gotoAndPlay(我.伤);
  324. 俺.hertCount = 10;
  325. 俺.hp.改值(-20);
  326. };
  327. ///////////////////////////////////////
  328. function 商标(){
  329. base(this,LSprite,[]);
  330. this.初始();
  331. }
  332. 商标.prototype.初始 = function(){
  333. var 俺 = this,labelText;
  334. var bitmap = new LBitmap(new LBitmapData(苦数据列表["logo"]));
  335. 俺.addChild(bitmap);
  336. 俺.addEventListener(LMouseEvent.MOUSE_UP, 俺.开始);
  337. };
  338. 商标.prototype.开始 = function(event){
  339. var 俺 = event.clickTarget;
  340. 游戏开始();
  341. bgmusic.replay();
  342. };
  343. ///////////////////////////////////////
  344. function 地图(){
  345. base(this,LSprite,[]);
  346. this.初始();
  347. }
  348. 地图.prototype.初始 = function(){
  349. var 俺 = this;
  350. 俺.dieFloorList = [];
  351. 俺.加底部(2);
  352. 俺.floor.x = 0;
  353. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  354. };
  355. 地图.prototype.心跳 = function(event){
  356. var 俺 = event.target;
  357. if(苦游戏主体.为停止())return;
  358. while(俺.dieFloorList.length > 0){
  359. var child = 俺.dieFloorList.shift();
  360. 俺.removeChild(child);
  361. }
  362. };
  363. 地图.prototype.加底部 = function(index){
  364. var 俺 = this;
  365. 俺.floor = StageData.取底部(index);
  366. 俺.addChild(俺.floor);
  367. 俺.floor.addEventListener(底部.OUT_COMPLETE,俺.取底部);
  368. 俺.floor.addEventListener(底部.OUT_DIE,俺.加死亡底部);
  369. };
  370. 地图.prototype.取底部 = function(event){
  371. var 俺 = event.target.parent;
  372. 俺.floor.removeEventListener(底部.OUT_COMPLETE,俺.取底部);
  373. 俺.加底部(1);
  374. };
  375. 地图.prototype.加死亡底部 = function(event){
  376. var 俺 = event.target.parent;
  377. 俺.dieFloorList.push(event.target);
  378. };
  379. ///////////////////////////////////////
  380. var StageData = {
  381. 取底部:function(index){
  382. var floor;
  383. floor = new 底部(index);
  384. return floor;
  385. }
  386. };
  387. ///////////////////////////////////////
  388. function 游戏主体(){
  389. base(this,LSprite,[]);
  390. this.初始();
  391. }
  392. 游戏主体.prototype.初始 = function(){
  393. var 俺 = this;
  394. 俺.moveStepCount = 0;
  395. 俺.gameover = false;
  396. var background = new 背景();
  397. 俺.addChild(background);
  398. 俺.speedBitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],32*14,32*3,40,48));
  399. 俺.speedBitmap.x = 32;
  400. 俺.speedBitmap.y = 30;
  401. 俺.speedBitmap.visible = false;
  402. 俺.addChild(俺.speedBitmap);
  403. 苦项目层 = new LSprite();
  404. 苦名人层 = new LSprite();
  405. 苦运行地图 = new 地图();
  406. 俺.addChild(苦运行地图);
  407. 俺.addChild(苦项目层);
  408. 俺.addChild(苦名人层);
  409. var hp = new 血();
  410. hp.x = 16;
  411. hp.y = 10;
  412. 苦星控制 = new 星();
  413. 苦星控制.x = 32 + hp.getWidth();
  414. 苦星控制.y = 2;
  415. 苦运行角色 = new 我(hp);
  416. 苦运行角色.x = 32 * 8;
  417. 苦运行角色.y = 32 * 4;
  418. 苦运行角色.置矩形();
  419. 俺.addChild(苦运行角色);
  420. 俺.character = 苦运行角色;
  421. 俺.addChild(hp);
  422. 俺.addChild(苦星控制);
  423. var num = new 数值(数值.LEFT);
  424. num.x = LGlobal.width/2 ;
  425. num.y = 42;
  426. 俺.addChild(num);
  427. 苦运行角色.distanceObj = num;
  428. 俺.stopBitmapData = new LBitmapData(苦数据列表["stage"],32*23,32*3,64,64);
  429. 俺.playBitmapData = new LBitmapData(苦数据列表["stage"],32*25,32*3,64,64);
  430. 俺.stopBitmap = new LBitmap(俺.stopBitmapData);
  431. 俺.stopBitmap.x = 416;
  432. 俺.stopBitmap.y = 16;
  433. 俺.addChild(俺.stopBitmap);
  434. 俺.addEventListener(LMouseEvent.MOUSE_UP, 俺.mouseup);
  435. 俺.addEventListener(LMouseEvent.MOUSE_DOWN, 俺.mousedown);
  436. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  437. };
  438. 游戏主体.prototype.为停止 = function(){
  439. if(苦停止标志 || 苦运行角色.spiritCount > 0){
  440. return true;
  441. }
  442. return false;
  443. };
  444. 游戏主体.prototype.心跳 = function(event){
  445. var 俺 = event.target,child,i,l;
  446. if(苦游戏主体.为停止())return;
  447. if(常移步 == 常移步快){
  448. if(俺.moveStepCount-- <= 0 && !苦运行角色.无敌()){
  449. 常移步 = 常移步慢;
  450. 俺.speedBitmap.visible = false;
  451. }
  452. }
  453. for(i=0,l=苦名人层.childList.length;i<l;i++){
  454. child = 苦名人层.childList[i];
  455. if(child.x < -96){
  456. child.remove();
  457. i--;
  458. l--;
  459. }
  460. }
  461. for(i=0,l=苦项目层.childList.length;i<l;i++){
  462. child = 苦项目层.childList[i];
  463. if(child.x < -96){
  464. child.remove();
  465. i--;
  466. l--;
  467. }
  468. }
  469. };
  470. 游戏主体.prototype.mousedown = function(event){
  471. var 俺 = event.clickTarget;
  472. if(event.selfX > 俺.stopBitmap.x && event.selfX < 俺.stopBitmap.x + 俺.stopBitmap.getWidth() &&
  473. event.selfY > 俺.stopBitmap.y && event.selfY < 俺.stopBitmap.y + 俺.stopBitmap.getHeight()){
  474. if(苦停止标志){
  475. 俺.stopBitmap.bitmapData = 俺.stopBitmapData;
  476. // MySoundPlayer.background.play();
  477. }else{
  478. 俺.stopBitmap.bitmapData = 俺.playBitmapData;
  479. // MySoundPlayer.background.stop();
  480. }
  481. 苦停止标志 = !苦停止标志;
  482. return;
  483. }
  484. if(苦游戏主体.为停止())return;
  485. // MySoundPlayer.loadSound();
  486. 俺.character.跳();
  487. };
  488. 游戏主体.prototype.mouseup = function(event){
  489. var 俺 = event.clickTarget;
  490. if(苦游戏主体.为停止())return;
  491. 俺.character.跳完();
  492. };
  493. 游戏主体.prototype.游戏结束 = function(event){
  494. 苦停止标志 = true;
  495. var 俺 = this;
  496. 俺.removeEventListener(LMouseEvent.MOUSE_UP, 俺.mouseup);
  497. 俺.removeEventListener(LMouseEvent.MOUSE_DOWN, 俺.mousedown);
  498. var overLayer = new 游戏结束();
  499. 俺.addChild(overLayer);
  500. };
  501. ///////////////////////////////////////
  502. function 底部(index){
  503. base(this,LSprite,[]);
  504. this.初始(index);
  505. }
  506. 底部.OUT_COMPLETE = "floor_out_complete";
  507. 底部.OUT_DIE = "floor_out_die";
  508. 底部.prototype.初始 = function(index){
  509. var 俺 = this;
  510. 俺.isOutComplete = false;
  511. 俺.x = LGlobal.width;
  512. 俺.y = 32*6 + 32*(8*Math.random() >>> 0);
  513. 俺.isStart = false;
  514. var bitmap,rightBitmap;
  515. switch(index){
  516. case 1:
  517. bitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],0,0,32*(3 + (19*Math.random() >>> 0)),96));
  518. bitmap.y = -32;
  519. 俺.addChild(bitmap);
  520. break;
  521. default:
  522. 俺.isStart = true;
  523. bitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],0,0,960,96));
  524. bitmap.y = -32;
  525. 俺.addChild(bitmap);
  526. rightBitmap = true;
  527. break;
  528. }
  529. if(!rightBitmap){
  530. rightBitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],32*29,0,32,96));
  531. rightBitmap.x = bitmap.getWidth();
  532. rightBitmap.y = -32;
  533. 俺.addChild(rightBitmap);
  534. }
  535. 俺.maxRight = LGlobal.width - 32*2 - 32*(10*Math.random() >>> 0);
  536. 俺.right = 俺.getWidth();
  537. 俺.bottom = 32*2;
  538. 名人.加(俺);
  539. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  540. };
  541. 底部.prototype.心跳 = function(event){
  542. var 俺 = event.target;
  543. if(苦游戏主体.为停止())return;
  544. 俺.x -= 常移步;
  545. if(!俺.isOutComplete && 俺.x + 俺.getWidth() < 俺.maxRight){
  546. 俺.isOutComplete = true;
  547. 俺.dispatchEvent(底部.OUT_COMPLETE);
  548. }else if(俺.x + 俺.getWidth() < 0){
  549. 俺.dispatchEvent(底部.OUT_DIE);
  550. 俺.die();
  551. }
  552. };
  553. 底部.prototype.检查碰撞点 = function(x,y){
  554. var 俺 = this;
  555. if(x > 俺.x && x < 俺.x + 俺.right && y > 俺.y && y< 俺.y + 俺.bottom){
  556. return true;
  557. }
  558. return false;
  559. };
  560. ///////////////////////////////////////
  561. function 血(){
  562. base(this,LSprite,[]);
  563. this.初始();
  564. }
  565. 血.prototype.初始 = function(){
  566. var 俺 = this;
  567. var HP_bg = new LBitmap(new LBitmapData(苦数据列表["HP_bg"]));
  568. HP_bg.x = 445; //-15
  569. HP_bg.y = 100; //-2
  570. 俺.addChild(HP_bg);
  571. 俺.value = 俺.maxValue = 100;
  572. 俺.HP_value = new LBitmap(new LBitmapData(苦数据列表["HP_value"]));
  573. 俺.HP_value.x = 453; //-15
  574. 俺.HP_value.y = 102; //-2
  575. 俺.addChild(俺.HP_value);
  576. };
  577. 血.prototype.改值 = function(value){
  578. var 俺 = this;
  579. 俺.value += value;
  580. if(俺.value < 1){
  581. 俺.value = 1;
  582. }else if(俺.value > 100){
  583. 俺.value = 100;
  584. }
  585. 俺.HP_value.scaleX = 俺.value/俺.maxValue;
  586. };
  587. ///////////////////////////////////////
  588. function 数值(direction){
  589. base(this,LSprite,[]);
  590. this.初始(direction);
  591. }
  592. 数值.LEFT = "num_left";
  593. 数值.RIGHT = "num_right";
  594. 数值.prototype.初始 = function(direction){
  595. var 俺 = this;
  596. 俺.direction = direction;
  597. 俺.苦数据列表 = [
  598. new LBitmapData(苦数据列表["num_0"]),
  599. new LBitmapData(苦数据列表["num_1"]),
  600. new LBitmapData(苦数据列表["num_2"]),
  601. new LBitmapData(苦数据列表["num_3"]),
  602. new LBitmapData(苦数据列表["num_4"]),
  603. new LBitmapData(苦数据列表["num_5"]),
  604. new LBitmapData(苦数据列表["num_6"]),
  605. new LBitmapData(苦数据列表["num_7"]),
  606. new LBitmapData(苦数据列表["num_8"]),
  607. new LBitmapData(苦数据列表["num_9"])
  608. ];
  609. 俺.list = [];
  610. 俺.置值(0);
  611. };
  612. 数值.prototype.置值 = function(value){
  613. var 俺 = this;
  614. 俺.value = value;
  615. var strValue = 俺.value.toString(),numBitmap,sx;
  616. if(俺.childList.length != strValue.length){
  617. 俺.置列表(strValue.length);
  618. }
  619. for(var i=0,l=strValue.length;i<l;i++){
  620. numBitmap = 俺.childList[i];
  621. numBitmap.bitmapData = 俺.苦数据列表[parseInt(strValue.charAt(i))];
  622. }
  623. };
  624. 数值.prototype.置列表 = function(length){
  625. var 俺 = this;
  626. if(俺.childList.length > length){
  627. 俺.childList.splice(length - 1,俺.childList.length - length);
  628. return;
  629. }
  630. var sx,numBitmap;
  631. if(俺.direction == 数值.LEFT){
  632. sx = -length*20;
  633. }else{
  634. sx = -20;
  635. }
  636. for(var i=0,l=length;i<l;i++){
  637. if(i >= 俺.childList.length){
  638. numBitmap = new LBitmap(俺.苦数据列表[0]);
  639. 俺.addChild(numBitmap);
  640. }
  641. numBitmap = 俺.childList[i];
  642. sx += 20;
  643. numBitmap.x = sx;
  644. }
  645. };
  646. ///////////////////////////////////////
  647. function 名人(name){
  648. base(this,LSprite,[]);
  649. this.初始(name);
  650. }
  651. 名人.prototype.初始 = function(name){
  652. var 俺 = this;
  653. 俺.name = name;
  654. var data = new LBitmapData(苦数据列表[name],0,0,96,96);
  655. var list = LGlobal.divideCoordinate(384,96,1,4);
  656. 俺.hero = new LAnimationTimeline(data,list);
  657. 俺.hero.x = -48;
  658. 俺.hero.y = -90;
  659. 俺.hero.speed = 16; //6
  660. 俺.addChild(俺.hero);
  661. 俺.vy = 0;
  662. 俺.苦值 = 0;
  663. 俺.speedx = 0;
  664. if(俺.name == "gui"){
  665. 俺.苦值 = 苦值;
  666. 俺.hero.y = -96;
  667. 俺.rect = new LRectangle(-48,-70,96,70);
  668. }else if(俺.name == "bird"){
  669. 俺.hero.y = -64;
  670. 俺.speedx = 14; //4
  671. 俺.rect = new LRectangle(-32,-32,64,32);
  672. }
  673. //俺.graphics.drawRect(2,"#ff0000",[俺.rect.x,俺.rect.y,俺.rect.width,俺.rect.height],true,"#880088");
  674. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  675. };
  676. 名人.prototype.心跳 = function(event){
  677. var 俺 = event.target;
  678. if(苦游戏主体.为停止()){
  679. if(俺.hero.mode != 0){
  680. 俺.hero.stop();
  681. }
  682. return;
  683. }else if(俺.hero.mode == 0){
  684. 俺.hero.play();
  685. }
  686. 俺.检查碰撞();
  687. 俺.y += 俺.vy;
  688. 俺.vy += 俺.苦值;
  689. 俺.x -= (常移步 + 俺.speedx);
  690. if(俺.vy <= 0)return;
  691. var checkList = 苦运行地图.childList,child;
  692. for(var i=0,l=checkList.length;i<l;i++){
  693. child = checkList[i];
  694. if(child.检查碰撞点(俺.x,俺.y)){
  695. 俺.y = child.y;
  696. 俺.vy = 0;
  697. break;
  698. }
  699. }
  700. };
  701. 名人.prototype.检查碰撞 = function(){
  702. var 俺 = this;
  703. if(俺.x < -96)return;
  704. if(苦运行角色.rect.action != 我.伤){
  705. var ix = (俺.x + 俺.rect.x) > (苦运行角色.x + 苦运行角色.rect.x) ? (俺.x + 俺.rect.x) : (苦运行角色.x + 苦运行角色.rect.x);
  706. var iy = (俺.y + 俺.rect.y) > (苦运行角色.y + 苦运行角色.rect.y) ? (俺.y + 俺.rect.y) : (苦运行角色.y + 苦运行角色.rect.y);
  707. var ax = (俺.x + 俺.rect.x + 俺.rect.width) > (苦运行角色.x + 苦运行角色.rect.x + 苦运行角色.rect.width) ? (苦运行角色.x + 苦运行角色.rect.x + 苦运行角色.rect.width) : (俺.x + 俺.rect.x + 俺.rect.width);
  708. var ay = (俺.y + 俺.rect.y + 俺.rect.height) > (苦运行角色.y + 苦运行角色.rect.y + 苦运行角色.rect.height) ? (苦运行角色.y + 苦运行角色.rect.y + 苦运行角色.rect.height) : (俺.y + 俺.rect.y + 俺.rect.height);
  709. if(ix <= ax && iy <= ay){
  710. if(苦运行角色.无敌()){
  711. 俺.removeEventListener(LEvent.ENTER_FRAME,俺.心跳);
  712. LTweenLite.to(俺,4,{y:Math.random()>0.5?-LGlobal.height:LGlobal.height*2,x:-200,ease:Elastic.easeOut});
  713. }else{
  714. 苦运行角色.伤();
  715. }
  716. }
  717. }
  718. };
  719. 名人.加 = function(floor){
  720. if(floor.isStart)return;
  721. var npc;
  722. var randNum = Math.random();
  723. if(randNum > 0.8){
  724. npc = new 名人("gui");
  725. npc.y = floor.y - 32;
  726. }else if(randNum > 0.6){
  727. npc = new 名人("bird");
  728. npc.y = floor.y - npc.getHeight();
  729. }else{
  730. 项.加(floor);
  731. }
  732. if(npc){
  733. npc.x = 48 + floor.x + (floor.getWidth() - 96)*Math.random();
  734. 苦名人层.addChild(npc);
  735. }
  736. };
  737. ///////////////////////////////////////
  738. function 项(name){
  739. base(this,LSprite,[]);
  740. this.初始(name);
  741. }
  742. 项.MODE_LIVE = "live";
  743. 项.MODE_GET = "get";
  744. 项.MODE_DELETE = "delete";
  745. 项.prototype.初始 = function(name){
  746. var 俺 = this;
  747. 俺.name = name;
  748. if(俺.name == "star"){
  749. 俺.bitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],32*9,32*3,32,32));
  750. }else if(俺.name == "speed"){
  751. 俺.bitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],32*14,32*3,40,48));
  752. 俺.bitmap.x = -1;
  753. 俺.bitmap.y = -8;
  754. }else if(俺.name == "solution"){
  755. 俺.bitmap = new LBitmap(new LBitmapData(苦数据列表["stage"],32*16,32*3,40,48));
  756. 俺.bitmap.x = -4;
  757. 俺.bitmap.y = -8;
  758. }
  759. 俺.mode = 项.MODE_LIVE;
  760. 俺.addChild(俺.bitmap);
  761. 俺.addEventListener(LEvent.ENTER_FRAME,俺.心跳);
  762. };
  763. 项.prototype.心跳 = function(event){
  764. var 俺 = event.target;
  765. if(苦游戏主体.为停止())return;
  766. if(俺.mode == 项.MODE_LIVE){
  767. 俺.检查碰撞();
  768. }
  769. 俺.x -= 常移步;
  770. };
  771. 项.prototype.检查碰撞 = function(){
  772. var 俺 = this;
  773. if(俺.x < -130)return;
  774. if(苦运行角色.rect.action != 我.伤){
  775. var ix = 俺.x > (苦运行角色.x + 苦运行角色.rect.x) ? 俺.x : (苦运行角色.x + 苦运行角色.rect.x);
  776. var iy = 俺.y > (苦运行角色.y + 苦运行角色.rect.y) ? 俺.y : (苦运行角色.y + 苦运行角色.rect.y);
  777. var ax = (俺.x + 32) > (苦运行角色.x + 苦运行角色.rect.x + 苦运行角色.rect.width) ? (苦运行角色.x + 苦运行角色.rect.x + 苦运行角色.rect.width) : (俺.x + 32);
  778. var ay = (俺.y + 32) > (苦运行角色.y + 苦运行角色.rect.y + 苦运行角色.rect.height) ? (苦运行角色.y + 苦运行角色.rect.y + 苦运行角色.rect.height) : (俺.y + 32);
  779. if(ix <= ax && iy <= ay){
  780. if(俺.name == "star"){
  781. 苦星控制.改值(1);
  782. }else if(俺.name == "speed"){
  783. 苦游戏主体.moveStepCount = 200;
  784. 苦游戏主体.speedBitmap.visible = true;
  785. 常移步 = 常移步快;
  786. }else if(俺.name == "solution"){
  787. 苦运行角色.hp.改值(20);
  788. }
  789. // MySoundPlayer.playSound("get");
  790. 俺.mode = 项.MODE_GET;
  791. LTweenLite.to(俺.bitmap,0.2,{y:-10,scaleX:0.1,alpha:0.75,ease:LEasing.None})
  792. .to(俺.bitmap,0.2,{y:-20,scaleX:1,alpha:0.5,ease:LEasing.None})
  793. .to(俺.bitmap,0.2,{y:-30,scaleX:0.1,alpha:0.25,ease:LEasing.None})
  794. .to(俺.bitmap,0.2,{y:-40,scaleX:1,alpha:0,ease:LEasing.None});
  795. }
  796. }
  797. };
  798. 项.加 = function(floor){
  799. var item,i;
  800. var randNum = Math.random();
  801. if(randNum > 0.7){
  802. return;
  803. }
  804. var maxnum = floor.getWidth()/32 >>> 0,addnum;
  805. if(maxnum > 5){
  806. addnum = 5 + ((maxnum - 5)*Math.random() >>> 0);
  807. }else{
  808. addnum = maxnum;
  809. }
  810. var sx = floor.x + (floor.getWidth() - addnum*32)*0.5;//路上出来的“心”★
  811. var specialItem = false;
  812. for(i=0;i<addnum;i++){
  813. if(i % 2 == 0)continue;
  814. randNum = Math.random();
  815. if(randNum > 0.95 && !specialItem){
  816. specialItem = true;
  817. item = new 项("speed");
  818. }else if(randNum > 0.9 && !specialItem){
  819. specialItem = true;
  820. item = new 项("solution");
  821. }else{
  822. item = new 项("star");
  823. }
  824. item.x = sx + i*32;
  825. item.y = floor.y - 32;
  826. 苦项目层.addChild(item);
  827. }
  828. };
  829. function 星(){
  830. base(this,LSprite,[]);
  831. this.初始();
  832. }
  833. 星.prototype.初始 = function(){
  834. var 俺 = this;
  835. var Star_bg = new LBitmap(new LBitmapData(苦数据列表["stage"],32*9,32*4,32*5,32));
  836. 俺.addChild(Star_bg);
  837. 俺.value = 0;
  838. 俺.maxValue = 50;
  839. 俺.Star_value = new LBitmap(new LBitmapData(苦数据列表["stage"],32*9,32*3,32*5,32));
  840. 俺.addChild(俺.Star_value);
  841. 俺.改值(49);
  842. };
  843. 星.prototype.改值 = function(value){
  844. var 俺 = this;
  845. 俺.value += value;
  846. 俺.Star_value.visible = true;
  847. if(俺.value < 0){
  848. 俺.value = 0;
  849. 俺.Star_value.visible = false;
  850. return;
  851. }else if(俺.value > 俺.maxValue){
  852. 俺.value = 俺.maxValue;
  853. }
  854. 俺.Star_value.bitmapData.setProperties(32*9,32*3,32*5*俺.value/俺.maxValue,32);
  855. if(俺.value == 俺.maxValue && !苦运行角色.无敌()){
  856. 苦运行角色.spiritCount = 4;
  857. 苦运行角色.hero.stop();
  858. 苦运行角色.心灵开始();
  859. }
  860. };
  861. ///////////////////////////////////////
  862. function 游戏结束(){
  863. base(this,LSprite,[]);
  864. this.初始();
  865. }
  866. 游戏结束.prototype.初始 = function(){
  867. var 俺 = this;
  868. 俺.overLayer = new LSprite();
  869. 俺.addChild(俺.overLayer);
  870. var windowBitmap = new LBitmap(new LBitmapData(苦数据列表["window"]));
  871. 俺.overLayer.addChild(windowBitmap);
  872. 俺.overLayer.x = (LGlobal.width - 俺.overLayer.getWidth())*0.5;
  873. 俺.overLayer.y = (LGlobal.height - 俺.overLayer.getHeight())*0.5;
  874. var 蚊游戏分 = new LTextField();
  875. 蚊游戏分.text = "勇气 : " + 苦运行角色.distanceObj.value;
  876. 蚊游戏分.color = "#FFFFFF";
  877. 蚊游戏分.size = 45;
  878. 蚊游戏分.weight = "bolder";
  879. 蚊游戏分.x = 210;
  880. 蚊游戏分.y = 120;
  881. 俺.overLayer.addChild(蚊游戏分);
  882. // updateShare(苦运行角色.distanceObj.value);
  883. // Play68.setRankingScoreDesc(苦运行角色.distanceObj.value);
  884. bgmusic.pause();
  885. var 豹再来 = new LButtonSample1("再来一次");
  886. 豹再来.x = 150;
  887. 豹再来.y = 650;
  888. 豹再来.width = 150;
  889. 豹再来.height = 60;
  890. 俺.overLayer.addChild(豹再来);
  891. 豹再来.addEventListener(LMouseEvent.MOUSE_UP, function(){
  892. 游戏开始();
  893. bgmusic.replay();
  894. });
  895. var more = new LButtonSample1("更多游戏");
  896. more.x = 350;
  897. more.y = 650;
  898. more.width = 150;
  899. more.height = 60;
  900. 俺.overLayer.addChild(more);
  901. more.addEventListener(LMouseEvent.MOUSE_UP, function(){
  902. clickMore();
  903. });
  904. };