preMenu.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. var errorEmptyName;
  2. /*
  3. var langState = {
  4. create: function(){},
  5. --------------------------------------- end of phaser functions
  6. setLang: function(){} //calls loadState
  7. };
  8. var loadState = {
  9. preload: function(){},
  10. create: function(){} //calls nameState
  11. -------------------------------------- end of phaser functions
  12. };
  13. var nameState = {
  14. create: function(){},
  15. ------------------------------------------------ end of phaser functions
  16. nameIsEmpty: function(){}
  17. ready: function(){} //calls menu.js -> menuState
  18. };
  19. var buttonSettings = {
  20. addButtons: function(_,_,_,_,_,_,_,_,_){},
  21. loadState: function(){}
  22. };
  23. */
  24. // "choose language" screen
  25. var langState = {
  26. create: function() {
  27. game.stage.backgroundColor = '#cce5ff';
  28. var style = { font: '28px Arial', fill: '#00804d', align: 'center' };
  29. //pt_BR
  30. var title1 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY - 100, 'FRAÇÕES ', style);
  31. title1.anchor.setTo(1, 0.5);
  32. var flag1 = game.add.sprite(this.game.world.centerX - 220, this.game.world.centerY - 100, 'flag_BR');
  33. flag1.anchor.setTo(0, 0.5);
  34. flag1.inputEnabled = true;
  35. flag1.input.useHandCursor = true;
  36. flag1.events.onInputDown.add(this.setLang,{lang:'pt_BR'});
  37. //es_PE
  38. var title2 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY - 100, 'FRACCIONES ', style);
  39. title2.anchor.setTo(1, 0.5);
  40. var flag2 = game.add.sprite(this.game.world.centerX + 200, this.game.world.centerY - 100, 'flag_PE');
  41. flag2.anchor.setTo(0, 0.5);
  42. flag2.inputEnabled = true;
  43. flag2.input.useHandCursor = true;
  44. flag2.events.onInputDown.add(this.setLang,{lang:'es_PE'});
  45. //en_US
  46. var title3 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY + 100, 'FRACTIONS ', style);
  47. title3.anchor.setTo(1, 0.5);
  48. var flag3 = game.add.sprite(this.game.world.centerX - 220, this.game.world.centerY + 100, 'flag_US');
  49. flag3.anchor.setTo(0, 0.5);
  50. flag3.inputEnabled = true;
  51. flag3.input.useHandCursor = true;
  52. flag3.events.onInputDown.add(this.setLang,{lang:'en_US'});
  53. //fr_FR
  54. var title4 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY + 100, 'FRACTIONS ', style);
  55. title4.anchor.setTo(1, 0.5);
  56. var flag4 = game.add.sprite(this.game.world.centerX + 200, this.game.world.centerY + 100, 'flag_FR');
  57. flag4.anchor.setTo(0, 0.5);
  58. flag4.inputEnabled = true;
  59. flag4.input.useHandCursor = true;
  60. flag4.events.onInputDown.add(this.setLang,{lang:'fr_FR'});
  61. },
  62. setLang: function(){
  63. //set language
  64. lang = this.lang;
  65. //start resource loading
  66. game.state.start('load');
  67. }
  68. };
  69. // "loading" screen
  70. var loadState = {
  71. preload: function() {
  72. // Displaying the progress bar
  73. var progressBar = game.add.sprite(game.world.centerX, game.world.centerY, 'progressBar');
  74. progressBar.anchor.setTo(0.5, 0.5);
  75. game.load.setPreloadSprite(progressBar);
  76. // Loading dictionary
  77. game.load.json('dictionary', 'assets/languages/'+lang+'.json');
  78. },
  79. create: function() {
  80. // gets selected language from json
  81. lang = game.cache.getJSON('dictionary');
  82. audio_lang_aux = lang.audio_on;
  83. if(!nameStatus){
  84. nameStatus = true;
  85. game.state.start('name');
  86. }else{
  87. game.state.start('menu');
  88. }
  89. }
  90. };
  91. // "username" screen
  92. var nameState = {
  93. create: function() {
  94. var style = { font: '30px Arial', fill: '#00804d', align: 'center' };
  95. var styleName = { font: '44px Arial', fill: '#000000', align: 'center' };
  96. // title
  97. var title = game.add.text(this.game.world.centerX, this.game.world.centerY - 100, lang.insert_name, style);
  98. title.anchor.setTo(0.5);
  99. // "READY" button
  100. var btn = game.add.graphics(this.game.world.centerX - 84, this.game.world.centerY + 70);
  101. btn.lineStyle(1, 0x293d3d);
  102. btn.beginFill(0x3d5c5c);
  103. btn.drawRect(0, 0, 168, 60);
  104. btn.alpha = 0.5;
  105. btn.endFill();
  106. btn.inputEnabled = true;
  107. btn.input.useHandCursor = true;
  108. btn.events.onInputDown.add(this.nameIsEmpty, null);
  109. var ready = game.add.text(this.game.world.centerX + 1, this.game.world.centerY + 102, lang.ready, { font: '34px Arial', fill: '#f0f5f5', align: 'center' });
  110. ready.anchor.setTo(0.5);
  111. errorEmptyName = game.add.text(this.game.world.centerX, this.game.world.centerY - 70, "", {font: '18px Arial', fill: '#330000', align: 'center'});
  112. errorEmptyName.anchor.setTo(0.5);
  113. document.getElementById("text-field-div").style.visibility = "visible";
  114. document.getElementById("name_id").addEventListener('keypress', function(e){
  115. var keycode = e.keycode ? e.keycode : e.which;
  116. //se apertar enter vai para ready, assim como o botão
  117. if(keycode == 13){
  118. nameState["nameIsEmpty"]();
  119. }
  120. });
  121. },
  122. nameIsEmpty: function() {
  123. if(document.getElementById("name_id").value!=""){
  124. nameState["ready"]();
  125. errorEmptyName.setText("");
  126. }else{
  127. errorEmptyName.setText(lang.empty_name);
  128. }
  129. },
  130. ready: function() {
  131. // saves the typed name on username variable
  132. username = document.getElementById("name_id").value;
  133. console.log("user is" + username);
  134. document.getElementById("text-field-div").style.visibility = "hidden";
  135. //clears the text field again
  136. document.getElementById("name_id").value = "";
  137. if(oneMenu){ //If menu, normal game
  138. // Go to the menu state
  139. game.state.start('menu');
  140. }else{ //parameters game
  141. if(oneShape=="Circle"){
  142. game.state.start("mapCOne");
  143. }else if(oneShape=="Square"){
  144. if(oneOperator=='Mixed'){
  145. twoPosition = 0;
  146. twoMove = true;
  147. twoDifficulty = oneDifficulty;
  148. twoOperator= "";
  149. twoLabel= false;
  150. twoShape = oneShape;
  151. twoType = oneType;
  152. twoMenu = false;
  153. game.state.start("mapSTwo");
  154. }else{
  155. game.state.start("mapSOne");
  156. }
  157. }
  158. }
  159. }
  160. };
  161. var m_info_right, m_info_left;
  162. var m_world, m_menu, m_back, m_help, m_audio;
  163. var buttonSettings = {
  164. addButtons: function(left, right, b0Esq, b1Esq, b2Esq, b0Dir, b1Dir, phase, helpBtn){
  165. var xEsq = 10;
  166. var xDir = (game.world.width - 50 - 10);
  167. if(left == 1){
  168. m_info_left = game.add.text(xEsq, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
  169. }
  170. if(right == 1){
  171. m_info_right = game.add.text(xDir+50, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
  172. m_info_right.anchor.setTo(1,0.02);
  173. }
  174. //left buttons
  175. if(b0Esq == 1){
  176. // Return to diffculty
  177. m_back = game.add.sprite(xEsq, 10, 'back');
  178. m_back.inputEnabled = true;
  179. m_back.input.useHandCursor = true;
  180. m_back.events.onInputDown.add(this.loadState, {state: phase, beep: beepSound});
  181. m_back.events.onInputOver.add(function(){ m_info_left.text = lang.menu_back});
  182. m_back.events.onInputOut.add(function(){ m_info_left.text = ""});
  183. xEsq+=50;
  184. }
  185. if(b1Esq == 1){
  186. // Return to menu button
  187. m_list = game.add.sprite(xEsq, 10, 'list');
  188. m_list.inputEnabled = true;
  189. m_list.input.useHandCursor = true;
  190. m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
  191. m_list.events.onInputOver.add(function(){ m_info_left.text = lang.menu_list});
  192. m_list.events.onInputOut.add(function(){ m_info_left.text = ""});
  193. xEsq+=50;
  194. }
  195. if(b2Esq == 1){
  196. // Help button
  197. m_help = game.add.sprite(xEsq, 10, 'help');
  198. m_help.inputEnabled = true;
  199. m_help.input.useHandCursor = true;
  200. m_help.events.onInputDown.add(helpBtn, {beep: beepSound});
  201. m_help.events.onInputOver.add(function(){ m_info_left.text = lang.menu_help});
  202. m_help.events.onInputOut.add(function(){ m_info_left.text = ""});
  203. xEsq+=50;
  204. }
  205. //rightButtons
  206. if(b0Dir == 1){
  207. m_audio = game.add.sprite(xDir, 10, 'audio');
  208. audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
  209. m_audio.inputEnabled = true;
  210. m_audio.input.useHandCursor = true;
  211. m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
  212. m_audio.events.onInputOver.add(function(){ m_info_right.text = lang.audio });
  213. m_audio.events.onInputOut.add(function(){ m_info_right.text = "" });
  214. xDir-=50;
  215. }
  216. if(b1Dir == 1){
  217. // Return to language button
  218. m_world = game.add.sprite(xDir, 10, 'world');
  219. m_world.inputEnabled = true;
  220. m_world.input.useHandCursor = true;
  221. m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
  222. m_world.events.onInputOver.add(function(){ m_info_right.text = lang.menu_world });
  223. m_world.events.onInputOut.add(function(){ m_info_right.text = "" });
  224. xDir-=50;
  225. }
  226. },
  227. loadState: function(){
  228. if(audioStatus){
  229. this.beep.play();
  230. }
  231. game.state.start(this.state);
  232. }
  233. };