menu.js 8.8 KB

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