boot.js 11 KB

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