preMenu.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. preload: function(){},
  15. create: function(){},
  16. ------------------------------------------------ end of phaser functions
  17. ready: function(){} //calls menu.js -> menuState
  18. };
  19. */
  20. // "choose language" screen
  21. var langState = {
  22. create: function() {
  23. game.stage.backgroundColor = '#cce5ff';
  24. var style = { font: '28px Arial', fill: '#00804d', align: 'center' };
  25. //pt_BR
  26. var title1 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY - 100, 'FRAÇÕES ', style);
  27. title1.anchor.setTo(1, 0.5);
  28. var flag1 = game.add.sprite(this.game.world.centerX - 220, this.game.world.centerY - 100, 'flag_BR');
  29. flag1.anchor.setTo(0, 0.5);
  30. flag1.inputEnabled = true;
  31. flag1.input.useHandCursor = true;
  32. flag1.events.onInputDown.add(this.setLang,{lang:'pt_BR'});
  33. //es_PE
  34. var title2 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY - 100, 'FRACCIONES ', style);
  35. title2.anchor.setTo(1, 0.5);
  36. var flag2 = game.add.sprite(this.game.world.centerX + 200, this.game.world.centerY - 100, 'flag_PE');
  37. flag2.anchor.setTo(0, 0.5);
  38. flag2.inputEnabled = true;
  39. flag2.input.useHandCursor = true;
  40. flag2.events.onInputDown.add(this.setLang,{lang:'es_PE'});
  41. //en_US
  42. var title3 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY + 100, 'FRACTIONS ', style);
  43. title3.anchor.setTo(1, 0.5);
  44. var flag3 = game.add.sprite(this.game.world.centerX - 220, this.game.world.centerY + 100, 'flag_US');
  45. flag3.anchor.setTo(0, 0.5);
  46. flag3.inputEnabled = true;
  47. flag3.input.useHandCursor = true;
  48. flag3.events.onInputDown.add(this.setLang,{lang:'en_US'});
  49. //fr_FR
  50. var title4 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY + 100, 'FRACTIONS ', style);
  51. title4.anchor.setTo(1, 0.5);
  52. var flag4 = game.add.sprite(this.game.world.centerX + 200, this.game.world.centerY + 100, 'flag_FR');
  53. flag4.anchor.setTo(0, 0.5);
  54. flag4.inputEnabled = true;
  55. flag4.input.useHandCursor = true;
  56. flag4.events.onInputDown.add(this.setLang,{lang:'fr_FR'});
  57. },
  58. setLang: function(){
  59. //set language
  60. lang = this.lang;
  61. //start resource loading
  62. game.state.start('load');
  63. }
  64. };
  65. // "loading" screen
  66. var loadState = {
  67. preload: function() {
  68. // Displaying the progress bar
  69. var progressBar = game.add.sprite(game.world.centerX, game.world.centerY, 'progressBar');
  70. progressBar.anchor.setTo(0.5, 0.5);
  71. game.load.setPreloadSprite(progressBar);
  72. // Loading dictionary
  73. game.load.json('dictionary', 'assets/languages/'+lang+'.json');
  74. },
  75. create: function() {
  76. // gets selected language from json
  77. lang = game.cache.getJSON('dictionary');
  78. audio_lang_aux = lang.audio_on;
  79. game.state.start('name');
  80. }
  81. };
  82. // "username" screen
  83. var nameState = {
  84. create: function() {
  85. var style = { font: '30px Arial', fill: '#00804d', align: 'center' };
  86. var styleName = { font: '44px Arial', fill: '#000000', align: 'center' };
  87. // title
  88. var title = game.add.text(this.game.world.centerX, this.game.world.centerY - 100, lang.insert_name, style);
  89. title.anchor.setTo(0.5);
  90. // "READY" button
  91. var btn = game.add.graphics(this.game.world.centerX - 84, this.game.world.centerY + 70);
  92. btn.lineStyle(1, 0x293d3d);
  93. btn.beginFill(0x3d5c5c);
  94. btn.drawRect(0, 0, 168, 60);
  95. btn.alpha = 0.5;
  96. btn.endFill();
  97. btn.inputEnabled = true;
  98. btn.input.useHandCursor = true;
  99. btn.events.onInputDown.add(this.nameIsEmpty, null);
  100. var ready = game.add.text(this.game.world.centerX + 1, this.game.world.centerY + 102, lang.ready, { font: '34px Arial', fill: '#f0f5f5', align: 'center' });
  101. ready.anchor.setTo(0.5);
  102. errorEmptyName = game.add.text(this.game.world.centerX, this.game.world.centerY - 70, "", {font: '18px Arial', fill: '#330000', align: 'center'});
  103. errorEmptyName.anchor.setTo(0.5);
  104. document.getElementById("text-field-div").style.visibility = "visible";
  105. document.getElementById("name_id").addEventListener('keypress', function(e){
  106. var keycode = e.keycode ? e.keycode : e.which;
  107. //se apertar enter vai para ready, assim como o botão
  108. if(keycode == 13){
  109. nameState["nameIsEmpty"]();
  110. }
  111. });
  112. },
  113. nameIsEmpty: function() {
  114. if(document.getElementById("name_id").value!=""){
  115. nameState["ready"]();
  116. errorEmptyName.setText("");
  117. }else{
  118. errorEmptyName.setText(lang.empty_name);
  119. }
  120. },
  121. //var ready = function readyFunction() {...},
  122. //var ready = function() {...},
  123. ready: function() {
  124. // saves the typed name on username variable
  125. username = document.getElementById("name_id").value;
  126. console.log("user is" + username);
  127. document.getElementById("text-field-div").style.visibility = "hidden";
  128. //clears the text field again
  129. document.getElementById("name_id").value = "";
  130. if(oneMenu){ //If menu, normal game
  131. // Go to the menu state
  132. game.state.start('menu');
  133. }else{ //parameters game
  134. if(oneShape=="Circle"){
  135. game.state.start("mapCOne");
  136. }else if(oneShape=="Square"){
  137. if(oneOperator=='Mixed'){
  138. twoPosition = 0;
  139. twoMove = true;
  140. twoDifficulty = oneDifficulty;
  141. twoOperator= "";
  142. twoLabel= false;
  143. twoShape = oneShape;
  144. twoType = oneType;
  145. twoMenu = false;
  146. game.state.start("mapSTwo");
  147. }else{
  148. game.state.start("mapSOne");
  149. }
  150. }
  151. }
  152. }
  153. };