boot.js 9.1 KB

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