Advertisement
Guest User

PauseMenuBlockRunner.js

a guest
Apr 24th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. var INIT_PAUSE = false;
  2.  
  3. var PauseMenu = cc.Layer.extend
  4. ({
  5. resumeBtn:null,
  6. quitBtn:null,
  7. restartBtn:null,
  8. pauseStr:null,
  9. sfxBtn:null,
  10. musicBtn:null,
  11. isResumed:false,
  12. playerRef:null,
  13.  
  14. ctor:function (player)
  15. {
  16. this._super();
  17.  
  18. this.playerRef = player;
  19.  
  20. var whiteBg = cc.LayerColor.create(new cc.Color(128,128,128,160));
  21. this.addChild(whiteBg);
  22.  
  23. var bg = new cc.Sprite("#PauseBg.png");
  24. bg.x = cc.winSize.width * 0.5;
  25. bg.y = cc.winSize.height * 0.5;
  26. bg.setScale(GameVars.scaleFactor);
  27. this.addChild(bg);
  28.  
  29. this.restartBtn = new ccui.Button("BigBtn.png","BigBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
  30. this.restartBtn.x = cc.winSize.width * 0.5;
  31. this.restartBtn.y = cc.winSize.height * 0.74;
  32. this.restartBtn.setScale(GameVars.scaleFactor);
  33. this.restartBtn.addTouchEventListener(this.touchResume, this);
  34. this.addChild(this.restartBtn);
  35.  
  36. var restStr = new cc.LabelBMFont("Resume", res.menuFont_ttf);
  37. restStr.setScale(0.4 * GameVars.scaleFactor,0.4 * GameVars.scaleFactor)
  38. restStr.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.74));
  39. restStr.color = cc.color.RED;
  40. this.addChild(restStr);
  41.  
  42. this.resumeBtn = new ccui.Button("BigBtn.png","BigBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
  43. this.resumeBtn.x = cc.winSize.width * 0.5;
  44. this.resumeBtn.y = cc.winSize.height * 0.55;
  45. this.resumeBtn.setScale(GameVars.scaleFactor);
  46. this.resumeBtn.addTouchEventListener(this.touchRestart, this);
  47. this.addChild(this.resumeBtn);
  48.  
  49. var resStr = new cc.LabelBMFont("Restart", res.menuFont_ttf);
  50. resStr.setScale(0.4 * GameVars.scaleFactor,0.4 * GameVars.scaleFactor)
  51. resStr.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.55));
  52. resStr.color = cc.color.RED;
  53. this.addChild(resStr);
  54.  
  55. this.quitBtn = new ccui.Button("BigBtn.png","BigBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
  56. this.quitBtn.x = cc.winSize.width * 0.5;
  57. this.quitBtn.y = cc.winSize.height * 0.35;
  58. this.quitBtn.setScale(GameVars.scaleFactor);
  59. this.quitBtn.addTouchEventListener(this.touchQuit, this);
  60. this.addChild(this.quitBtn);
  61.  
  62. this.pauseStr = new cc.LabelBMFont("Quit", res.menuFont_ttf);
  63. this.pauseStr.setScale(0.4 * GameVars.scaleFactor,0.4 * GameVars.scaleFactor)
  64. this.pauseStr.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.35));
  65. this.pauseStr.color = cc.color.RED;
  66. this.addChild(this.pauseStr);
  67.  
  68. var title = new cc.LabelBMFont("Pause", res.menuFont_ttf);
  69. title.setScale(0.6 * GameVars.scaleFactor,0.6 * GameVars.scaleFactor)
  70. if(GameVars.scaleFactor == 1)
  71. title.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.93));
  72. else if(GameVars.scaleFactor == 2)
  73. title.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.86));
  74. title.color = cc.color.RED;
  75. this.addChild(title);
  76.  
  77. var sfx = new cc.LabelBMFont("SFX", res.menuFont_ttf);
  78. sfx.setScale(0.4 * GameVars.scaleFactor,0.4 * GameVars.scaleFactor)
  79. sfx.setPosition(cc.p(cc.winSize.width * 0.42, cc.winSize.height * 0.22));
  80. sfx.color = cc.color.RED;
  81. this.addChild(sfx);
  82.  
  83. this.sfxBtn = new ccui.Button();
  84. if(GameVars.sfxOn)
  85. this.sfxBtn.loadTextures(res.onBtn_png, res.onBtn_png);
  86. else if (GameVars.sfxOn == false)
  87. {
  88. this.sfxBtn.loadTextures(res.offBtn_png, res.offBtn_png);
  89. }
  90. this.sfxBtn.x = cc.winSize.width * 0.42;
  91. this.sfxBtn.y = cc.winSize.height * 0.15;
  92. this.sfxBtn.addTouchEventListener(this.sfxOff, this);
  93. this.addChild(this.sfxBtn);
  94.  
  95. var music = new cc.LabelBMFont("Music", res.menuFont_ttf);
  96. music.setScale(0.4 * GameVars.scaleFactor,0.4 * GameVars.scaleFactor)
  97. music.setPosition(cc.p(cc.winSize.width * 0.55, cc.winSize.height * 0.22));
  98. music.color = cc.color.RED;
  99. this.addChild(music);
  100.  
  101. this.musicBtn = new ccui.Button();
  102. if(GameVars.musicOn)
  103. this.musicBtn.loadTextures(res.onBtn_png, res.onBtn_png);
  104. else if (GameVars.musicOn == false)
  105. {
  106. this.musicBtn.loadTextures(res.offBtn_png, res.offBtn_png);
  107. }
  108. this.musicBtn.x = cc.winSize.width * 0.55;
  109. this.musicBtn.y = cc.winSize.height * 0.15;
  110. this.musicBtn.addTouchEventListener(this.musicOff, this);
  111. this.addChild(this.musicBtn);
  112. },
  113.  
  114. musicOff:function(sender,type)
  115. {
  116. switch (type)
  117. {
  118. case ccui.Widget.TOUCH_ENDED:
  119. cc.audioEngine.playEffect(res.buttonClick_mp3);
  120. if(GameVars.musicOn)
  121. {
  122. this.musicBtn.loadTextures(res.offBtn_png, res.offBtn_png);
  123. cc.audioEngine.setMusicVolume(0);
  124. GameVars.musicVol = 0;
  125. GameVars.musicOn = false;
  126. }
  127. else if(GameVars.musicOn == false)
  128. {
  129. this.musicBtn.loadTextures(res.onBtn_png, res.onBtn_png);
  130. GameVars.musicOn = true;
  131. cc.audioEngine.setMusicVolume(100);
  132. GameVars.musicVol = 100;
  133. }
  134. break;
  135.  
  136. break;
  137. }
  138. },
  139.  
  140. sfxOff:function(sender,type)
  141. {
  142. switch (type)
  143. {
  144. case ccui.Widget.TOUCH_ENDED:
  145. cc.audioEngine.playEffect(res.buttonClick_mp3);
  146. if(GameVars.sfxOn)
  147. {
  148. this.sfxBtn.loadTextures(res.offBtn_png, res.offBtn_png);
  149. cc.audioEngine.setEffectsVolume(0);
  150. GameVars.sfxVol = 0;
  151. GameVars.sfxOn = false;
  152. }
  153. else if(GameVars.sfxOn == false)
  154. {
  155. this.sfxBtn.loadTextures(res.onBtn_png, res.onBtn_png);
  156. GameVars.sfxOn = true;
  157. cc.audioEngine.setEffectsVolume(100);
  158. GameVars.sfxVol = 100;
  159. }
  160. break;
  161.  
  162. break;
  163. }
  164. },
  165.  
  166. touchRestart: function(sender, type)
  167. {
  168.  
  169. INIT_END = false;
  170.  
  171. switch (type)
  172. {
  173. case ccui.Widget.TOUCH_ENDED:
  174. switch(GameVars.currLevel)
  175. {
  176. case 0:
  177. INIT_TUT = false;
  178. this.playerRef.moveForCollision();
  179. cc.director.resume();
  180. GameVars.touchRestart = true;
  181. cc.audioEngine.playEffect(res.buttonClick_mp3);
  182. cc.director.runScene(new cc.TransitionFade(1.5, new tutScene()));
  183. break;
  184. case 1:
  185. INIT_GAME = false;
  186. this.playerRef.moveForCollision();
  187. cc.director.resume();
  188. GameVars.touchRestart = true;
  189. cc.audioEngine.playEffect(res.buttonClick_mp3);
  190. cc.director.runScene(new gameScene())
  191. break;
  192. case 2:
  193. INIT_LEVEL2 = false;
  194. this.playerRef.moveForCollision();
  195. cc.director.resume();
  196. GameVars.touchRestart = true;
  197. cc.audioEngine.playEffect(res.buttonClick_mp3);
  198. cc.director.runScene(new gameSceneLvl2())
  199. break;
  200. case 3:
  201. INIT_LEVEL3 = false;
  202. this.playerRef.moveForCollision();
  203. GameVars.isAccelLvl = false;
  204. cc.director.resume();
  205. cc.audioEngine.playEffect(res.buttonClick_mp3);
  206. cc.director.runScene(new gameSceneLvl3());
  207. break;
  208. case 4:
  209. INIT_LEVEL4 = false;
  210. this.playerRef.moveForCollision();
  211. GameVars.isAccelLvl = false;
  212. cc.director.resume();
  213. cc.audioEngine.playEffect(res.buttonClick_mp3);
  214. cc.director.runScene(new gameSceneLvl4());
  215. break;
  216. case 5:
  217. INIT_LEVEL5 = false;
  218. cc.director.resume();
  219. this.playerRef.moveForCollision();
  220. GameVars.isAccelLvl = false;
  221. cc.audioEngine.playEffect(res.buttonClick_mp3);
  222. cc.director.runScene(new gameSceneLvl5());
  223. break;
  224. }
  225. break;
  226.  
  227. break;
  228. }
  229. },
  230.  
  231. touchResume: function(sender, type)
  232. {
  233. switch (type)
  234. {
  235. case ccui.Widget.TOUCH_ENDED:
  236. cc.audioEngine.playEffect(res.buttonClick_mp3);
  237. this.isResumed = true;
  238. this.resume();
  239. break;
  240.  
  241. break;
  242. }
  243. },
  244.  
  245. touchQuit: function(sender, type)
  246. {
  247. switch (type)
  248. {
  249. case ccui.Widget.TOUCH_ENDED:
  250. cc.audioEngine.playEffect(res.buttonClick_mp3);
  251. cc.audioEngine.stopMusic();
  252. cc.audioEngine.playMusic(res.menuMusic_mp3, false);
  253. this.onQuitPressed();
  254. break;
  255.  
  256. break;
  257. }
  258. },
  259.  
  260. resume:function()
  261. {
  262. INIT_PAUSE = false;
  263. this.visible = false;
  264. cc.director.resume();
  265. },
  266.  
  267. onQuitPressed:function()
  268. {
  269. GameVars.isAccelLvl = false;
  270. cc.director.resume();
  271. INIT_GAME = false;
  272. INIT_TUT = false;
  273. cc.director.runScene(new cc.TransitionFade(1.5, new MainMenuScene()));
  274. },
  275. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement