boot.js 11 KB

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