one-way platforms
This commit is contained in:
@@ -10,4 +10,17 @@ export class Platform extends Phaser.GameObjects.Rectangle {
|
|||||||
scene.add.existing(this);
|
scene.add.existing(this);
|
||||||
scene.physics.add.existing(this, true);
|
scene.physics.add.existing(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Phaser collider processCallback: only collide when the mover is descending onto the top.
|
||||||
|
static canLand(
|
||||||
|
mover: Phaser.Types.Physics.Arcade.GameObjectWithBody,
|
||||||
|
platform: Phaser.Types.Physics.Arcade.GameObjectWithBody,
|
||||||
|
): boolean {
|
||||||
|
const moverBody = mover.body as Phaser.Physics.Arcade.Body;
|
||||||
|
const platBody = platform.body as Phaser.Physics.Arcade.StaticBody;
|
||||||
|
return (
|
||||||
|
moverBody.velocity.y >= 0 &&
|
||||||
|
moverBody.bottom - moverBody.deltaY() <= platBody.top
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export class GameScene extends Phaser.Scene {
|
|||||||
this.exit = loaded.exit;
|
this.exit = loaded.exit;
|
||||||
this.platforms = loaded.platforms;
|
this.platforms = loaded.platforms;
|
||||||
|
|
||||||
this.physics.add.collider(this.player, this.platforms);
|
this.physics.add.collider(this.player, this.platforms, undefined, Platform.canLand);
|
||||||
this.physics.add.overlap(this.player, this.exit, () => this.completeLevel());
|
this.physics.add.overlap(this.player, this.exit, () => this.completeLevel());
|
||||||
|
|
||||||
this.hudText = this.add.text(
|
this.hudText = this.add.text(
|
||||||
|
|||||||
Reference in New Issue
Block a user