From: Elias Fleckenstein Date: Fri, 25 Jun 2021 21:15:22 +0000 (+0200) Subject: Fix jumping bugs X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=5344a9e7072c2f2b9563d2dfd6f9a1100223eef5;p=dragonblocks.git Fix jumping bugs --- diff --git a/engine/spawned_entity.js b/engine/spawned_entity.js index e35e01d..8d4757b 100644 --- a/engine/spawned_entity.js +++ b/engine/spawned_entity.js @@ -318,13 +318,36 @@ dragonblocks.SpawnedEntity = class this.physicsResetY(); } + canJump() + { + for (let x = Math.floor(this.x); x <= Math.ceil(this.x + this.width - 0.01) - 1; x++) { + let entityY = this.y + this.height; + let y = Math.ceil(entityY); + + if (y - entityY <= 0.01) { + let node = dragonblocks.getNode(x, y); + + if (! node) + return true; + + let nodeDef = node.toNode(); + + if (! nodeDef) + return true; + + if (nodeDef.mobstable) + return true; + } + } + } + jump() { - if (this.vy == -this.verticalSpeed) + if (! this.canJump()) return; this.jumping = true; - this.vy = -this.verticalSpeed; + this.vy = -this.verticalSpeed; } stopJump()