end.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /******************************
  2. * This file holds game states.
  3. ******************************/
  4. /** [ENDING STATE] Ending screen shown when the player has completed all 4 levels and therefore completed the game.
  5. *
  6. * @namespace
  7. */
  8. const endState = {
  9. /**
  10. * Main code
  11. */
  12. create: function () {
  13. self.preAnimate = false;
  14. self.animate = true;
  15. renderBackground();
  16. // Progress bar
  17. const y = 20;
  18. game.add.geom.rect(
  19. context.canvas.width - 300,
  20. y,
  21. 4 * 37.5,
  22. 35,
  23. undefined,
  24. 0,
  25. colors.greenNeon,
  26. 0.5
  27. );
  28. game.add.geom.rect(
  29. context.canvas.width - 300 + 1,
  30. y + 1,
  31. 149,
  32. 34,
  33. colors.blue,
  34. 3,
  35. undefined,
  36. 1
  37. );
  38. game.add.text(
  39. context.canvas.width - 300 + 160,
  40. y + 33,
  41. '100%',
  42. textStyles.h2_blueDark
  43. ).align = 'left';
  44. game.add.text(
  45. context.canvas.width - 300 - 10,
  46. y + 33,
  47. game.lang.difficulty + ' ' + gameDifficulty,
  48. textStyles.h2_blueDark
  49. ).align = 'right';
  50. game.add
  51. .image(360 + 400, context.canvas.height - 100, 'tree_4', 1.05)
  52. .anchor(0, 1);
  53. gameList[gameId].assets.end.building();
  54. this.character = gameList[gameId].assets.end.character();
  55. this.character.animation = gameList[gameId].assets.end.characterAnimation;
  56. if (gameName === 'circleOne') {
  57. this.preAnimate = true;
  58. this.animate = false;
  59. // Balloon
  60. this.balloon = game.add.image(0, -260, 'balloon', 1.5);
  61. this.balloon.anchor(0.5, 0.5);
  62. this.basket = game.add.image(0, -150, 'balloon_basket', 1.5);
  63. this.basket.anchor(0.5, 0.5);
  64. }
  65. if (this.animate) game.animation.play(this.character.animation[0]);
  66. game.add
  67. .image(30 + 200, context.canvas.height - 20, 'tree_4', 1.275)
  68. .anchor(0, 1);
  69. },
  70. /**
  71. * Game loop
  72. */
  73. update: function () {
  74. if (isDebugMode && debugState.end.status) {
  75. if (debugState.end.stop) {
  76. self.animate = false;
  77. }
  78. }
  79. // Balloon falling
  80. if (self.preAnimate) {
  81. if (self.character.y < 460) {
  82. self.balloon.y += 2;
  83. self.basket.y += 2;
  84. self.character.y += 2;
  85. self.balloon.x++;
  86. self.basket.x++;
  87. self.character.x++;
  88. } else {
  89. self.preAnimate = false;
  90. self.animate = true;
  91. game.animation.play(self.character.animation[0]);
  92. }
  93. }
  94. // Character running
  95. if (self.animate) {
  96. if (self.character.x <= 700) {
  97. self.character.x += 2;
  98. } else {
  99. self.animate = false;
  100. game.animation.stop(self.character.animation[0]);
  101. // FOR MOODLE
  102. if (!moodle) {
  103. completedLevels = 0;
  104. game.state.start('menu');
  105. } else {
  106. // FOR MOODLE
  107. parent.location.reload(true);
  108. }
  109. }
  110. }
  111. game.render.all();
  112. },
  113. };