menu.js 8.4 KB

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