boot.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Start phaser
  2. const game = new Phaser.Game(
  3. defaultWidth,
  4. defaultHeight,
  5. Phaser.CANVAS,
  6. 'fractions-game'
  7. );
  8. // Game state : preload progress bar icon to use while preloading game assets
  9. let loadProgressBar = {
  10. preload: function () {
  11. game.load.image('progressBar', imgsrc + 'scenario/pgbar.png');
  12. },
  13. create: function () {
  14. game.state.start('loadAssets');
  15. }
  16. };
  17. // Game state : Load assets (and calls first game screen)
  18. let loadAssets = {
  19. preload: function () {
  20. // Create progress bar
  21. const progressBar = game.add.sprite(game.world.centerX, game.world.centerY, 'progressBar');
  22. progressBar.anchor.setTo(0.5, 0.5);
  23. // Executes progress bar untill the end of preload function
  24. game.load.setPreloadSprite(progressBar);
  25. // Sets default background color (persistent through screen changes)
  26. game.stage.backgroundColor = colors.blueBckg;
  27. // Loading assets
  28. loadAudios(media.boot('audio'));
  29. for (let i = 0, image = media.boot('image'); i < image.length; i++) {
  30. game.load.image(image[i][0], image[i][1]);
  31. }
  32. for (let i = 0, sprite = media.boot('spritesheet'); i < sprite.length; i++) {
  33. game.load.spritesheet(sprite[i][0], sprite[i][1], sprite[i][2], sprite[i][3], sprite[i][4]);
  34. }
  35. },
  36. create: function () {
  37. // Centers phaser canvas in its containing div
  38. game.scaleMode = Phaser.ScaleManager.SHOW_ALL;
  39. game.scale.pageAlignHorizontally = true;
  40. game.scale.pageAlignVertically = true;
  41. // Enable phaser Arcade Physics system
  42. game.physics.startSystem(Phaser.Physics.ARCADE);
  43. // Calls first screen seen by the player
  44. game.state.start('language');
  45. }
  46. };
  47. // Adding game states
  48. game.state.add('language', langState); // preMenu.js
  49. game.state.add('load', loadState); // preMenu.js
  50. game.state.add('name', nameState); // preMenu.js
  51. game.state.add('menu', menuState); // menu.js
  52. game.state.add('map', mapState); // map.js
  53. game.state.add('end', endState); // map.js
  54. game.state.add('difficulty', difficultyState); // difficulty.js
  55. game.state.add('gameCircleOne', gameCircleOne); // circleOne.js
  56. game.state.add('gameSquareOne', gameSquareOne); // squareOne.js
  57. game.state.add('gameSquareTwo', gameSquareTwo); // squareTwo.js
  58. game.state.add('loadProgressBar', loadProgressBar); // boot.js
  59. game.state.add('loadAssets', loadAssets); // boot.js
  60. // Calls first game state
  61. game.state.start('loadProgressBar');