CGameOver.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. function CGameOver(oSpriteBg, iScore, iLevel, iLines) {
  2. var _oGroup;
  3. var _oGroupMsgBox;
  4. var _oBg;
  5. var _oFade;
  6. var _oButMenu;
  7. var _oButRestart;
  8. this._init = function (oSpriteBg, iScore, iLevel, iLines) {
  9. s_oGame.setPause(true);
  10. _oGroup = new createjs.Container();
  11. _oGroupMsgBox = new createjs.Container();
  12. _oGroupMsgBox.y = -CANVAS_WIDTH_HALF - oSpriteBg.width * 0.5;
  13. _oBg = createBitmap(oSpriteBg);
  14. _oBg.x = CANVAS_WIDTH * 0.5;
  15. _oBg.y = CANVAS_HEIGHT * 0.5;
  16. _oBg.regX = oSpriteBg.width * 0.5;
  17. _oBg.regY = oSpriteBg.height * 0.5;
  18. _oGroupMsgBox.addChild(_oBg);
  19. _oFade = new createjs.Shape();
  20. _oFade.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
  21. _oFade.alpha = 0;
  22. _oFade.on("click", function () {});
  23. _oGroup.addChild(_oFade);
  24. var pGameOverPos = {x: CANVAS_WIDTH * 0.5, y: CANVAS_HEIGHT * 0.5 - 75};
  25. var iSizeFont = 40;
  26. var iSizeFontGameOver = 60;
  27. var oTextLevel;
  28. var oTextLevelStruct;
  29. var oTextLines;
  30. var oTextLinesStruct;
  31. var oTextGameOverScore;
  32. var oTextGameOverScoreStruct;
  33. var oTextTitle;
  34. var oTextTitleStruct;
  35. oTextTitleStruct = new CTLText(_oGroupMsgBox,
  36. pGameOverPos.x-300, pGameOverPos.y - 150, 600, iSizeFontGameOver,
  37. iSizeFontGameOver, "center", "#0025c2", PRIMARY_FONT, 1,
  38. 0, 0,
  39. TEXT_GAMEOVER,
  40. true, true, false,
  41. false );
  42. oTextTitleStruct.setOutline(OUTLINE_TEXT);
  43. oTextTitle = new CTLText(_oGroupMsgBox,
  44. pGameOverPos.x-300, pGameOverPos.y-150, 600, iSizeFontGameOver,
  45. iSizeFontGameOver, "center", "#ffd800", PRIMARY_FONT, 1,
  46. 0, 0,
  47. TEXT_GAMEOVER,
  48. true, true, false,
  49. false );
  50. oTextLevelStruct = new CTLText(_oGroupMsgBox,
  51. pGameOverPos.x-300, pGameOverPos.y-25 , 250, iSizeFont*2,
  52. iSizeFont, "center", "#025cce", PRIMARY_FONT, 1,
  53. 0, 0,
  54. TEXT_LEVEL + "\n" + iLevel,
  55. true, true, true,
  56. false );
  57. oTextLevelStruct.setOutline(OUTLINE_TEXT);
  58. oTextLevel = new CTLText(_oGroupMsgBox,
  59. pGameOverPos.x-300, pGameOverPos.y-25, 250, iSizeFont*2,
  60. iSizeFont, "center", "#ffd800", PRIMARY_FONT, 1,
  61. 0, 0,
  62. TEXT_LEVEL + "\n" + iLevel,
  63. true, true, true,
  64. false );
  65. oTextLinesStruct = new CTLText(_oGroupMsgBox,
  66. pGameOverPos.x+50, pGameOverPos.y -25, 250, iSizeFont*2,
  67. iSizeFont, "center", "#025cce", PRIMARY_FONT, 1,
  68. 0, 0,
  69. TEXT_LINES + "\n" + iLines,
  70. true, true, true,
  71. false );
  72. oTextLinesStruct.setOutline(OUTLINE_TEXT);
  73. oTextLines = new CTLText(_oGroupMsgBox,
  74. pGameOverPos.x+50, pGameOverPos.y -25, 250, iSizeFont*2,
  75. iSizeFont, "center", "#ffd800", PRIMARY_FONT, 1,
  76. 0, 0,
  77. TEXT_LINES + "\n" + iLines,
  78. true, true, true,
  79. false );
  80. oTextGameOverScoreStruct = new CTLText(_oGroupMsgBox,
  81. pGameOverPos.x-150, pGameOverPos.y +100, 300, iSizeFont*3,
  82. iSizeFont, "center", "#025cce", PRIMARY_FONT, 1,
  83. 0, 0,
  84. TEXT_SCORE_GAMEOVER + "\n\n" + iScore,
  85. true, true, true,
  86. false );
  87. oTextGameOverScoreStruct.setOutline(4);
  88. oTextGameOverScore = new CTLText(_oGroupMsgBox,
  89. pGameOverPos.x-150, pGameOverPos.y +100, 300, iSizeFont*3,
  90. iSizeFont, "center", "#ffd800", PRIMARY_FONT, 1,
  91. 0, 0,
  92. TEXT_SCORE_GAMEOVER + "\n\n" + iScore,
  93. true, true, true,
  94. false );
  95. _oGroup.addChild(_oGroupMsgBox);
  96. s_oStage.addChild(_oGroup);
  97. var oSpriteRestart = s_oSpriteLibrary.getSprite("but_restart");
  98. var oSpriteHome = s_oSpriteLibrary.getSprite("but_home");
  99. _oButMenu = new CGfxButton((CANVAS_WIDTH / 2 - 250), CANVAS_HEIGHT / 2 + 150, oSpriteHome, _oGroupMsgBox);
  100. _oButMenu.addEventListener(ON_MOUSE_UP, this._onMenu, this);
  101. _oButRestart = new CGfxButton((CANVAS_WIDTH / 2 + 250), CANVAS_HEIGHT / 2 + 150, oSpriteRestart, _oGroupMsgBox);
  102. _oButRestart.addEventListener(ON_MOUSE_UP, this._onRestart, this);
  103. _oButRestart.pulseAnimation();
  104. createjs.Tween.get(_oFade).to({alpha: 0.5}, 750, createjs.Ease.cubicOut);
  105. createjs.Tween.get(_oGroupMsgBox).to({y: 0}, 1500, createjs.Ease.bounceOut).call(function () {
  106. if (s_iAdsLevel === NUM_LEVEL_FOR_ADS) {
  107. $(s_oMain).trigger("show_interlevel_ad");
  108. s_iAdsLevel = 1;
  109. } else {
  110. s_iAdsLevel++;
  111. }
  112. });
  113. $(s_oMain).trigger("save_score", iScore);
  114. $(s_oMain).trigger("share_event", iScore);
  115. };
  116. this.unload = function () {
  117. _oFade.off("click", function () {});
  118. if (_oButMenu) {
  119. _oButMenu.unload();
  120. _oButMenu = null;
  121. }
  122. s_oStage.removeChild(_oGroup);
  123. };
  124. this._onMenu = function () {
  125. this.unload();
  126. s_oInterface._onButMenuRelease();
  127. };
  128. this._onRestart = function () {
  129. this.unload();
  130. s_oInterface._onButRestartLevelRelease();
  131. };
  132. this._init(oSpriteBg, iScore, iLevel, iLines);
  133. return this;
  134. }