From 5ccf54d00c7cfbe5c24d7190187d237130a7330d Mon Sep 17 00:00:00 2001 From: Daniel Legt Date: Wed, 24 Jun 2026 20:00:25 +0300 Subject: [PATCH] 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. --- README.md | 8 ++++++++ character.js | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..14ce62f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +## How to run + +Simply run: +```python +python3 -m http.server 8081 +``` + +Inside of the project's cloned folder \ No newline at end of file diff --git a/character.js b/character.js index ecb9345..b300619 100644 --- a/character.js +++ b/character.js @@ -10,7 +10,20 @@ var c = { size: 50, img: null, 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; } },