CEndPanel.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. function CEndPanel(oSpriteBg) {
  2. var _oBg;
  3. var _oGroup;
  4. var _oMsgText1;
  5. var _oScoreText1;
  6. var _oButRestart;
  7. var _oButHome;
  8. this._init = function (oSpriteBg) {
  9. _oBg = createBitmap(oSpriteBg);
  10. _oBg.on("click", function () {});
  11. _oMsgText1 = new createjs.Text("", " 44px " + FONT2, "#fff");
  12. _oMsgText1.x = CANVAS_WIDTH / 2;
  13. _oMsgText1.y = (CANVAS_HEIGHT / 2) - 190;
  14. _oMsgText1.textAlign = "center";
  15. _oMsgText1.textBaseline = "alphabetic";
  16. _oMsgText1.lineHeight = 60;
  17. _oMsgText1.lineWidth = 450;
  18. _oScoreText1 = new createjs.Text("", " 40px " + FONT2, "#fff");
  19. _oScoreText1.x = CANVAS_WIDTH / 2;
  20. _oScoreText1.y = (CANVAS_HEIGHT / 2);
  21. _oScoreText1.textAlign = "center";
  22. _oScoreText1.textBaseline = "alphabetic";
  23. _oScoreText1.lineHeight = 60;
  24. _oScoreText1.lineWidth = 470;
  25. _oGroup = new createjs.Container();
  26. _oGroup.alpha = 0;
  27. _oGroup.visible = false;
  28. _oGroup.addChild(_oBg, _oScoreText1, _oMsgText1);
  29. var oSpriteRestart = s_oSpriteLibrary.getSprite('but_restart');
  30. _oButRestart = new CGfxButton(CANVAS_WIDTH / 2 + 170, CANVAS_HEIGHT_HALF + 160, oSpriteRestart, _oGroup);
  31. var oSpriteHome = s_oSpriteLibrary.getSprite('but_home');
  32. _oButHome = new CGfxButton(CANVAS_WIDTH / 2 - 170, CANVAS_HEIGHT_HALF + 160, oSpriteHome, _oGroup);
  33. s_oStage.addChild(_oGroup);
  34. };
  35. this.unload = function () {
  36. _oBg.off("click", function () {});
  37. createjs.Tween.get(_oGroup).to({alpha: 0}, 500).call(function () {
  38. _oButHome.unload();
  39. _oButRestart.unload();
  40. s_oStage.removeChild(_oGroup);
  41. });
  42. };
  43. this._initListener = function () {
  44. _oButHome.addEventListener(ON_MOUSE_UP, this._onExit, this);
  45. _oButRestart.addEventListener(ON_MOUSE_UP, this._onRestart, this);
  46. };
  47. this.show = function (iScore) {
  48. playSound("buzzer",1,false);
  49. _oMsgText1.text = TEXT_GAMEOVER;
  50. _oScoreText1.text = TEXT_SCORE + iScore;
  51. _oGroup.visible = true;
  52. var oParent = this;
  53. createjs.Tween.get(_oGroup).to({alpha: 1}, 500).call(function () {
  54. oParent._initListener();
  55. if (s_iAdsLevel === NUM_LEVEL_FOR_ADS) {
  56. $(s_oMain).trigger("show_interlevel_ad");
  57. s_iAdsLevel = 1;
  58. } else {
  59. s_iAdsLevel++;
  60. }
  61. });
  62. $(s_oMain).trigger("end_level", 1);
  63. $(s_oMain).trigger("share_event", iScore);
  64. $(s_oMain).trigger("save_score", iScore);
  65. };
  66. this._onRestart = function () {
  67. this.unload();
  68. s_oGame.resetGame();
  69. };
  70. this._onExit = function () {
  71. this.unload();
  72. s_oGame.onExit();
  73. };
  74. this._init(oSpriteBg);
  75. return this;
  76. }