index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. var placedata=["农坛","丰体","天安门","天坛","鸟巢","南锣鼓巷","北海","永定门","五道口","西单","宣武门","马甸","雍和宫","颐和园","圆明园"];
  2. var placepos=0;
  3. var Main = {};
  4. btGame.makePublisher(Main);
  5. // 舞台宽高
  6. Main.width = 720;
  7. Main.height = 950;
  8. // 地平线
  9. Main.floorLine = 850;
  10. // 路标间距
  11. Main.guideDistance = Main.width;
  12. Main.debug = false;
  13. // 角度
  14. Main.minAngle = 5;
  15. Main.maxAngle = 30;
  16. Main.randomAngle = 2; // 上下偏移角度
  17. // 掉落时间
  18. Main.fallingTime = 1100;
  19. // 速度
  20. Main.speed = 400;
  21. // 舞台可视距离
  22. Main.visibleDistance = 250;
  23. // 最高份
  24. Main.maxScore = (window.localStorage && +localStorage["zqdsMaxScore"]) || 0;
  25. // 帧频
  26. Main.fps = 40;
  27. var Resource;
  28. ;~function(res){
  29. // 资源加载
  30. res.load = function(){
  31. if(res.queue != null) return;
  32. res.queue = new createjs.LoadQueue(false);
  33. res.queue.addEventListener("progress",function(e) {
  34. //console.log(e);// 进度:e.loaded
  35. btGame.gameLoading(e.loaded);
  36. });
  37. res.queue.addEventListener("complete",function(e) {
  38. Main.log("完成", e);
  39. });
  40. res.queue.addEventListener("error",function(e) {
  41. btGame.gameLoading(0.1, e.text);
  42. });
  43. res.queue.loadFile("img/start.png");
  44. res.queue.loadFile("img/morebtn.png");
  45. res.queue.loadFile("img/startbtn.png");
  46. res.queue.loadFile("img/penguin.png");
  47. res.queue.loadFile("img/bear.png");
  48. res.queue.loadFile("img/hill.png");
  49. res.queue.loadFile("img/guide.png");
  50. res.queue.loadFile("img/background1.png");
  51. res.queue.loadFile("img/background2.png");
  52. res.queue.loadFile("img/flyend.png");
  53. res.queue.loadFile("img/traces.png");
  54. res.queue.loadFile("img/longtraces.png");
  55. res.queue.loadFile("img/score.png");
  56. res.queue.loadFile("img/fly.png");
  57. res.queue.loadFile("img/end.png");
  58. res.queue.loadFile("img/againbtn.png");
  59. res.queue.loadFile("img/notifybtn.png");
  60. }
  61. res.get = function(path){
  62. return res.queue.getResult(path);
  63. }
  64. }(Resource || (Resource = {}));
  65. Main.log = function(){
  66. Main.debug && console.log(arguments);
  67. }
  68. Main.shareTextMap = {
  69. "0": {
  70. tip: "没踢中,脚滑!再来一次~"
  71. ,title: "玩到了一个坑爹的游戏,不想砸手机就千万别来玩!"
  72. }
  73. ,"1": {
  74. tip: "没吃饱饭吗,用力用力!!"
  75. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  76. }
  77. ,"2": {
  78. tip: "哎呦,你真的吊炸天了!"
  79. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  80. }
  81. ,"3": {
  82. tip: "哇塞,你是大力神转世吧!"
  83. ,title: "我把企鹅打出了${m}米,击败了${n}%人,来挑战我吧!"
  84. },"4": {
  85. tip: "哎呦,你真的吊炸天了!"
  86. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  87. },"5": {
  88. tip: "哇塞,你是大力神转世吧!"
  89. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  90. },"6": {
  91. tip: "我去,超人也没你力量大,坏蛋!"
  92. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  93. },"7": {
  94. tip: "哼,你要把踢射出地球表面嘛?"
  95. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  96. },"8": {
  97. tip: "下手太狠了,快把伦家踢出地球!"
  98. ,title: "我把足球踢出了${m}米,击败了${n}%人,来挑战我吧!"
  99. }
  100. };
  101. Main.getShareText = function(distance){
  102. var i = 0, n = 0;
  103. if(distance > 0){
  104. i = 1;
  105. n = Math.floor(Math.random() * 11 + 30);
  106. }
  107. if(distance > 1000){
  108. i = 2;
  109. n = Math.floor(Math.random() * 9 + 40);
  110. }
  111. if(distance > 1500){
  112. i = 3;
  113. n = Math.floor(Math.random() * 9 + 50);
  114. }if(distance > 2000){
  115. i = 4;
  116. n = Math.floor(Math.random() * 9 + 60);
  117. }if(distance > 2500){
  118. i = 5;
  119. n = Math.floor(Math.random() * 9 + 70);
  120. }if(distance > 3000){
  121. i = 6;
  122. n = Math.floor(Math.random() * 9 + 80);
  123. }if(distance > 30000){
  124. i = 7;
  125. n = Math.floor(Math.random() * 5 + 90);
  126. }if(distance > 40000){
  127. i = 8;
  128. n = Math.floor(Math.random() * 9 + 90);
  129. }
  130. var share=Main.shareTextMap[i];
  131. return share;
  132. };
  133. // 游戏开始界面
  134. Main.startGame = function(){
  135. var container = new createjs.Container();
  136. container.addChild(new createjs.Bitmap(Resource.get("img/start.png")));
  137. // 开始游戏
  138. var beginGame = new createjs.Bitmap(Resource.get("img/startbtn.png"));
  139. beginGame.setTransform(34, 750);
  140. beginGame.cursor = "pointer";
  141. beginGame.addEventListener("click", function(){
  142. createjs.Tween.get(container, {loop: false})
  143. .to({alpha: 0}, 300)
  144. .call(function(){
  145. Main.initGame();
  146. });
  147. });
  148. container.addChild(beginGame);
  149. // 更多游戏
  150. var moreGame = new createjs.Bitmap(Resource.get("img/morebtn.png"));
  151. moreGame.setTransform(377, 750);
  152. moreGame.cursor = "pointer";
  153. moreGame.addEventListener("click", function(){
  154. dp_Ranking();
  155. });
  156. container.addChild(moreGame);
  157. Main.stage.addChild(container);
  158. }
  159. // 游戏结束界面
  160. Main.endGame = function(distance){
  161. if(!Main.endContainer){
  162. Main.endContainer = new createjs.Container();
  163. }else{
  164. Main.endContainer.removeAllEventListeners();
  165. Main.endContainer.removeAllChildren();
  166. }
  167. var container = Main.endContainer;
  168. container.alpha = 0;
  169. container.addChild(new createjs.Bitmap(Resource.get("img/end.png")));
  170. // 本次成绩
  171. var text1 = new createjs.Text(
  172. "本次距离: "+distance+" M", "bold 28pt Tahoma Helvetica Arial sans-serif", "#ffffff"
  173. );
  174. text1.textAlign = "center";
  175. text1.x = Main.width / 2;
  176. text1.y = 174;
  177. container.addChild(text1);
  178. var text2 = text1.clone(true);
  179. text2.text = "最远距离: " + Main.maxScore + " M";
  180. text2.y = 248;
  181. container.addChild(text2);
  182. var share = Main.getShareText(distance);
  183. var text3 = text1.clone(true);
  184. text3.text = share["tip"];
  185. text3.font = "bold 24pt Tahoma Helvetica Arial sans-serif";
  186. text3.textAlign = "center";
  187. text3.y = 394;
  188. container.addChild(text3);
  189. // 再来一次
  190. var again = new createjs.Bitmap(Resource.get("img/againbtn.png"));
  191. again.setTransform(35, 623);
  192. again.addEventListener("click", function(){
  193. placepos=0;
  194. createjs.Tween.get(container, {loop: false})
  195. .to({y: -Main.height, alpha: 0}, 500, createjs.Ease.quintInOut)
  196. .call(function(){
  197. container.alpha = 1;
  198. container.removeAllEventListeners();
  199. container.removeAllChildren();
  200. Main.reset.replay();
  201. });
  202. });
  203. container.addChild(again);
  204. // 通知好友
  205. var notify = new createjs.Bitmap(Resource.get("img/notifybtn.png"));
  206. notify.setTransform(376, 623);
  207. notify.addEventListener("click", function(){
  208. dp_share();
  209. });
  210. container.addChild(notify);
  211. // 更多游戏
  212. var more = new createjs.Shape();
  213. more.graphics.beginFill("#ffffff").drawRect(0, 0, Main.width, 60);
  214. more.alpha = 0.1;
  215. more.y = 870;
  216. more.addEventListener("click", function(){
  217. dp_Ranking();
  218. });
  219. container.addChild(more);
  220. Main.stage.addChild(container);
  221. container.y = -Main.height;
  222. createjs.Tween.get(container, {loop: false})
  223. .to({y:0, alpha:1}, 500, createjs.Ease.quintInOut);
  224. var pos=placepos-1;
  225. if(pos<0){
  226. pos=placedata.length-1;
  227. }
  228. dp_submitScore(distance,placedata[pos]);
  229. }
  230. Main.initStage = function(){
  231. // 舞台已经有了,就不用再初始化了
  232. if(!this.stage){
  233. Main.stage = new createjs.Stage("canvas");
  234. }
  235. // Main.stage.enableMouseOver();
  236. Main.stage.removeAllEventListeners();
  237. Main.stage.removeAllChildren();
  238. // 清空舞台
  239. Main.stage.removeAllChildren();
  240. Main.stage.removeAllEventListeners();
  241. // 舞台大小
  242. Main.stage.width = canvas.width = Main.width;
  243. Main.stage.height = canvas.height = Main.height;
  244. createjs.Ticker.addEventListener("tick", this.stage);
  245. // 先加载资源
  246. Resource.load();
  247. Resource.queue.addEventListener("complete", function(){
  248. // Main.startGame();
  249. Main.startGame();
  250. });
  251. };
  252. Main.initGame = function(){
  253. Main.initGame = function(){}; // 防止重复初始化
  254. Main.stage.enableMouseOver(true);
  255. Main.log("开始初始化游戏");
  256. Main.log("初始化:游戏背景");
  257. var img = new createjs.Container();
  258. img.setBounds(0, 0, Main.width * 2, Main.height);
  259. var b1 = new createjs.Bitmap(Resource.get("img/background2.png"));
  260. img.addChild(b1);
  261. b1 = new createjs.Bitmap(Resource.get("img/background2.png"));
  262. b1.x = Main.width;
  263. img.addChild(b1);
  264. b1 = new createjs.Bitmap(Resource.get("img/background1.png"));
  265. b1.x = Main.width * 2;
  266. img.addChild(b1);
  267. this.background = img;
  268. this.stage.addChild(img);
  269. this.reset.background(img);
  270. Main.log("初始化:北极熊");
  271. var bearImg = new createjs.Bitmap(Resource.get("img/bear.png"));
  272. var bearBound = bearImg.getBounds();
  273. var bearSS = new createjs.SpriteSheet({
  274. "framerate": 4
  275. ,"animations":{
  276. "normal": [0, 0]
  277. ,"prepare": [1, 2, false, 1.5]
  278. ,"shoot": {
  279. frames: [1, 3, 4, 5],
  280. next: false,
  281. speed: 5
  282. }
  283. ,"shootNull":{
  284. frames: [1, 3, 4, 0],
  285. next: false,
  286. speed: 2
  287. }
  288. },
  289. "images": [Resource.get("img/bear.png")],
  290. "frames":{
  291. "height": 360,
  292. "width":300,
  293. "regX": 0,
  294. "regY": 0,
  295. "count": 6
  296. }
  297. });
  298. var bear = new createjs.Sprite(bearSS);
  299. this.bear = bear;
  300. this.stage.addChild(bear);
  301. this.reset.bear();
  302. this.knockPoint = Math.ceil(bear.y + bearBound.height * 0.2);
  303. if(Main.debug){
  304. Main.log("计算击打点:" + this.knockPoint);
  305. var shape = new createjs.Shape();
  306. shape.graphics.beginFill("#ff0000").drawRect(0, 0, 50, 20);
  307. shape.x = this.width -200;
  308. shape.y = this.knockPoint;
  309. this.stage.addChild(shape);
  310. shape = null;
  311. // 地平线
  312. var floor = new createjs.Shape();
  313. floor.graphics.beginFill("#ffff00").drawRect(0, 0, Main.width, 10);
  314. floor.x = 0;
  315. floor.y = this.floorLine;
  316. this.stage.addChild(floor);
  317. floor = null;
  318. }
  319. // 回收熊的内存
  320. bearImg = bearBound = bearSS = bear = null;
  321. Main.log("初始化: 分数");
  322. var score = new createjs.Container();
  323. score.setBounds(0, 00, 138, 36);
  324. if(this.debug){
  325. var shape = new createjs.Shape();
  326. shape.graphics.beginFill("#fefefe").drawRect(
  327. 0, 0, score.getBounds().width, score.getBounds().height
  328. );
  329. score.addChild(shape);
  330. }
  331. var top = new createjs.Text("TOP:", "20px Arial Black", "#336600");
  332. score.addChild(top);
  333. var topWidth = top.getMeasuredWidth();
  334. var text = new createjs.Text("", "20px Arial Black", "#FF0000");
  335. text.x = topWidth+20;
  336. score.addChild(text);
  337. this.scoreTop = top;
  338. this.scoreText = text;
  339. this.score = score;
  340. this.stage.addChild(score);
  341. this.reset.score();
  342. score = top = text = null;
  343. // 路标
  344. Main.log("初始化:路标");
  345. var guideBackground = new createjs.Bitmap(Resource.get("img/guide.png"));
  346. var guideBackgroundHeight = guideBackground.getBounds().height;
  347. var guideBackgroundWidth = guideBackground.getBounds().width;
  348. var guideIcon = new createjs.Container();
  349. guideIcon.setBounds(guideBackground.getBounds());
  350. guideIcon.addChild(guideBackground);
  351. guideIcon.y = this.floorLine - guideBackgroundHeight - 20;
  352. var guideText = new createjs.Text("", "24px Arial Black", "#2B5580");
  353. guideText.y = 25;
  354. guideIcon.addChild(guideText);
  355. this.guideWidth = guideBackgroundWidth;
  356. this.guideHeight = guideBackgroundHeight;
  357. this.guideText = guideText;
  358. this.guide = guideIcon;
  359. this.stage.addChild(guideIcon);
  360. this.reset.guide("100M");
  361. Main.log("初始化:企鹅");
  362. var penguinImg = new createjs.Bitmap(Resource.get("img/penguin.png"));
  363. var penguinBound = penguinImg.getBounds();
  364. var penguinSS = new createjs.SpriteSheet({
  365. "framerate": 5
  366. ,"animations": {
  367. "normal": {
  368. frames:[0, 1, 0, 1, 2]
  369. ,next: false
  370. }
  371. ,"nod" : [2, 2, "normal"]
  372. ,"jump" : {
  373. frames: [2, 3, 4, 5]
  374. ,speed: 2
  375. ,next: false
  376. }
  377. }
  378. ,"images" : [Resource.get("img/penguin.png")]
  379. ,"frames" : {
  380. width: 180,
  381. height: 170,
  382. count: 6
  383. }
  384. });
  385. var penguin = new createjs.Sprite(penguinSS);
  386. this.penguin = penguin;
  387. this.penguinHeight = penguinBound.height;
  388. this.stage.addChild(penguin);
  389. this.reset.penguin();
  390. // 回收内存吧,少年!
  391. img = bound = null;
  392. Main.log("初始化:游戏结束的企鹅");
  393. var endData = {
  394. images: [Resource.get("img/flyend.png")],
  395. frames: {width:180, height:170, count: 2},
  396. animations: {slide:[0], down:[1]}
  397. };
  398. Main.gameOverPenguinSS = new createjs.SpriteSheet(endData);
  399. endData = null;
  400. // 结束的分数牌
  401. Main.log("初始化:游戏结束的分数牌");
  402. Main.gameOverScore = new createjs.Container();
  403. Main.gameOverScoreBg = new createjs.Bitmap(Resource.get("img/score.png"));
  404. Main.gameOverScore.addChild(Main.gameOverScoreBg);
  405. Main.gameOverScore.regY = Main.gameOverScoreBg.getBounds().height;
  406. Main.gameOverScoreText = new createjs.Text("0", "26px Arial Black", "#336600");
  407. Main.gameOverScoreText.x = 10;
  408. Main.gameOverScoreText.y = 13;
  409. Main.gameOverScore.addChild(Main.gameOverScoreText);
  410. Main.stage.addChild(Main.gameOverScore);
  411. Main.gameOverScore.x = 0;
  412. Main.gameOverScore.y = 0;
  413. Main.gameOverScore.cursor = "pointer";
  414. Main.reset.gameOverScore(1);
  415. // 事件绑定,htc 坑爹的速度
  416. setTimeout(function(){
  417. Main.initEvent();
  418. }, 200);
  419. };
  420. Main.gameOverSocreHd = {
  421. over: function(event){
  422. console.log(this.hover);
  423. }
  424. ,out: function(event){
  425. console.log(this.hover);
  426. }
  427. }
  428. // 重设状态
  429. Main.penguinOffsetX = 260;
  430. Main.reset = {
  431. replay: function(){
  432. this.guide("100M");
  433. this.score();
  434. this.penguin();
  435. this.bear();
  436. this.background();
  437. this.endPenguin(false);
  438. this.gameOverScore("0");
  439. placepos=0;
  440. // 游戏数据
  441. Main.penguinAnimation = null;
  442. Main.isPlaying = false; // 正在进行游戏
  443. Main.isQuiver = false;
  444. Main.guideMoveLength = 0;
  445. Main.guideMoveIndex = 1;
  446. Main.fire("replay");
  447. }
  448. ,guide: function(text){
  449. Main.guide.x = -Main.guideWidth;
  450. var guideText = Main.guideText;
  451. if(text){
  452. guideText.text = text;
  453. guideText.x = (Main.guideWidth - guideText.getMeasuredWidth()) / 2;
  454. }
  455. }
  456. ,score: function(txt){
  457. var text = Main.scoreText;
  458. var topWidth = Main.scoreTop.getMeasuredWidth(); // top 文字的宽度
  459. var maxWidth = Main.score.getBounds().width - topWidth;
  460. text.text = txt || (Main.maxScore + "M");
  461. var width = text.getMeasuredWidth();
  462. if(width >= maxWidth){
  463. text.x = topWidth;
  464. text.text = text.text.slice(0, -1);
  465. }else{
  466. text.x = topWidth + (maxWidth - width) / 2;
  467. }
  468. Main.score.x = 63;
  469. Main.score.y = 661;
  470. }
  471. ,gameOverScore: function(txt){
  472. var text = Main.gameOverScoreText;
  473. var offsetX = 11, width = 100;
  474. if(txt){
  475. text.text = txt;
  476. var textWidth = text.getMeasuredWidth();
  477. if(textWidth >= width){
  478. text.x = offsetX;
  479. }else{
  480. text.x = (width - textWidth) / 2 + offsetX;
  481. }
  482. }
  483. Main.gameOverScore.y = -Main.gameOverScore.getBounds().height;
  484. }
  485. ,penguin: function(){
  486. var penguin = Main.penguin;
  487. var bound = Main.penguin.getBounds();
  488. penguin.x = Main.width - Main.penguinOffsetX-10;
  489. penguin.y = 32;
  490. penguin.alpha = 1;
  491. penguin.rotation = 0;
  492. penguin.gotoAndPlay("normal");
  493. }
  494. ,bear: function(){
  495. var bear = Main.bear;
  496. var bound = bear.getBounds();
  497. bear.x = Main.width - 320;
  498. bear.y = 500;
  499. bear.gotoAndPlay("normal");
  500. }
  501. ,background: function(){
  502. var background = Main.background;
  503. Main.stopMoveStage();
  504. background.regX = 2 * Main.width;
  505. }
  506. ,endPenguin: function(visible){
  507. if(visible){
  508. if(!Main.gameOverPenguin){
  509. Main.gameOverPenguin = new createjs.Sprite(Main.gameOverPenguinSS);
  510. Main.stage.addChild(Main.gameOverPenguin);
  511. }
  512. Main.penguin.alpha = 0;
  513. Main.gameOverPenguin.alpha = 1;
  514. Main.gameOverPenguin.gotoAndPlay("down");
  515. Main.gameOverPenguin.x = Main.penguin.x;
  516. Main.gameOverPenguin.y = Main.penguin.y;
  517. }else{
  518. Main.penguin.alpha = 1;
  519. Main.gameOverPenguin && (Main.gameOverPenguin.alpha = 0);
  520. }
  521. }
  522. };
  523. Main.initEvent = function(){
  524. Main.clickTime = 0;
  525. this.stage.removeEventListener("stagemousedown", this.eventHandler.stageClick);
  526. this.stage.addEventListener("stagemousedown", this.eventHandler.stageClick);
  527. };
  528. var eventCD = false;
  529. Main.eventHandler = {
  530. stageClick: function(event){
  531. // 如果点击了游戏结束排
  532. // 三星坑爹的事件,重复触发了
  533. if(!eventCD){
  534. Main.fire("stageClick", Main.clickTime);
  535. eventCD = true;
  536. setTimeout(function(){
  537. eventCD = false;
  538. }, 500);
  539. }
  540. }
  541. };
  542. Main.penguinAnimation = null;
  543. Main.isPlaying = false; // 正在进行游戏
  544. Main.isQuiver = false; // 是否击中
  545. /* 事件处理 */
  546. Main.on("stageClick", function(clickTime){
  547. // 第一次点击:企鹅掉下来 + 白熊准备动作
  548. if(!Main.isPlaying){
  549. Main.isPlaying = true;
  550. // 重设场景
  551. this.reset.penguin();
  552. this.reset.bear();
  553. this.reset.background();
  554. this.reset.score();
  555. Main.log("白熊挥棒了!");
  556. Main.bear.gotoAndPlay("prepare");
  557. Main.log("企鹅跳下来吧~!");
  558. Main.penguin.gotoAndPlay("jump");
  559. var toY = Main.floorLine - Main.penguinHeight + 70;
  560. Main.penguinAnimation = createjs.Tween.get(this.penguin, {loop: false});
  561. Main.penguinAnimation.to({y: toY}, Main.fallingTime, createjs.Ease.quadIn)
  562. .call(function(){
  563. Main.fire("gameOver", 0);
  564. Main.log("掉下来了");
  565. });
  566. // 监听熊的挥棒动作
  567. Main.bearListenerShoot();
  568. }else if(!Main.penguinAnimation._paused){
  569. // 这里很诡异,没有检测 pause 的方法..
  570. var penguinY = this.penguin.y - this.penguin.regY;
  571. var clickX = Math.abs(this.knockPoint - penguinY);
  572. Main.isQuiver = clickX <= this.penguinHeight;
  573. // 击中了?
  574. if(Main.isQuiver){
  575. clickX = Math.ceil(clickX / this.penguinHeight * 100);
  576. var angle = Main.calculateAngle(clickX);
  577. Main.log("击中角度:" + angle);
  578. Main.fire("knockPenguin", angle);
  579. // 解除熊的监听
  580. Main.bearRemoveListenerShoot();
  581. }else{
  582. Main.log("你木有击中!!");
  583. }
  584. this.bear.gotoAndPlay("shoot");
  585. }
  586. });
  587. Main.bearListenerShoot = function(){
  588. this.bearRemoveListenerShoot();
  589. this.bear.addEventListener("animationend", Main.bearShoot);
  590. }
  591. Main.bearRemoveListenerShoot = function(){
  592. this.bear.removeEventListener("animationend", Main.bearShoot);
  593. }
  594. // 如果打不中,立刻回去准备
  595. Main.bearShoot = function(){
  596. if(!Main.isQuiver && Main.bear.currentAnimation == "shoot"){
  597. Main.bear.gotoAndPlay("prepare");
  598. }
  599. }
  600. Main.on("knockPenguin", function(event, angle){
  601. Main.penguinAnimation.setPaused(true);
  602. Main.flyLine(angle);
  603. });
  604. Main.on("moveStage", function(event, distance, totalDistance){
  605. Main.moveStage(distance, totalDistance);
  606. });
  607. Main._moveStage = function(distance, totalDistance){
  608. Main.moveStage = Main.moveStage2;
  609. Main.moveStage(distance, totalDistance);
  610. }
  611. Main.moveStage = Main._moveStage;
  612. Main.stopMoveStage = function(){
  613. // this.stage.removeEventListener("tick", testMoveStage);
  614. Main.moveStage = Main._moveStage;
  615. }
  616. // 2、熊、山都和背景,都往后挪,Main.visibleDistance距离左右,就不挪动了
  617. Main.moveStage2 = function(distance, totalDistance){
  618. if(this.background.regX > Main.width){
  619. this.bear.x += distance;
  620. this.score.x += distance;
  621. this.background.regX -= distance;
  622. Main.moveGuide(distance, totalDistance);
  623. }else{
  624. Main.moveStage = Main.moveStage3;
  625. // Main.guideMoveLength = Main.guideDistance + Main.guideWidth;
  626. Main.moveStage3(distance, totalDistance);
  627. // 添加1个路标
  628. // Main.tool.addNewGuide(totalDistance, 0);
  629. }
  630. }
  631. // 3、背景往后挪
  632. Main.moveStage3 = function(distance, totalDistance){
  633. this.background.regX -= distance;
  634. if(this.background.regX <= 0){
  635. this.background.regX += Main.width;
  636. }
  637. Main.moveGuide(distance, totalDistance);
  638. }
  639. // 路标
  640. Main.guideMoveLength = 0;
  641. Main.guideMoveIndex = 2;
  642. Main.moveGuide = function(distance, totalDistance){
  643. this.guide.x += distance;
  644. // 路标
  645. this.guideMoveLength += distance;
  646. if(this.guideMoveLength >= this.guideDistance + this.guideWidth){
  647. Main.guideMoveIndex++;
  648. var place=placedata[placepos];
  649. placepos=(placepos+1)%placedata.length;
  650. this.reset.guide(place+Main.guideMoveIndex + "00M");
  651. this.guideMoveLength = 0;
  652. }
  653. }
  654. Main.getTotalDistance = function(distance){
  655. Main.log(distance);
  656. var result = Main.guideMoveIndex * 100;
  657. var total = this.guideDistance + this.guideWidth;
  658. result += Math.round(Main.guide.x * total / Main.width) / 10;
  659. return distance > 0 ? result : 0;
  660. }
  661. Main.calculateAngle = function(x){
  662. Main.log("角度" + x);
  663. var y = Main.minAngle + Main.maxAngle * Math.sin(Math.PI * x / 200);
  664. y += Math.round(Math.random() * Main.randomAngle) * (Math.random() < 0.5 ? -1 : 1);
  665. return Math.ceil(y);
  666. }
  667. Main.gameOverScoreUtil = {
  668. dropDown: function(score, x){
  669. Main.reset.gameOverScore(score);
  670. Main.gameOverScore.x = x;
  671. createjs.Tween.get(Main.gameOverScore, {loop: false})
  672. .to({
  673. y: Main.floorLine - 60
  674. }, 800, createjs.Ease.quintIn);
  675. }
  676. };
  677. // 游戏结束
  678. Main.on("gameOver", function(event, distance, x){
  679. Main.log("游戏结束:" + Main.getTotalDistance(distance));
  680. var score = Main.getTotalDistance(distance);
  681. var hasNewMaxScore = score > Main.maxScore;
  682. Main.maxScore = Math.max(Main.maxScore, score);
  683. try{
  684. localStorage["zqdsMaxScore"] = Main.maxScore;
  685. }catch(e){
  686. }
  687. if(distance <= 0){
  688. Main.reset.endPenguin(true);
  689. Main.bear.gotoAndPlay("shootNull");
  690. //Main.gameOverScoreUtil.dropDown("0", Main.penguin.x + 50);
  691. }else{
  692. //Main.gameOverScoreUtil.dropDown(score, x);
  693. }
  694. setTimeout(function(){
  695. Main.endGame(score);
  696. }, 1200);
  697. });
  698. btGame.resizePlayArea($("#container"), Main.width, Main.height, "center", "center");
  699. Main.initStage();