boot.js 11 KB

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