diff --git a/CHANGELOG.md b/CHANGELOG.md index cd2c31e4f614162dfb241ed2c47273e1ad51f7fc..90dc30b3d799fda895c9958dfd0e179b615d198f 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 b0a64b168e0083a6dd2446a808c92f1a108a2178..0244be99fbf52dd62a3e6c07370f580122199e78 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 f73fbd82fa1e86bce8e841595aaf5d0a34a7a323..ca55c193f697e3ee8be37a4c1c90f588b3867cdc 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 784e868d6e3f5d08e43c3d6565eeb206c953933d..d36309578191347b98e7ce0f700600902ecf8136 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) {