boot.js 11 KB

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