]> git.lizzy.rs Git - dragonblocks.git/commitdiff
Fix jumping bugs
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 25 Jun 2021 21:15:22 +0000 (23:15 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 25 Jun 2021 21:15:22 +0000 (23:15 +0200)
engine/spawned_entity.js

index e35e01d590bd67da984aefd9a70708f5f2b988d6..8d4757b9e85dbc0c69c04cd15322bac93bb5a8c4 100644 (file)
@@ -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()