menu.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. m_world = game.add.sprite(10, 10, 'world');
  25. m_world.inputEnabled = true;
  26. m_world.input.useHandCursor = true;
  27. m_world.events.onInputDown.add(this.loadState, {state: "boot", beep: beepSound});
  28. m_world.events.onInputOver.add(this.showOption, {message: words.menu_world});
  29. m_world.events.onInputOut.add(this.showOption, {message: ""});
  30. // List buttons
  31. menu1 = game.add.sprite(this.game.world.centerX + 10, this.game.world.centerY - 70, 'game1c');
  32. menu2 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY - 70, 'game2c');
  33. menu3 = game.add.sprite(this.game.world.centerX + 10, this.game.world.centerY + 90, 'game3c');
  34. menu4 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY + 90, 'game4c');
  35. menu5 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY - 70, 'game1s');
  36. menu6 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY - 70, 'game2s');
  37. menu7 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY + 90, 'game3s');
  38. menu8 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY + 90, 'game4s');
  39. menu9 = game.add.sprite(this.game.world.centerX + 350, this.game.world.centerY -70, 'game5s');
  40. // Buttons actions
  41. menu1.anchor.setTo(0.5, 0.5);
  42. menu1.inputEnabled = true;
  43. menu1.input.useHandCursor = true;
  44. menu1.events.onInputDown.add(this.loadGame,{num:1, beep: beepSound, shape : "Circle", label : true});
  45. menu1.events.onInputOver.add(this.showTitle,{num:1, beep: beepSound, shape : "Circle", label : true});
  46. menu1.events.onInputOut.add(this.clearTitle);
  47. menu2.anchor.setTo(0.5, 0.5);
  48. menu2.inputEnabled = true;
  49. menu2.input.useHandCursor = true;
  50. menu2.events.onInputDown.add(this.loadGame,{num:2, beep: beepSound, shape : "Circle", label : false});
  51. menu2.events.onInputOver.add(this.showTitle,{num:2, beep: beepSound, shape : "Circle", label : false});
  52. menu2.events.onInputOut.add(this.clearTitle);
  53. menu3.anchor.setTo(0.5, 0.5);
  54. menu3.inputEnabled = true;
  55. menu3.input.useHandCursor = true;
  56. menu3.events.onInputDown.add(this.loadGame,{num:3, beep: beepSound, shape : "Circle", label : true});
  57. menu3.events.onInputOver.add(this.showTitle,{num:3, beep: beepSound, shape : "Circle", label : true});
  58. menu3.events.onInputOut.add(this.clearTitle);
  59. menu4.anchor.setTo(0.5, 0.5);
  60. menu4.inputEnabled = true;
  61. menu4.input.useHandCursor = true;
  62. menu4.events.onInputDown.add(this.loadGame,{num:4, beep: beepSound, shape : "Circle", label : false});
  63. menu4.events.onInputOver.add(this.showTitle,{num:4, beep: beepSound, shape : "Circle", label : false});
  64. menu4.events.onInputOut.add(this.clearTitle);
  65. menu5.anchor.setTo(0.5, 0.5);
  66. menu5.inputEnabled = true;
  67. menu5.input.useHandCursor = true;
  68. menu5.events.onInputDown.add(this.loadGame,{num:1, beep: beepSound, shape : "Square", label : true});
  69. menu5.events.onInputOver.add(this.showTitle,{num:1, beep: beepSound, shape : "Square", label : true});
  70. menu5.events.onInputOut.add(this.clearTitle);
  71. menu6.anchor.setTo(0.5, 0.5);
  72. menu6.inputEnabled = true;
  73. menu6.input.useHandCursor = true;
  74. menu6.events.onInputDown.add(this.loadGame,{num:2, beep: beepSound, shape : "Square", label : false});
  75. menu6.events.onInputOver.add(this.showTitle,{num:2, beep: beepSound, shape : "Square", label : false});
  76. menu6.events.onInputOut.add(this.clearTitle);
  77. menu7.anchor.setTo(0.5, 0.5);
  78. menu7.inputEnabled = true;
  79. menu7.input.useHandCursor = true;
  80. menu7.events.onInputDown.add(this.loadGame,{num:3, beep: beepSound, shape : "Square", label : true});
  81. menu7.events.onInputOver.add(this.showTitle,{num:3, beep: beepSound, shape : "Square", label : true});
  82. menu7.events.onInputOut.add(this.clearTitle);
  83. menu8.anchor.setTo(0.5, 0.5);
  84. menu8.inputEnabled = true;
  85. menu8.input.useHandCursor = true;
  86. menu8.events.onInputDown.add(this.loadGame,{num:4, beep: beepSound, shape : "Square", label : false});
  87. menu8.events.onInputOver.add(this.showTitle,{num:4, beep: beepSound, shape : "Square", label : false});
  88. menu8.events.onInputOut.add(this.clearTitle);
  89. menu9.anchor.setTo(0.5, 0.5);
  90. menu9.inputEnabled = true;
  91. menu9.input.useHandCursor = true;
  92. menu9.events.onInputDown.add(this.loadGame,{num:5, beep: beepSound, shape : "Square", label : false});
  93. menu9.events.onInputOver.add(this.showTitle,{num:5, beep: beepSound, shape : "Square", label : false});
  94. menu9.events.onInputOut.add(this.clearTitle);
  95. // Floor
  96. for(var i=0;i<9;i++){
  97. game.add.image(i*100, 501, 'floor');
  98. }
  99. },
  100. loadGame: function(){
  101. this.beep.play();
  102. if( (this.num==1 || this.num==2) && this.shape=="Circle"){
  103. oneShape = this.shape;
  104. oneLabel = this.label;
  105. oneType = "A";
  106. game.state.start('menuCOne');
  107. }
  108. if( (this.num==3 || this.num==4) && this.shape=="Circle"){
  109. oneShape = this.shape;
  110. oneLabel = this.label;
  111. oneType = "B";
  112. game.state.start('menuCOne');
  113. }
  114. if( (this.num==1 || this.num==2) && this.shape=="Square"){
  115. oneShape = this.shape;
  116. oneLabel = this.label;
  117. oneType = "A";
  118. game.state.start('menuSOne');
  119. }
  120. if( (this.num==3 || this.num==4) && this.shape=="Square"){
  121. oneShape = this.shape;
  122. oneLabel = this.label;
  123. oneType = "B";
  124. game.state.start('menuSOne');
  125. }
  126. if( this.num==5 && this.shape=="Square"){
  127. twoShape = this.shape;
  128. twoLabel = this.label;
  129. twoType = "";
  130. game.state.start('menuSTwo');
  131. }
  132. },
  133. showTitle: function(){
  134. var title = "";
  135. var type = "";
  136. if( (this.num==1 || this.num==2) ){
  137. type = "A";
  138. }
  139. if( (this.num==3 || this.num==4) ){
  140. type = "B";
  141. }
  142. if( this.num==5 && this.shape=="Square"){
  143. type = "C";
  144. }
  145. if(this.shape=="Circle"){
  146. title += words.circle_name;
  147. }else if(this.shape=="Square"){
  148. title += words.square_name;
  149. }
  150. if(type!=""){
  151. title += ", "+words.mode_name+ " "+type;
  152. }
  153. if(this.label){
  154. title += ", " + words.with_name + " " + words.label_name;
  155. }else{
  156. title += ", " + words.without_name + " " + words.label_name;
  157. }
  158. lbl_game.text = title;
  159. },
  160. clearTitle: function(){
  161. lbl_game.text = "";
  162. },
  163. showOption: function(){
  164. m_info.text = this.message;
  165. },
  166. loadState: function(){
  167. this.beep.play();
  168. game.state.start(this.state);
  169. }
  170. };