Skip to content

Workshop 3 starter #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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", {
Expand Down Expand Up @@ -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

Expand All @@ -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

}

/**
Expand All @@ -110,6 +128,9 @@ class GameScene extends Phaser.Scene {
* check for win conditions, etc.
*/
update() {

// TODO 5.1:

this.movePlayer();
this.checkCoinCollisions();

Expand Down Expand Up @@ -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(),
});
}
Expand All @@ -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,
Expand Down