From c943b14ae14a83c201f85049b72293a856cf5893 Mon Sep 17 00:00:00 2001 From: Paolo Brasolin <paolo.brasolin@eurac.edu> Date: Tue, 29 Mar 2022 11:46:15 +0200 Subject: [PATCH] fix: #fe player/critters falling through ground on big screens --- CHANGELOG.md | 5 +++++ frontend/src/js/critter.ts | 2 +- frontend/src/js/fight_scene.ts | 35 ++++++++++++++++++++++++---------- frontend/src/js/spear.ts | 4 +++- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd2c31e..90dc30b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `FE` player doesn't fall through ground on big screens. +- `FE` animals don't fall through ground on big screens. + ## [0.3.0] - 2022-03-24 ### Added diff --git a/frontend/src/js/critter.ts b/frontend/src/js/critter.ts index b0a64b1..0244be9 100644 --- a/frontend/src/js/critter.ts +++ b/frontend/src/js/critter.ts @@ -35,7 +35,7 @@ class Critter extends Phaser.Physics.Arcade.Sprite { this.body = new Phaser.Physics.Arcade.Body(this.scene.physics.world, this); this.scene.physics.world.add(this.body); - this.scene.physics.add.collider(this, this.scene.ground); + this.setCollideWorldBounds(true); this.setScale(scale); diff --git a/frontend/src/js/fight_scene.ts b/frontend/src/js/fight_scene.ts index f73fbd8..ca55c19 100644 --- a/frontend/src/js/fight_scene.ts +++ b/frontend/src/js/fight_scene.ts @@ -19,7 +19,6 @@ interface InputStatus { export default class FightScene extends Phaser.Scene { foes: Array<Foe>; - ground: Phaser.Types.Physics.Arcade.ImageWithStaticBody; player: Phaser.Types.Physics.Arcade.SpriteWithDynamicBody; cluesGroup: Phaser.Physics.Arcade.Group; beGame: Types.Game; @@ -32,7 +31,6 @@ export default class FightScene extends Phaser.Scene { } preload() { - this.load.image("ground", "assets/background_layers/ground.png"); this.load.spritesheet("oezi", "assets/sprites/player/oezi.png", { frameWidth: 27, frameHeight: 35, @@ -97,12 +95,29 @@ export default class FightScene extends Phaser.Scene { createAnim(this, "hit", "hit", 0, 9); createAnim(this, "missing", "miss", 0, 6); - this.ground = this.physics.add - .staticImage(0, this.cameras.main.height - 25, "ground") - .refreshBody() - .setImmovable(true); - // TODO: re-enable - //this.ground.body.allowGravity = false; + this.physics.world.setBounds( + 0, + 0, + this.cameras.main.width, + this.cameras.main.height - 30, + false, + false, + false, + true, + ); + + this.physics.world.on( + "worldbounds", + function ( + body: Phaser.Physics.Arcade.Body, + up: boolean, + down: boolean, + left: boolean, + right: boolean, + ) { + body.gameObject.emit("hitWorldBounds", { up, down, left, right }); + }, + ); this.player = this.physics.add .sprite( @@ -117,7 +132,7 @@ export default class FightScene extends Phaser.Scene { this.player.play({ key: "player_run" }); - this.physics.add.collider(this.player, this.ground); + this.player.setCollideWorldBounds(true); this.tweens.add({ targets: this.player, @@ -125,7 +140,7 @@ export default class FightScene extends Phaser.Scene { ease: "Power2", duration: 2000, onComplete: () => { - setAnimation(this.player, "player_idle"); + setAnimation(this.player, "player_run"); }, }); diff --git a/frontend/src/js/spear.ts b/frontend/src/js/spear.ts index 784e868..d363095 100644 --- a/frontend/src/js/spear.ts +++ b/frontend/src/js/spear.ts @@ -28,7 +28,9 @@ class Spear extends Phaser.Physics.Arcade.Sprite { //scene.physics.world.enableBody(this, Phaser.Physics.Arcade.DYNAMIC_BODY); this.body = new Phaser.Physics.Arcade.Body(scene.physics.world, this); scene.physics.world.add(this.body); - scene.physics.add.collider(this, scene.ground, this.hitGround.bind(this)); + this.setCollideWorldBounds(true, 0, 0.2); + this.body.onWorldBounds = true; + this.on("hitWorldBounds", this.hitGround.bind(this)); this.body.setBounce(0, 0.2); // TODO: bounce only at small angles if (this.target) { -- GitLab