diff --git a/src/app.js b/src/app.js index c2d5a1a..8101014 100644 --- a/src/app.js +++ b/src/app.js @@ -10,6 +10,8 @@ class GameScene extends Phaser.Scene { frameHeight: 20, }); + // TODO 1: load the tileset and tilemap with keys of "tileset" and "map" respectively. + this.load.image("wallHorizontal", "assets/wallHorizontal.png"); this.load.image("wallVertical", "assets/wallVertical.png"); @@ -53,7 +55,8 @@ class GameScene extends Phaser.Scene { // Make the player collide with walls this.physics.add.collider(this.player, this.walls); - this.coin = this.physics.add.sprite(60, 130, "coin"); + this.coin = this.physics.add.sprite(0, 0, "coin"); + this.moveCoin(); // Display the score this.scoreLabel = this.add.text(30, 25, "score: 0", { @@ -81,14 +84,19 @@ class GameScene extends Phaser.Scene { this.jumpSound = this.sound.add("jump"); this.coinSound = this.sound.add("coin"); this.deadSound = this.sound.add("dead"); + + // TODO 4.2: Add emitter for particle system. } /** * Creates the walls of the game */ createWalls() { + // TODO 2.1: comment out manual wall creation this.walls = this.physics.add.staticGroup(); + // TODO 4.1: import pixel as "pixel" from "assets/pixel.png" + this.walls.create(10, 170, "wallVertical"); // Left this.walls.create(490, 170, "wallVertical"); // Right @@ -101,6 +109,16 @@ class GameScene extends Phaser.Scene { this.walls.create(500, 170, "wallHorizontal"); // Middle right this.walls.create(250, 90, "wallHorizontal"); // Middle top this.walls.create(250, 250, "wallHorizontal"); // Middle bottom + + // TODO 2.2: create a tilemap called map with this.add.tilemap() + // the first parameter is the name of the tilemap in preload() + + // TODO 2.3: add the tileset to the tilemap with map.addTilesetImage(tilesetName, key) + // the first parameter is the name of the tileset in Tiled + // the second parameter is the name of the tileset in preload() + + // TODO 2.4: Enable collisions for the first tile (the blue walls) with the setCollision() method + } /** @@ -110,6 +128,9 @@ class GameScene extends Phaser.Scene { * check for win conditions, etc. */ update() { + + // TODO 5.1: + this.movePlayer(); this.checkCoinCollisions(); @@ -211,10 +232,10 @@ class GameScene extends Phaser.Scene { // bounce back in the opposite direction without losing speed enemy.body.bounce.x = 1; - // destroy the enemy after 10 seconds + // destroy the enemy after 15 seconds // this is roughly how long it takes to fall through the hole this.time.addEvent({ - delay: 10000, + delay: 15000, callback: () => enemy.destroy(), }); } @@ -223,12 +244,17 @@ class GameScene extends Phaser.Scene { * Called when the player dies. Restart the game */ handlePlayerDeath() { + // TODO 5.1: EXPLODE!! this.scene.restart(); this.deadSound.play(); + + // TODO 5.2: Instead of immediately restarting the game, add a delay + // Hint: see addEnemy() + } } - +// TODO 3.1: Update the map config so that the width is 800 and the height is 560 const config = { type: Phaser.AUTO, width: 500,