menu.js 9.3 KB

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