boot.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. let loadAssets = {
  3. preload: function(){},
  4. create: function()
  5. ---------------------------- end of phaser functions
  6. };
  7. */
  8. // OUTRAS VARIAVEIS GLOBAIS
  9. let passedLevels;
  10. //premenu
  11. let errorEmptyName;
  12. //map
  13. let kid, tractor;
  14. //square 1 + circle 1
  15. let startX;
  16. let clicked, hideLabels, checkCollide, result, hasFigure;
  17. let detail;
  18. let endPosition;
  19. let fractionClicked, fractionIndex;
  20. let blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator; //blocks control
  21. //square 1
  22. let blockWidth, blockIndex;
  23. let floorBlocks, floorIndex, floorCount, floorClicked, curFloor;
  24. let move, moveCounter, moveEnd;
  25. let arrow;
  26. let arrowPlace;
  27. //circle 1
  28. let blockSize, blockAngle, blockTraceColor;
  29. let fly, flyCounter, flyend; //flyvariables
  30. let trace; //circle trace
  31. let numPlus, endIndex;
  32. let kid_walk, balloon, basket;
  33. let balloonPlace;
  34. //square 2
  35. let sizeA, sizeB, valueA, valueB;
  36. let clickA, clickB, animateA, animateB, animate, cDelay, eDelay;
  37. let blocksA, blocksB, auxblqA, auxblqB;
  38. let labelA, fractionA, separatorA, labelB, fractionB, separatorB;
  39. let kidDirection, equals, counter, endCounter;
  40. let xA, yA, xB, yB, blockW, blockH;
  41. // INFO
  42. let username; //player name
  43. let lang; //language
  44. // IMAGES
  45. let beepSound, okSound, errorSound; //sounds
  46. let okImg, errorImg;
  47. let timer, totalTime;
  48. // variaveis globais
  49. let audioStatus = false; // turns game audio on/off
  50. let firstTime = true; //if player has just oppened the game
  51. let debugMode = true; //turns console messages for developers on/off (changeable only by code)
  52. // game dimentions
  53. const defaultWidth = 900;
  54. const defaultHeight = 600;
  55. // Initialize the game
  56. let game = new Phaser.Game(
  57. defaultWidth,
  58. defaultHeight,
  59. Phaser.CANVAS,
  60. 'fractions-game'
  61. );
  62. const hip = "143.107.45.11"; //Host ip
  63. // Game One : kid and truck
  64. let levelPosition = 0; //Map position
  65. let levelMove = false; //Move to next position
  66. let levelDifficulty = 0; //From one to five
  67. let levelOperator = ""; //Plus; Minus; Mixed
  68. let levelLabel= false; //Show block label
  69. let levelShape = ""; //Circle; square
  70. let levelType = ""; // A - Place distance; B - Select blocks
  71. let levelMenu = true;
  72. //adding game states (scenes)
  73. game.state.add('language', langState); // preMenu.js
  74. game.state.add('load', loadState); // preMenu.js
  75. game.state.add('name', nameState); // preMenu.js
  76. game.state.add('menu', menuState); // menu.js
  77. game.state.add('map', mapState); // map.js
  78. game.state.add('menuCircleOne', menuCircleOne); // circleOne.js
  79. game.state.add('gameCircleOne', gameCircleOne); // circleOne.js
  80. game.state.add('endCircleOne', endCircleOne); // circleOne.js
  81. game.state.add('menuSquareOne', menuSquareOne); // squareOne.js
  82. game.state.add('gameSquareOne', gameSquareOne); // squareOne.js
  83. game.state.add('endSquareOne', endSquareOne); // squareOne.js
  84. game.state.add('menuSquareTwo', menuSquareTwo); // squareTwo.js
  85. game.state.add('gameSquareTwo', gameSquareTwo); // squareTwo.js
  86. game.state.add('endSquareTwo', endSquareTwo); // squareTwo.js
  87. let loadAssets = {
  88. preload: function(){
  89. //auxiliar directory
  90. const imgsrc = 'assets/img/';
  91. //Progress bar image
  92. game.load.image('progressBar', imgsrc+'pgbar.png');
  93. //flags
  94. game.load.image('flag_BR', imgsrc+'flag/BRAZ.jpg');
  95. game.load.image('flag_PE', imgsrc+'flag/PERU.jpg');
  96. game.load.image('flag_US', imgsrc+'flag/UNST.jpg');
  97. game.load.image('flag_FR', imgsrc+'flag/FRAN.jpg');
  98. game.load.image('flag_IT', imgsrc+'flag/ITAL.png');
  99. //scenario
  100. game.load.image('bgimage', imgsrc+'bg.jpg');
  101. game.load.image('bgmap', imgsrc+'bg_map.png');
  102. game.load.image('cloud', imgsrc+'cloud.png');
  103. game.load.image('floor', imgsrc+'floor.png');
  104. game.load.image('road', imgsrc+'road.png');
  105. //game phases buttons list
  106. this.levelSpriteList = [];
  107. let levelSpriteSource = [
  108. '1-left-subs.png', //square I
  109. '2-left-subs.png', //square II
  110. '3-left-subs.png', //circle I
  111. '4-left-subs.png', //circle II
  112. '5.png' //square III
  113. ];
  114. if(debugMode){
  115. levelSpriteSource.push(
  116. '5.png',
  117. '5.png',
  118. '5.png',
  119. '5.png',
  120. '5.png',
  121. '5.png',
  122. '5.png',
  123. '5.png'
  124. );
  125. }
  126. for(let i=0; i<levelSpriteSource.length; i++){
  127. this.levelSpriteList[i] = 'game'+i;
  128. game.load.image(this.levelSpriteList[i], imgsrc+'game/'+levelSpriteSource[i]);
  129. }
  130. this.levelShapeList = [
  131. 'Square',
  132. 'Square',
  133. 'Circle',
  134. 'Circle',
  135. 'Square',
  136. ];
  137. if(debugMode){
  138. this.levelShapeList.push(
  139. 'Square',
  140. 'Square',
  141. 'Square',
  142. 'Square',
  143. 'Square',
  144. 'Square',
  145. 'Square',
  146. 'Square'
  147. );
  148. }
  149. this.levelTypeList = [
  150. 1,
  151. 2,
  152. 1,
  153. 2,
  154. 3
  155. ];
  156. if(debugMode){
  157. this.levelTypeList.push(
  158. 3,
  159. 3,
  160. 3,
  161. 3,
  162. 3,
  163. 3,
  164. 3,
  165. 3
  166. );
  167. }
  168. //header menu buttons
  169. game.load.image('back', imgsrc+'menu/back.png');
  170. game.load.image('home', imgsrc+'menu/home.png');
  171. game.load.image('info', imgsrc+'menu/info.png');
  172. game.load.image('world', imgsrc+'menu/language.png');
  173. game.load.image('list', imgsrc+'menu/menu.png');
  174. game.load.image('help', imgsrc+'menu/help.png');
  175. game.load.image('pgbar', imgsrc+'menu/progressBar.png');
  176. game.load.image('block', imgsrc+'menu/block.png');
  177. game.load.spritesheet('audio', imgsrc+'menu/audio_48x48.png',48,48,2);
  178. //operators
  179. game.load.image('add', imgsrc+'operator/add.png');
  180. game.load.image('subtract', imgsrc+'operator/subtract.png');
  181. game.load.image('separator',imgsrc+'operator/separator.png');
  182. game.load.image('equal', imgsrc+'operator/equal.png');
  183. //feedback
  184. game.load.image('h_arrow', imgsrc+'help/arrow.png');
  185. game.load.image('h_double', imgsrc+'help/double.png');
  186. game.load.image('h_error', imgsrc+'help/error.png');
  187. game.load.image('h_ok', imgsrc+'help/ok.png');
  188. game.load.image('down', imgsrc+'help/down.png');
  189. game.load.image('pointer', imgsrc+'help/pointer.png');
  190. // Loading assets based on language
  191. game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
  192. game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 26);
  193. game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
  194. game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
  195. game.load.image('tractor_green', imgsrc+'tractor/frame-0.png');
  196. game.load.image('tractor_red', imgsrc+'tractor/frame-5.png');
  197. game.load.image('balloon', imgsrc+'airballoon_upper.png');
  198. game.load.image('balloon_basket', imgsrc+'airballoon_base.png');
  199. game.load.image('birch', imgsrc+'birch.png');
  200. game.load.image('flag', imgsrc+'flag.png');
  201. game.load.image('house', imgsrc+'house.png');
  202. game.load.image('place_a', imgsrc+'place_a.png');
  203. game.load.image('place_b', imgsrc+'place_b.png');
  204. game.load.image('garage', imgsrc+'garage.png');
  205. game.load.image('farm', imgsrc+'farm.png');
  206. game.load.image('rock', imgsrc+'rock.png');
  207. game.load.image('school', imgsrc+'school.png');
  208. game.load.image('sign', imgsrc+'sign.png');
  209. game.load.image('tree1', imgsrc+'tree.png');
  210. game.load.image('tree2', imgsrc+'tree2.png');
  211. game.load.image('tree3', imgsrc+'tree3.png');
  212. game.load.image('tree4', imgsrc+'tree4.png');
  213. // Loadind Sound Effects
  214. game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
  215. game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
  216. game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
  217. },
  218. create: function(){
  219. game.scaleMode = Phaser.ScaleManager.SHOW_ALL;
  220. game.scale.pageAlignHorizontally = true;
  221. game.scale.pageAlignVertically = true;
  222. game.physics.startSystem(Phaser.Physics.ARCADE);
  223. game.state.start('language');
  224. }
  225. };
  226. game.state.add('loadAssets', loadAssets); // boot.js
  227. // We finished loading everything and the first state is called
  228. game.state.start('loadAssets');