menu.js 9.1 KB

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