boot.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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; //game 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. let gameStateString;
  64. // Game One : kid and truck
  65. let levelPosition = 0; //Map position
  66. let levelMove = false; //Move to next position
  67. let levelDifficulty = 0; //From one to five
  68. let levelOperator = ""; //Plus; Minus; Mixed
  69. let levelLabel= false; //Show block label
  70. let levelShape = ""; //Circle; square
  71. let levelType = ""; // A - Place distance; B - Select blocks
  72. let levelMenu = true;
  73. //adding game states (scenes)
  74. game.state.add('language', langState); // preMenu.js
  75. game.state.add('load', loadState); // preMenu.js
  76. game.state.add('name', nameState); // preMenu.js
  77. game.state.add('menu', menuState); // menu.js
  78. game.state.add('map', mapState); // map.js
  79. game.state.add('difficulty', difficultyState); // difficulty.js
  80. game.state.add('gameCircleOne', gameCircleOne); // circleOne.js
  81. game.state.add('gameSquareOne', gameSquareOne); // squareOne.js
  82. game.state.add('gameSquareTwo', gameSquareTwo); // squareTwo.js
  83. game.state.add('end', endState); // end.js
  84. let loadAssets = {
  85. preload: function(){
  86. // Auxiliar string that holds the base directory
  87. const imgsrc = 'assets/img/';
  88. // Progress bar
  89. game.load.image('progressBar', imgsrc+'pgbar.png');
  90. // Flags
  91. game.load.image('flag_BR', imgsrc+'flag/BRAZ.jpg');
  92. game.load.image('flag_PE', imgsrc+'flag/PERU.jpg');
  93. game.load.image('flag_US', imgsrc+'flag/UNST.jpg');
  94. game.load.image('flag_FR', imgsrc+'flag/FRAN.jpg');
  95. game.load.image('flag_IT', imgsrc+'flag/ITAL.png');
  96. // Scenario
  97. game.load.image('bgimage', imgsrc+'bg.jpg');
  98. game.load.image('bgmap', imgsrc+'bg_map.png');
  99. game.load.image('cloud', imgsrc+'cloud.png');
  100. game.load.image('floor', imgsrc+'floor.png');
  101. game.load.image('road', imgsrc+'road.png');
  102. game.load.image('birch', imgsrc+'birch.png');
  103. game.load.image('flag', imgsrc+'flag.png');
  104. game.load.image('house', imgsrc+'house.png');
  105. game.load.image('place_a', imgsrc+'place_a.png');
  106. game.load.image('place_b', imgsrc+'place_b.png');
  107. game.load.image('garage', imgsrc+'garage.png');
  108. game.load.image('farm', imgsrc+'farm.png');
  109. game.load.image('rock', imgsrc+'rock.png');
  110. game.load.image('school', imgsrc+'school.png');
  111. game.load.image('sign', imgsrc+'sign.png');
  112. game.load.image('tree1', imgsrc+'tree.png');
  113. game.load.image('tree2', imgsrc+'tree2.png');
  114. game.load.image('tree3', imgsrc+'tree3.png');
  115. game.load.image('tree4', imgsrc+'tree4.png');
  116. // Menu icons on the top of the page
  117. game.load.image('back', imgsrc+'menu/back.png');
  118. game.load.image('home', imgsrc+'menu/home.png');
  119. game.load.image('info', imgsrc+'menu/info.png');
  120. game.load.image('world', imgsrc+'menu/language.png');
  121. game.load.image('list', imgsrc+'menu/menu.png');
  122. game.load.image('help', imgsrc+'menu/help.png');
  123. game.load.image('pgbar', imgsrc+'menu/progressBar.png');
  124. game.load.image('block', imgsrc+'menu/block.png');
  125. game.load.spritesheet('audio', imgsrc+'menu/audio_48x48.png',48,48,2);
  126. // Mathematical operators
  127. game.load.image('add', imgsrc+'operator/add.png');
  128. game.load.image('subtract', imgsrc+'operator/subtract.png');
  129. game.load.image('separator',imgsrc+'operator/separator.png');
  130. game.load.image('equal', imgsrc+'operator/equal.png');
  131. // Feedback icons
  132. game.load.image('h_arrow', imgsrc+'help/arrow.png');
  133. game.load.image('h_double', imgsrc+'help/double.png');
  134. game.load.image('h_error', imgsrc+'help/error.png');
  135. game.load.image('h_ok', imgsrc+'help/ok.png');
  136. game.load.image('down', imgsrc+'help/down.png');
  137. game.load.image('pointer', imgsrc+'help/pointer.png');
  138. // Game sprites
  139. game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
  140. game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 26);
  141. game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
  142. game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
  143. game.load.image('tractor_green', imgsrc+'tractor/frame-0.png');
  144. game.load.image('tractor_red', imgsrc+'tractor/frame-5.png');
  145. game.load.image('balloon', imgsrc+'airballoon_upper.png');
  146. game.load.image('balloon_basket', imgsrc+'airballoon_base.png');
  147. // Sound effects
  148. game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
  149. game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
  150. game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
  151. const levelSpriteSource = [
  152. '1-left-subs.png', //square I
  153. '2-left-subs.png', //square II
  154. '3-left-subs.png', //circle I
  155. '4-left-subs.png', //circle II
  156. '5.png' //square III
  157. ];
  158. if(debugMode){
  159. levelSpriteSource.push(
  160. '5.png',
  161. '5.png',
  162. '5.png',
  163. '5.png',
  164. '5.png',
  165. '5.png',
  166. '5.png',
  167. '5.png'
  168. );
  169. }
  170. //game phases buttons list
  171. this.levelSpriteList = [];
  172. for(let i=0; i<levelSpriteSource.length; i++){
  173. this.levelSpriteList[i] = 'game'+i;
  174. game.load.image(this.levelSpriteList[i], imgsrc+'game/'+levelSpriteSource[i]);
  175. }
  176. this.levelShapeList = [
  177. 'Square',
  178. 'Square',
  179. 'Circle',
  180. 'Circle',
  181. 'Square',
  182. ];
  183. if(debugMode){
  184. this.levelShapeList.push(
  185. 'Square',
  186. 'Square',
  187. 'Square',
  188. 'Square',
  189. 'Square',
  190. 'Square',
  191. 'Square',
  192. 'Square'
  193. );
  194. }
  195. this.levelTypeList = [
  196. 1,
  197. 2,
  198. 1,
  199. 2,
  200. 3
  201. ];
  202. if(debugMode){
  203. this.levelTypeList.push(
  204. 3,
  205. 3,
  206. 3,
  207. 3,
  208. 3,
  209. 3,
  210. 3,
  211. 3
  212. );
  213. }
  214. },
  215. create: function(){
  216. // Centers phaser canvas in its containing div
  217. game.scaleMode = Phaser.ScaleManager.SHOW_ALL;
  218. game.scale.pageAlignHorizontally = true;
  219. game.scale.pageAlignVertically = true;
  220. // Enable phaser Arcade Physics system
  221. game.physics.startSystem(Phaser.Physics.ARCADE);
  222. //loading game sounds
  223. beepSound = game.add.audio('sound_beep'); // game sound
  224. okSound = game.add.audio('sound_ok'); // correct answer sound
  225. errorSound = game.add.audio('sound_error'); // wrong answer sound
  226. // Calls first screen seen by the player
  227. game.state.start('language');
  228. }
  229. };
  230. game.state.add('loadAssets', loadAssets); // boot.js
  231. // Calls the first game state in charge of loading all the assets needed for the game
  232. game.state.start('loadAssets');