menu.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. var menu1, menu2, menu3, menu4;
  2. var m_info, m_world, m_menu, m_back, m_help, m_audio;
  3. var lbl_game;
  4. /*
  5. var menuState = {
  6. create: function(){},
  7. loadGame: function(){},
  8. ---------------------------- end of phaser functions
  9. showTitle: function(){},
  10. clearTitle: function(){},
  11. loadState: function(){}
  12. }
  13. */
  14. var menuState = {
  15. // game menu screen
  16. create: function() {
  17. // Creating sound variable
  18. beepSound = game.add.audio('sound_beep');
  19. // Reading dictionary
  20. lang = game.cache.getJSON('dictionary');
  21. // Title
  22. var style = { font: "32px Arial", fill: "#00804d", align: "center" };
  23. var title = game.add.text(this.game.world.centerX, 80, lang.menu_title, style);
  24. title.anchor.setTo(0.5,0.5);
  25. // Subtitle : game mode
  26. var style_game = { font: "27px Arial", fill: "#003cb3", align: "center" };
  27. lbl_game = game.add.text(this.game.world.centerX, 110, "", style_game);
  28. lbl_game.anchor.setTo(0.5,0.5);
  29. var player_info = game.add.text(this.game.world.centerX, 40, lang.welcome + ", " + username + "!", { font: "20px Arial", fill: "#330000", align: "center" });
  30. player_info.anchor.setTo(0.5,0.5);
  31. // Menu options
  32. //information label
  33. m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
  34. m_info_right.anchor.setTo(1,0.02);
  35. // Return to language button
  36. m_world = game.add.sprite(game.world.width - 120, 10, 'world');
  37. m_world.inputEnabled = true;
  38. m_world.input.useHandCursor = true;
  39. m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
  40. m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
  41. m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
  42. m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
  43. audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
  44. m_audio.inputEnabled = true;
  45. m_audio.input.useHandCursor = true;
  46. m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
  47. m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
  48. m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
  49. //game buttons
  50. // loading button sprites
  51. menu1 = game.add.sprite(this.game.world.centerX + 10, this.game.world.centerY - 70, 'game1c');
  52. menu2 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY - 70, 'game2c');
  53. menu3 = game.add.sprite(this.game.world.centerX + 10, this.game.world.centerY + 90, 'game3c');
  54. menu4 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY + 90, 'game4c');
  55. menu5 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY - 70, 'game1s');
  56. menu6 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY - 70, 'game2s');
  57. menu7 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY + 90, 'game3s');
  58. menu8 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY + 90, 'game4s');
  59. menu9 = game.add.sprite(this.game.world.centerX + 350, this.game.world.centerY -70, 'game5s');
  60. // button actions
  61. menu1.anchor.setTo(0.5, 0.5);
  62. menu1.inputEnabled = true;
  63. menu1.input.useHandCursor = true;
  64. menu1.events.onInputDown.add(this.loadGame,{num:1, beep: beepSound, shape : "Circle", label : true});
  65. menu1.events.onInputOver.add(this.showTitle,{num:1, beep: beepSound, shape : "Circle", label : true});
  66. menu1.events.onInputOut.add(this.clearTitle);
  67. menu2.anchor.setTo(0.5, 0.5);
  68. menu2.inputEnabled = true;
  69. menu2.input.useHandCursor = true;
  70. menu2.events.onInputDown.add(this.loadGame,{num:2, beep: beepSound, shape : "Circle", label : false});
  71. menu2.events.onInputOver.add(this.showTitle,{num:2, beep: beepSound, shape : "Circle", label : false});
  72. menu2.events.onInputOut.add(this.clearTitle);
  73. menu3.anchor.setTo(0.5, 0.5);
  74. menu3.inputEnabled = true;
  75. menu3.input.useHandCursor = true;
  76. menu3.events.onInputDown.add(this.loadGame,{num:3, beep: beepSound, shape : "Circle", label : true});
  77. menu3.events.onInputOver.add(this.showTitle,{num:3, beep: beepSound, shape : "Circle", label : true});
  78. menu3.events.onInputOut.add(this.clearTitle);
  79. menu4.anchor.setTo(0.5, 0.5);
  80. menu4.inputEnabled = true;
  81. menu4.input.useHandCursor = true;
  82. menu4.events.onInputDown.add(this.loadGame,{num:4, beep: beepSound, shape : "Circle", label : false});
  83. menu4.events.onInputOver.add(this.showTitle,{num:4, beep: beepSound, shape : "Circle", label : false});
  84. menu4.events.onInputOut.add(this.clearTitle);
  85. menu5.anchor.setTo(0.5, 0.5);
  86. menu5.inputEnabled = true;
  87. menu5.input.useHandCursor = true;
  88. menu5.events.onInputDown.add(this.loadGame,{num:1, beep: beepSound, shape : "Square", label : true});
  89. menu5.events.onInputOver.add(this.showTitle,{num:1, beep: beepSound, shape : "Square", label : true});
  90. menu5.events.onInputOut.add(this.clearTitle);
  91. menu6.anchor.setTo(0.5, 0.5);
  92. menu6.inputEnabled = true;
  93. menu6.input.useHandCursor = true;
  94. menu6.events.onInputDown.add(this.loadGame,{num:2, beep: beepSound, shape : "Square", label : false});
  95. menu6.events.onInputOver.add(this.showTitle,{num:2, beep: beepSound, shape : "Square", label : false});
  96. menu6.events.onInputOut.add(this.clearTitle);
  97. menu7.anchor.setTo(0.5, 0.5);
  98. menu7.inputEnabled = true;
  99. menu7.input.useHandCursor = true;
  100. menu7.events.onInputDown.add(this.loadGame,{num:3, beep: beepSound, shape : "Square", label : true});
  101. menu7.events.onInputOver.add(this.showTitle,{num:3, beep: beepSound, shape : "Square", label : true});
  102. menu7.events.onInputOut.add(this.clearTitle);
  103. menu8.anchor.setTo(0.5, 0.5);
  104. menu8.inputEnabled = true;
  105. menu8.input.useHandCursor = true;
  106. menu8.events.onInputDown.add(this.loadGame,{num:4, beep: beepSound, shape : "Square", label : false});
  107. menu8.events.onInputOver.add(this.showTitle,{num:4, beep: beepSound, shape : "Square", label : false});
  108. menu8.events.onInputOut.add(this.clearTitle);
  109. menu9.anchor.setTo(0.5, 0.5);
  110. menu9.inputEnabled = true;
  111. menu9.input.useHandCursor = true;
  112. menu9.events.onInputDown.add(this.loadGame,{num:5, beep: beepSound, shape : "Square", label : false});
  113. menu9.events.onInputOver.add(this.showTitle,{num:5, beep: beepSound, shape : "Square", label : false});
  114. menu9.events.onInputOut.add(this.clearTitle);
  115. // Floor
  116. for(var i=0;i<9;i++){
  117. game.add.image(i*100, 501, 'floor');
  118. }
  119. },
  120. //calls the selected game menu screen
  121. loadGame: function(){
  122. if(audioStatus){
  123. this.beep.play();
  124. }
  125. if( (this.num==1 || this.num==2) && this.shape=="Circle"){
  126. oneShape = this.shape;
  127. oneLabel = this.label;
  128. oneType = "A";
  129. game.state.start('menuCOne');
  130. }
  131. if( (this.num==3 || this.num==4) && this.shape=="Circle"){
  132. oneShape = this.shape;
  133. oneLabel = this.label;
  134. oneType = "B";
  135. game.state.start('menuCOne');
  136. }
  137. if( (this.num==1 || this.num==2) && this.shape=="Square"){
  138. oneShape = this.shape;
  139. oneLabel = this.label;
  140. oneType = "A";
  141. game.state.start('menuSOne');
  142. }
  143. if( (this.num==3 || this.num==4) && this.shape=="Square"){
  144. oneShape = this.shape;
  145. oneLabel = this.label;
  146. oneType = "B";
  147. game.state.start('menuSOne');
  148. }
  149. if( this.num==5 && this.shape=="Square"){
  150. twoShape = this.shape;
  151. twoLabel = this.label;
  152. twoType = "";
  153. game.state.start('menuSTwo');
  154. }
  155. },
  156. showTitle: function(){
  157. var title = "";
  158. var type = "";
  159. if( (this.num==1 || this.num==2) ){
  160. type = "I";
  161. }
  162. if( (this.num==3 || this.num==4) ){
  163. type = "II";
  164. }
  165. if( this.num==5 && this.shape=="Square"){
  166. type = "III";
  167. }
  168. if(this.shape=="Circle"){
  169. title += lang.circle_name;
  170. }else if(this.shape=="Square"){
  171. title += lang.square_name;
  172. }
  173. if(type!=""){
  174. //circ/quad A/B/C
  175. title += " " + type;
  176. }
  177. if(this.label){
  178. //- sem/com legendas
  179. title += " - " + lang.with_name + " " + lang.label_name;
  180. }else{
  181. title += " - " + lang.without_name + " " + lang.label_name;
  182. }
  183. lbl_game.text = title;
  184. },
  185. clearTitle: function(){
  186. lbl_game.text = "";
  187. },
  188. loadState: function(){
  189. if(audioStatus){
  190. this.beep.play();
  191. }
  192. game.state.start(this.state);
  193. },
  194. };