feat(character): restrict jumping to when on a platform

Change the jump() condition from checking velocity to detecting whether the character's feet are touching a platform. This prevents mid-air jumps and makes jump behavior more intuitive for platformer gameplay.
This commit is contained in:
2026-06-24 20:00:25 +03:00
parent e258330757
commit 5ccf54d00c
2 changed files with 22 additions and 1 deletions

8
README.md Normal file
View File

@@ -0,0 +1,8 @@
## How to run
Simply run:
```python
python3 -m http.server 8081
```
Inside of the project's cloned folder

View File

@@ -10,7 +10,20 @@ var c = {
size: 50, size: 50,
img: null, img: null,
jump() { jump() {
if ( this.velocity <= 0.15 ) { const feet = this.pos.y + this.size;
const onPlatform = getPlatforms().some(p => {
const overlapsX =
this.pos.x + this.size > p.position.x &&
this.pos.x < p.position.x + p.size.x;
const touchesTop =
Math.abs(feet - p.position.y) < 2;
return overlapsX && touchesTop;
});
if (onPlatform) {
this.velocity.y = -5; this.velocity.y = -5;
} }
}, },