CEndPanel.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function CEndPanel(oSpriteBg) {
  2. var _oBg;
  3. var _oGroup;
  4. var _oFade;
  5. var _oMsgText1;
  6. var _oScoreText1;
  7. var _oButRestart;
  8. var _oButHome;
  9. var _oListener;
  10. this._init = function (oSpriteBg) {
  11. _oFade = new createjs.Shape();
  12. _oFade.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
  13. _oFade.alpha = 0.7;
  14. _oListener = _oFade.on("click", function(){});
  15. _oBg = createBitmap(oSpriteBg);
  16. _oBg.x = CANVAS_WIDTH_HALF;
  17. _oBg.y = CANVAS_HEIGHT_HALF + 95;
  18. _oBg.regX = oSpriteBg.width * 0.5;
  19. _oBg.regY = oSpriteBg.height * 0.5;
  20. _oFade.on("click", function () {}, null, true);
  21. _oMsgText1 = new createjs.Text("", "72px " + SECONDARY_FONT, "#fff");
  22. _oMsgText1.x = CANVAS_WIDTH / 2;
  23. _oMsgText1.y = (CANVAS_HEIGHT / 2) - 50;
  24. _oMsgText1.textAlign = "center";
  25. _oMsgText1.textBaseline = "alphabetic";
  26. _oMsgText1.lineHeight = 60;
  27. _oMsgText1.lineWidth = 450;
  28. _oScoreText1 = new createjs.Text("", "45px " + SECONDARY_FONT, "#fff");
  29. _oScoreText1.x = CANVAS_WIDTH / 2;
  30. _oScoreText1.y = (CANVAS_HEIGHT / 2) + 30;
  31. _oScoreText1.textAlign = "center";
  32. _oScoreText1.textBaseline = "alphabetic";
  33. _oScoreText1.lineHeight = 60;
  34. _oScoreText1.lineWidth = 470;
  35. _oGroup = new createjs.Container();
  36. _oGroup.alpha = 0;
  37. _oGroup.visible = false;
  38. _oGroup.addChild(_oFade, _oBg, _oScoreText1, _oMsgText1);
  39. var oSpriteRestart = s_oSpriteLibrary.getSprite('but_restart');
  40. _oButRestart = new CGfxButton(CANVAS_WIDTH / 2 + 170, CANVAS_HEIGHT_HALF + 120, oSpriteRestart, _oGroup);
  41. var oSpriteHome = s_oSpriteLibrary.getSprite('but_home');
  42. _oButHome = new CGfxButton(CANVAS_WIDTH / 2 - 170, CANVAS_HEIGHT_HALF + 120, oSpriteHome, _oGroup);
  43. s_oStage.addChild(_oGroup);
  44. };
  45. this.unload = function () {
  46. _oFade.off("click", _oListener);
  47. createjs.Tween.get(_oGroup).to({alpha: 0}, 500).call(function () {
  48. _oButHome.unload();
  49. _oButRestart.unload();
  50. s_oStage.removeChild(_oGroup);
  51. });
  52. };
  53. this._initListener = function () {
  54. _oButHome.addEventListener(ON_MOUSE_UP, this._onExit, this);
  55. _oButRestart.addEventListener(ON_MOUSE_UP, this._onRestart, this);
  56. };
  57. this.show = function (iScore) {
  58. if(iScore<300){
  59. _oMsgText1.text = TEXT_GAMEOVER;
  60. } else {
  61. _oMsgText1.text = TEXT_PERFECT;
  62. }
  63. _oScoreText1.text = TEXT_SCORE + ": " + iScore;
  64. _oGroup.visible = true;
  65. var oParent = this;
  66. createjs.Tween.get(_oGroup).to({alpha: 1}, 500).call(function () {
  67. oParent._initListener();
  68. if (s_iAdsLevel === NUM_LEVEL_FOR_ADS) {
  69. $(s_oMain).trigger("show_interlevel_ad");
  70. s_iAdsLevel = 1;
  71. } else {
  72. s_iAdsLevel++;
  73. }
  74. });
  75. $(s_oMain).trigger("share_event", iScore);
  76. $(s_oMain).trigger("save_score", iScore);
  77. };
  78. this._onRestart = function () {
  79. this.unload();
  80. s_oGame.restartGame();
  81. };
  82. this._onExit = function () {
  83. this.unload();
  84. s_oGame.onExit();
  85. };
  86. this._init(oSpriteBg);
  87. return this;
  88. }