boot.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. let loadAssets = {
  3. preload: function(){},
  4. create: function()
  5. ---------------------------- end of phaser functions
  6. };
  7. */
  8. // Global variables that still need checking
  9. //map
  10. let kid;
  11. //square 1 + circle 1
  12. let startX;
  13. let clicked, hideLabels, checkCollide, result, hasFigure;
  14. let detail;
  15. let endPosition;
  16. let fractionClicked, fractionIndex;
  17. let blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator; //blocks control
  18. //square 1
  19. let blockWidth, blockIndex;
  20. let floorBlocks, floorIndex, floorCount, floorClicked, curFloor;
  21. let move, moveCounter, moveEnd;
  22. let arrow;
  23. let arrowPlace;
  24. //circle 1
  25. let blockSize, blockAngle, blockTraceColor;
  26. let fly, flyCounter, flyend; //flyvariables
  27. let trace; //circle trace
  28. let numPlus, endIndex;
  29. let kid_walk, balloon, basket;
  30. let balloonPlace;
  31. //square 2
  32. let sizeA, sizeB, valueA, valueB;
  33. let clickA, clickB, animateA, animateB, animate, cDelay, eDelay;
  34. let blocksA, blocksB, auxblqA, auxblqB;
  35. let labelA, fractionA, separatorA, labelB, fractionB, separatorB;
  36. let kidDirection, equals, counter, endCounter;
  37. let xA, yA, xB, yB, blockW, blockH;
  38. // Game dimentions
  39. const defaultWidth = 900;
  40. const defaultHeight = 600;
  41. // Initialize phaser
  42. let game = new Phaser.Game(
  43. defaultWidth,
  44. defaultHeight,
  45. Phaser.CANVAS,
  46. 'fractions-game'
  47. );
  48. // META
  49. let username; // Player name
  50. let lang, langString; // Language object and language name
  51. let audioStatus = false; // Turns game audio ON/OFF
  52. let debugMode = true; // Turns console messages for developers ON/OFF (to be changed only by code)
  53. // GAME LEVELS
  54. let currentGameState; // Name of the current 'game' state
  55. let levelShape; // Can be 'circle' or 'square'
  56. /* LEVEL TYPE
  57. * in squareOne/circleOne can be: 'A' (click on the floor) or 'B' (click on the amount to go)
  58. * in squareTwo can be: 'C' (comparing fractions) */
  59. let levelType;
  60. let levelLabel = true; // Turns fraction labels ON/OFF
  61. /* SUBLEVEL TYPE
  62. * in squareOne/circleOne levels can be: 'Plus', 'Minus' or 'Mixed'
  63. * in squareTwo level can be: 'A', 'B' or 'C' */
  64. let sublevelType;
  65. let levelDifficulty; // Level difficulty: a value from 1 to 5 (depends on the level)
  66. let levelPosition; // Position of the character in the map
  67. let levelMove; // When true allows character to move to next position in the map
  68. let passedLevels; // Number of finished levels in the map
  69. // SOUNDS
  70. let beepSound, okSound, errorSound;
  71. // IMAGES
  72. let okImg, errorImg;
  73. // TIMER
  74. let timer, totalTime;
  75. // CONNECTION TO DATABASE
  76. const hip = "143.107.45.11"; // Host ip
  77. let loadAssets = {
  78. preload: function(){
  79. // Auxiliar string that holds the base directory
  80. const imgsrc = 'assets/img/';
  81. // Progress bar
  82. game.load.image('progressBar', imgsrc+'pgbar.png');
  83. // Flags
  84. game.load.image('flag_BR', imgsrc+'flag/BRAZ.jpg');
  85. game.load.image('flag_PE', imgsrc+'flag/PERU.jpg');
  86. game.load.image('flag_US', imgsrc+'flag/UNST.jpg');
  87. game.load.image('flag_FR', imgsrc+'flag/FRAN.jpg');
  88. game.load.image('flag_IT', imgsrc+'flag/ITAL.png');
  89. // Scenario
  90. game.load.image('bgimage', imgsrc+'bg.jpg');
  91. game.load.image('bgmap', imgsrc+'bg_map.png');
  92. game.load.image('cloud', imgsrc+'cloud.png');
  93. game.load.image('floor', imgsrc+'floor.png');
  94. game.load.image('road', imgsrc+'road.png');
  95. game.load.image('birch', imgsrc+'birch.png');
  96. game.load.image('house', imgsrc+'house.png');
  97. game.load.image('place_a', imgsrc+'place_a.png');
  98. game.load.image('place_b', imgsrc+'place_b.png');
  99. game.load.image('garage', imgsrc+'garage.png');
  100. game.load.image('farm', imgsrc+'farm.png');
  101. game.load.image('rock', imgsrc+'rock.png');
  102. game.load.image('school', imgsrc+'school.png');
  103. game.load.image('sign', imgsrc+'sign.png');
  104. game.load.image('tree1', imgsrc+'tree.png');
  105. game.load.image('tree2', imgsrc+'tree2.png');
  106. game.load.image('tree3', imgsrc+'tree3.png');
  107. game.load.image('tree4', imgsrc+'tree4.png');
  108. // Menu icons on the top of the page
  109. game.load.image('back', imgsrc+'menu/back.png');
  110. game.load.image('home', imgsrc+'menu/home.png');
  111. game.load.image('info', imgsrc+'menu/info.png');
  112. game.load.image('world', imgsrc+'menu/language.png');
  113. game.load.image('list', imgsrc+'menu/menu.png');
  114. game.load.image('help', imgsrc+'menu/help.png');
  115. game.load.image('pgbar', imgsrc+'menu/progressBar.png');
  116. game.load.image('block', imgsrc+'menu/block.png');
  117. game.load.spritesheet('audio', imgsrc+'menu/audio_48x48.png',48,48,2);
  118. // Mathematical operators
  119. game.load.image('add', imgsrc+'operator/add.png');
  120. game.load.image('subtract', imgsrc+'operator/subtract.png');
  121. game.load.image('separator',imgsrc+'operator/separator.png');
  122. game.load.image('equal', imgsrc+'operator/equal.png');
  123. // Feedback icons
  124. game.load.image('h_arrow', imgsrc+'help/arrow.png');
  125. game.load.image('h_double', imgsrc+'help/double.png');
  126. game.load.image('h_error', imgsrc+'help/error.png');
  127. game.load.image('h_ok', imgsrc+'help/ok.png');
  128. game.load.image('down', imgsrc+'help/down.png');
  129. game.load.image('pointer', imgsrc+'help/pointer.png');
  130. game.load.spritesheet('select', imgsrc+'help/selection_box.png', 310, 310, 2);
  131. // Game sprites
  132. game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
  133. game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 26);
  134. game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
  135. game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
  136. game.load.image('tractor_green', imgsrc+'tractor/frame-0.png');
  137. game.load.image('tractor_red', imgsrc+'tractor/frame-5.png');
  138. game.load.image('balloon', imgsrc+'airballoon_upper.png');
  139. game.load.image('balloon_basket', imgsrc+'airballoon_base.png');
  140. // Sound effects
  141. game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
  142. game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
  143. game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
  144. const levelSpriteSource = [
  145. 'squareOne_1.png', //square I
  146. 'squareOne_2.png', //square II
  147. 'circleOne_1.png', //circle I
  148. 'circleOne_2.png', //circle II
  149. 'squareTwo_3.png' //square III
  150. ];
  151. if(debugMode){
  152. levelSpriteSource.push(
  153. 'squareTwo_3.png',
  154. 'squareTwo_3.png',
  155. 'squareTwo_3.png',
  156. 'squareTwo_3.png',
  157. 'squareTwo_3.png',
  158. 'squareTwo_3.png',
  159. 'squareTwo_3.png',
  160. 'squareTwo_3.png'
  161. );
  162. }
  163. //game phases buttons list
  164. for(let i=0; i<levelSpriteSource.length; i++){
  165. game.load.image('game'+i, imgsrc+'game/'+levelSpriteSource[i]);
  166. }
  167. this.levelShapeList = [
  168. 'Square',
  169. 'Square',
  170. 'Circle',
  171. 'Circle',
  172. 'Square',
  173. ];
  174. if(debugMode){
  175. this.levelShapeList.push(
  176. 'Square',
  177. 'Square',
  178. 'Square',
  179. 'Square',
  180. 'Square',
  181. 'Square',
  182. 'Square',
  183. 'Square'
  184. );
  185. }
  186. this.levelTypeList = [
  187. 'A',
  188. 'B',
  189. 'A',
  190. 'B',
  191. 'C'
  192. ];
  193. if(debugMode){
  194. this.levelTypeList.push(
  195. 'C',
  196. 'C',
  197. 'C',
  198. 'C',
  199. 'C',
  200. 'C',
  201. 'C',
  202. 'C'
  203. );
  204. }
  205. },
  206. create: function(){
  207. // Centers phaser canvas in its containing div
  208. game.scaleMode = Phaser.ScaleManager.SHOW_ALL;
  209. game.scale.pageAlignHorizontally = true;
  210. game.scale.pageAlignVertically = true;
  211. // Enable phaser Arcade Physics system
  212. game.physics.startSystem(Phaser.Physics.ARCADE);
  213. //loading game sounds
  214. beepSound = game.add.audio('sound_beep'); // game sound
  215. okSound = game.add.audio('sound_ok'); // correct answer sound
  216. errorSound = game.add.audio('sound_error'); // wrong answer sound
  217. // Calls first screen seen by the player
  218. game.state.start('language');
  219. }
  220. };
  221. // Adding game states
  222. game.state.add('language', langState); // preMenu.js
  223. game.state.add('load', loadState); // preMenu.js
  224. game.state.add('name', nameState); // preMenu.js
  225. game.state.add('menu', menuState); // menu.js
  226. game.state.add('map', mapState); // map.js
  227. game.state.add('difficulty', difficultyState); // difficulty.js
  228. game.state.add('gameCircleOne', gameCircleOne); // circleOne.js
  229. game.state.add('gameSquareOne', gameSquareOne); // squareOne.js
  230. game.state.add('gameSquareTwo', gameSquareTwo); // squareTwo.js
  231. game.state.add('end', endState); // end.js
  232. game.state.add('loadAssets', loadAssets); // boot.js
  233. // Calls the first game state in charge of loading all the assets needed for the game
  234. game.state.start('loadAssets');