boot.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. var username;
  2. /*
  3. var bootState = {
  4. preload: function(){},
  5. create: function(){},
  6. setLang: function(){} //calls loadState
  7. };
  8. var loadState = {
  9. preload: function(){},
  10. create: function(){} //calls nameState
  11. };
  12. var nameState = {
  13. preload: function(){},
  14. create: function(){},
  15. clearName: function(){},
  16. keyPressed: function( char ){},
  17. ready: function(){} //calls menu.js -> menuState
  18. };
  19. */
  20. // choose language screen
  21. var bootState = {
  22. preload: function() {
  23. //Progress bar image
  24. game.load.image('progressBar', 'assets/img/pgbar.png');
  25. //loading flags (manually)
  26. game.load.image('flag_BR', 'assets/img/flag/BRAZ.jpg');
  27. game.load.image('flag_PE', 'assets/img/flag/PERU.jpg');
  28. game.load.image('flag_US', 'assets/img/flag/UNST.jpg');
  29. game.load.image('flag_FR', 'assets/img/flag/FRAN.jpg');
  30. },
  31. create: function() {
  32. //game settings
  33. game.stage.backgroundColor = '#cce5ff';
  34. game.physics.startSystem(Phaser.Physics.ARCADE);
  35. var style = { font: '28px Arial', fill: '#00804d', align: 'center' };
  36. //generating language selection
  37. //pt_BR
  38. var title1 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY - 100, 'FRAÇÕES ', style);
  39. title1.anchor.setTo(1, 0.5);
  40. var flag1 = game.add.sprite(this.game.world.centerX - 220, this.game.world.centerY - 100, 'flag_BR');
  41. flag1.anchor.setTo(0, 0.5);
  42. flag1.inputEnabled = true;
  43. flag1.input.useHandCursor = true;
  44. flag1.events.onInputDown.add(this.setLang,{lang:'pt_BR'});
  45. //es_PE
  46. var title2 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY - 100, 'FRACCIONES ', style);
  47. title2.anchor.setTo(1, 0.5);
  48. var flag2 = game.add.sprite(this.game.world.centerX + 200, this.game.world.centerY - 100, 'flag_PE');
  49. flag2.anchor.setTo(0, 0.5);
  50. flag2.inputEnabled = true;
  51. flag2.input.useHandCursor = true;
  52. flag2.events.onInputDown.add(this.setLang,{lang:'es_PE'});
  53. //en_US
  54. var title3 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY + 100, 'FRACTIONS ', style);
  55. title3.anchor.setTo(1, 0.5);
  56. var flag3 = game.add.sprite(this.game.world.centerX - 220, this.game.world.centerY + 100, 'flag_US');
  57. flag3.anchor.setTo(0, 0.5);
  58. flag3.inputEnabled = true;
  59. flag3.input.useHandCursor = true;
  60. flag3.events.onInputDown.add(this.setLang,{lang:'en_US'});
  61. //fr_FR
  62. var title4 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY + 100, 'FRACTIONS ', style);
  63. title4.anchor.setTo(1, 0.5);
  64. var flag4 = game.add.sprite(this.game.world.centerX + 200, this.game.world.centerY + 100, 'flag_FR');
  65. flag4.anchor.setTo(0, 0.5);
  66. flag4.inputEnabled = true;
  67. flag4.input.useHandCursor = true;
  68. flag4.events.onInputDown.add(this.setLang,{lang:'fr_FR'});
  69. },
  70. setLang: function(){
  71. //set language
  72. lang = this.lang;
  73. //start resource loading
  74. game.state.start('load');
  75. }
  76. };
  77. // loading screen (+loading assets)
  78. var loadState = {
  79. preload: function() {
  80. // Displaying the progress bar
  81. var progressBar = game.add.sprite(game.world.centerX, game.world.centerY, 'progressBar');
  82. progressBar.anchor.setTo(0.5, 0.5);
  83. game.load.setPreloadSprite(progressBar);
  84. if(!oneMenu){
  85. game.stage.backgroundColor = '#cce5ff';
  86. game.physics.startSystem(Phaser.Physics.ARCADE);
  87. }
  88. // Loading dictionary
  89. game.load.json('dictionary', 'assets/languages/'+lang+'.json');
  90. // Loading global assets (sprites and images)
  91. var imgsrc = 'assets/img/';
  92. game.load.image('bgimage', imgsrc+'bg.jpg');
  93. game.load.image('bgmap', imgsrc+'bg_map.png');
  94. game.load.image('cloud', imgsrc+'cloud.png');
  95. game.load.image('floor', imgsrc+'floor.png');
  96. game.load.image('road', imgsrc+'road.png');
  97. //games list buttons
  98. game.load.image('game1c', imgsrc+'game/one-c.png');
  99. game.load.image('game2c', imgsrc+'game/two-c.png');
  100. game.load.image('game3c', imgsrc+'game/three-c.png');
  101. game.load.image('game4c', imgsrc+'game/four-c.png');
  102. game.load.image('game1s', imgsrc+'game/one-s.png');
  103. game.load.image('game2s', imgsrc+'game/two-s.png');
  104. game.load.image('game3s', imgsrc+'game/three-s.png');
  105. game.load.image('game4s', imgsrc+'game/four-s.png');
  106. game.load.image('game5s', imgsrc+'game/five-s.png');
  107. //header menu
  108. game.load.image('back', imgsrc+'menu/back.png');
  109. game.load.image('home', imgsrc+'menu/home.png');
  110. game.load.image('info', imgsrc+'menu/info.png');
  111. game.load.image('world', imgsrc+'menu/language.png');
  112. game.load.image('list', imgsrc+'menu/menu.png');
  113. game.load.image('help', imgsrc+'menu/help.png');
  114. game.load.image('pgbar', imgsrc+'menu/progressBar.png');
  115. game.load.image('block', imgsrc+'menu/block.png');
  116. game.load.image('eraser', imgsrc+'menu/eraser.png');
  117. //operators
  118. game.load.image('add', imgsrc+'operator/add.png');
  119. game.load.image('subtract', imgsrc+'operator/subtract.png');
  120. game.load.image('separator', imgsrc+'operator/separator.png');
  121. game.load.image('equal', imgsrc+'operator/equal.png');
  122. //helpers
  123. game.load.image('h_arrow', imgsrc+'help/arrow.png');
  124. game.load.image('h_double', imgsrc+'help/double.png');
  125. game.load.image('h_error', imgsrc+'help/error.png');
  126. game.load.image('h_ok', imgsrc+'help/ok.png');
  127. game.load.image('down', imgsrc+'help/down.png');
  128. game.load.image('pointer', imgsrc+'help/pointer.png');
  129. // Loading assets based on lang
  130. game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
  131. game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 24);
  132. game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
  133. game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
  134. game.load.image('balloon', imgsrc+'airballoon_upper.png');
  135. game.load.image('balloon_basket', imgsrc+'airballoon_base.png');
  136. game.load.image('birch', imgsrc+'birch.png');
  137. game.load.image('flag', imgsrc+'flag.png');
  138. game.load.image('house', imgsrc+'house.png');
  139. game.load.image('place_a', imgsrc+'place_a.png');
  140. game.load.image('place_b', imgsrc+'place_b.png');
  141. game.load.image('garage', imgsrc+'garage.png');
  142. game.load.image('farm', imgsrc+'farm.png');
  143. game.load.image('rock', imgsrc+'rock.png');
  144. game.load.image('school', imgsrc+'school.png');
  145. game.load.image('sign', imgsrc+'sign.png');
  146. game.load.image('tree1', imgsrc+'tree.png');
  147. game.load.image('tree2', imgsrc+'tree2.png');
  148. game.load.image('tree3', imgsrc+'tree3.png');
  149. game.load.image('tree4', imgsrc+'tree4.png');
  150. // Loadind Sound Effects
  151. game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
  152. game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
  153. game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
  154. },
  155. create: function() {
  156. game.state.start('name');
  157. }
  158. };
  159. // type name screen
  160. var nameState = {
  161. preload: function () {
  162. },
  163. create: function() {
  164. game.stage.backgroundColor = '#cce5ff';
  165. // gets selected language from json
  166. var words = game.cache.getJSON('dictionary');
  167. game.physics.startSystem(Phaser.Physics.ARCADE);
  168. var style = { font: '30px Arial', fill: '#00804d', align: 'center' };
  169. var styleName = { font: '44px Arial', fill: '#000000', align: 'center' };
  170. // title
  171. var title = game.add.text(this.game.world.centerX, this.game.world.centerY - 100, words.insert_name, style);
  172. title.anchor.setTo(0.5);
  173. // "READY" button
  174. var btn = game.add.graphics(this.game.world.centerX - 84, this.game.world.centerY + 70);
  175. btn.lineStyle(1, 0x293d3d);
  176. btn.beginFill(0x3d5c5c);
  177. btn.drawRect(0, 0, 168, 60);
  178. btn.alpha = 0.5;
  179. btn.endFill();
  180. btn.inputEnabled = true;
  181. btn.input.useHandCursor = true;
  182. btn.events.onInputDown.add(this.ready, null);
  183. var ready = game.add.text(this.game.world.centerX + 1, this.game.world.centerY + 102, words.ready, { font: '34px Arial', fill: '#f0f5f5', align: 'center' });
  184. ready.anchor.setTo(0.5);
  185. document.getElementById("text-field-div").style.visibility = "visible";
  186. document.getElementById("name_id").addEventListener('keypress', function(e){
  187. var keycode = e.keycode ? e.keycode : e.which;
  188. //se apertar enter vai para ready, assim como o botão
  189. if(keycode == 13){
  190. nameState["ready"]();
  191. }
  192. });
  193. },
  194. //var ready = function readyFunction() {...},
  195. //var ready = function() {...},
  196. ready: function() {
  197. // saves the typed name on username variable
  198. username = document.getElementById("name_id").value;
  199. console.log("user is " + username);
  200. document.getElementById("text-field-div").style.visibility = "hidden";
  201. //clears the text field again
  202. document.getElementById("name_id").value = "";
  203. if(oneMenu){ //If menu, normal game
  204. // Go to the menu state
  205. game.state.start('menu');
  206. }else{ //parameters game
  207. if(oneShape=="Circle"){
  208. game.state.start("mapCOne");
  209. }else if(oneShape=="Square"){
  210. if(oneOperator=='Mixed'){
  211. twoPosition = 0;
  212. twoMove = true;
  213. twoDifficulty = oneDifficulty;
  214. twoOperator= "";
  215. twoLabel= false;
  216. twoShape = oneShape;
  217. twoType = oneType;
  218. twoMenu = false;
  219. game.state.start("mapSTwo");
  220. }else{
  221. game.state.start("mapSOne");
  222. }
  223. }
  224. }
  225. }
  226. };