From 71bddad622fe8cf63a0fa1297eb916606dfd72d9 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 04:42:30 +0000 Subject: [PATCH 1/9] Smooth Movement --- assets/js/platformer3x/Character.js | 13 ++++++- assets/js/platformer3x/PlayerBase.js | 51 +++++++++++++++++++++------- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/assets/js/platformer3x/Character.js b/assets/js/platformer3x/Character.js index 7bc6b7c8..c4f6b466 100644 --- a/assets/js/platformer3x/Character.js +++ b/assets/js/platformer3x/Character.js @@ -21,6 +21,9 @@ class Character extends GameObject { // gravity for character enabled by default this.gravityEnabled = true; this.onTop = false; + + // Velocity + this.yv = 0; } setSpriteAnimation(animation) { @@ -133,12 +136,20 @@ class Character extends GameObject { /** * Update the y posiion and update y related states */ + colY() { + while(!this.bottom > this.y && this.gravityEnabled) { + this.y += 1; + } + } + updateY() { if (this.bottom > this.y && this.gravityEnabled) { - this.y += GameEnv.gravity; + this.yv += GameEnv.gravity; this.onTop = false; } else { this.onTop = true; + this.yv = 0; + this.colY(); } } diff --git a/assets/js/platformer3x/PlayerBase.js b/assets/js/platformer3x/PlayerBase.js index c0f018a3..5fa81acf 100644 --- a/assets/js/platformer3x/PlayerBase.js +++ b/assets/js/platformer3x/PlayerBase.js @@ -67,6 +67,10 @@ export class PlayerBase extends Character { // Add event listeners document.addEventListener('keydown', this.keydownListener); document.addEventListener('keyup', this.keyupListener); + + // Velocity + this.xv = 0; + this.yv = 0; } /** @@ -101,11 +105,6 @@ export class PlayerBase extends Character { /** * gameLoop helper: Udate Player jump height */ - updateJump() { - // Jump height is 35% of the screen bottom, same as screen height - this.setY(this.y - (this.bottom * 0.35)); - } - /** * gameLoop: updates the player's movement based on the player's animation (idle, walk, run, jump, etc.) */ @@ -118,7 +117,7 @@ export class PlayerBase extends Character { if (this.state.movement.up && !this.state.movement.falling) { // jump GameEnv.playSound("PlayerJump"); - this.updateJump(); + this.yv = GameEnv.bottom * -0.06; // start falling this.state.movement.falling = true; } @@ -127,15 +126,33 @@ export class PlayerBase extends Character { // Player is moving left if (this.state.direction === 'left' && this.state.movement.left && 'a' in this.pressedKeys) { // Decrease the player's x position according to run or walk animation and related speed - this.setX(this.x - (this.state.animation === 'run' ? this.runSpeed : this.speed)); + if (this.state.animation === 'run') { + this.xv -= this.runSpeed; + } else { + this.xv -= this.speed; + } // Player is moving right } else if (this.state.direction === 'right' && this.state.movement.right && 'd' in this.pressedKeys){ // Increase the player's x position according to run or walk animation and related speed - this.setX(this.x + (this.state.animation === 'run' ? this.runSpeed : this.speed)); + if (this.state.animation === 'run') { + this.xv += this.runSpeed; + } else { + this.xv += this.speed; + } } } - GameEnv.PlayerPosition.playerX = this.x - GameEnv.PlayerPosition.playerY = this.y + + // Update X + this.xv *= 0.8; + this.x += this.xv; + this.setX(this.x); + + // Update Y + this.y += this.yv; + this.setY(this.y); + + GameEnv.PlayerPosition.playerX = this.x; + GameEnv.PlayerPosition.playerY = this.y; } @@ -333,16 +350,20 @@ export class PlayerBase extends Character { if (this.collisionData.touchPoints.this.onTopofOther) { this.state.movement = { up: false, down: false, left: true, right: true, falling: false}; this.gravityEnabled = false; + this.yv = 0; + this.y -= 1; // Player is touching the wall with right side } else if (this.collisionData.touchPoints.this.right) { this.state.movement = { up: false, down: false, left: true, right: false, falling: false}; - this.y -= 4; + this.x -= this.xv; + this.xv *= -1; // Player is touching the wall with left side } else if (this.collisionData.touchPoints.this.left) { this.state.movement = { up: false, down: false, left: false, right: true, falling: false}; - this.y -= 4; + this.x -= this.xv; + this.xv *= -1.5; } break; @@ -352,12 +373,18 @@ export class PlayerBase extends Character { if (this.collisionData.touchPoints.this.top && this.collisionData.touchPoints.other.bottom) { this.state.movement = { up: false, down: false, left: true, right: true, falling: false}; this.gravityEnabled = false; + this.yv = 0; + this.y -= 1; // Player is touching the wall with right side } else if (this.collisionData.touchPoints.this.right) { this.state.movement = { up: false, down: false, left: true, right: false, falling: false}; + this.x -= this.xv; + this.xv *= -1; // Player is touching the wall with left side } else if (this.collisionData.touchPoints.this.left) { this.state.movement = { up: false, down: false, left: false, right: true, falling: false}; + this.x -= this.xv; + this.xv *= -1; } break; From f345c623e189b3dd8dded29febe44df16511d65f Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 05:09:20 +0000 Subject: [PATCH 2/9] Hills/Boss Movement --- assets/js/platformer3x/PlayerBoss.js | 14 ++++++++------ assets/js/platformer3x/PlayerHills.js | 16 +++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/assets/js/platformer3x/PlayerBoss.js b/assets/js/platformer3x/PlayerBoss.js index dce09396..8ef13a9a 100644 --- a/assets/js/platformer3x/PlayerBoss.js +++ b/assets/js/platformer3x/PlayerBoss.js @@ -31,14 +31,16 @@ export class PlayerBoss extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } if (GameEnv.currentLevel.tag == "boss") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } /** * @override @@ -125,11 +127,11 @@ export class PlayerBoss extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.yv = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { diff --git a/assets/js/platformer3x/PlayerHills.js b/assets/js/platformer3x/PlayerHills.js index 534bfa03..48efbfdc 100644 --- a/assets/js/platformer3x/PlayerHills.js +++ b/assets/js/platformer3x/PlayerHills.js @@ -35,14 +35,16 @@ export class PlayerHills extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } if(GameEnv.currentLevel.tag == "boss"){ jumpHeightFactor = 0; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor + this.y += this.yv; + this.setY(this.y); } /** @@ -95,11 +97,11 @@ export class PlayerHills extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.yv = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.yv = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { @@ -127,11 +129,11 @@ export class PlayerHills extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { From 92c918dfadbb79655ab5286722a622e79532c4e7 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 05:13:25 +0000 Subject: [PATCH 3/9] Ice/Mini Movement --- assets/js/platformer3x/PlayerIce.js | 14 ++++++++------ assets/js/platformer3x/PlayerMini.js | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/assets/js/platformer3x/PlayerIce.js b/assets/js/platformer3x/PlayerIce.js index 016d8b36..26aee91f 100644 --- a/assets/js/platformer3x/PlayerIce.js +++ b/assets/js/platformer3x/PlayerIce.js @@ -40,13 +40,15 @@ export class PlayerIce extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.03; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } update(){ super.update(); @@ -84,11 +86,11 @@ export class PlayerIce extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { diff --git a/assets/js/platformer3x/PlayerMini.js b/assets/js/platformer3x/PlayerMini.js index 8ef1fe04..99e1fadc 100644 --- a/assets/js/platformer3x/PlayerMini.js +++ b/assets/js/platformer3x/PlayerMini.js @@ -39,13 +39,15 @@ export class PlayerMini extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.03; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } update(){ super.update(); @@ -104,11 +106,11 @@ export class PlayerMini extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { From 789f0f6147f8df01e82da3c833b0c80161f9d189 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 05:14:51 +0000 Subject: [PATCH 4/9] Hogwarts/Quidditch Movement --- assets/js/platformer3x/PlayerMiniHogwarts.js | 14 ++++++++------ assets/js/platformer3x/PlayerQuidditch.js | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/assets/js/platformer3x/PlayerMiniHogwarts.js b/assets/js/platformer3x/PlayerMiniHogwarts.js index a114ad0b..6d724e8b 100644 --- a/assets/js/platformer3x/PlayerMiniHogwarts.js +++ b/assets/js/platformer3x/PlayerMiniHogwarts.js @@ -39,13 +39,15 @@ export class PlayerMiniHogwarts extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.03; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } update(){ super.update(); @@ -104,11 +106,11 @@ export class PlayerMiniHogwarts extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { diff --git a/assets/js/platformer3x/PlayerQuidditch.js b/assets/js/platformer3x/PlayerQuidditch.js index 2199739f..6419f6a6 100644 --- a/assets/js/platformer3x/PlayerQuidditch.js +++ b/assets/js/platformer3x/PlayerQuidditch.js @@ -35,13 +35,15 @@ export class PlayerQuidditch extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.03; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } /** @@ -117,11 +119,11 @@ export class PlayerQuidditch extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250; + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { From 4c6f4081634a3e874461473d928fd99b68209f1e Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 05:16:36 +0000 Subject: [PATCH 5/9] Skibidi/Winter Movement --- assets/js/platformer3x/PlayerSkibidi.js | 14 ++++++++------ assets/js/platformer3x/PlayerWinter.js | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/assets/js/platformer3x/PlayerSkibidi.js b/assets/js/platformer3x/PlayerSkibidi.js index d12307b2..326918ed 100644 --- a/assets/js/platformer3x/PlayerSkibidi.js +++ b/assets/js/platformer3x/PlayerSkibidi.js @@ -35,13 +35,15 @@ export class PlayerSkibidi extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.03; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } /** @@ -93,11 +95,11 @@ export class PlayerSkibidi extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { diff --git a/assets/js/platformer3x/PlayerWinter.js b/assets/js/platformer3x/PlayerWinter.js index 4a01f013..e1cbfb67 100644 --- a/assets/js/platformer3x/PlayerWinter.js +++ b/assets/js/platformer3x/PlayerWinter.js @@ -32,17 +32,18 @@ export class PlayerWinter extends PlayerBase { * @override * gameLoop helper: Update Player jump height, replaces PlayerBase updateJump using settings from GameEnv */ - updateJump() { + updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; + } else { + jumpHeightFactor = 0.03; } - if (GameEnv.currentLevel.tag == "narwhalboss") { - jumpHeightFactor = 0.50; - } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } /** @@ -98,11 +99,11 @@ export class PlayerWinter extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { @@ -130,11 +131,11 @@ export class PlayerWinter extends PlayerBase { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { From b82559093df2727a755cc588eb5445dd750f1553 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 05:18:14 +0000 Subject: [PATCH 6/9] Zombie Movement --- assets/js/platformer3x/PlayerZombie.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/assets/js/platformer3x/PlayerZombie.js b/assets/js/platformer3x/PlayerZombie.js index 7dd31c69..74af4eae 100644 --- a/assets/js/platformer3x/PlayerZombie.js +++ b/assets/js/platformer3x/PlayerZombie.js @@ -29,17 +29,18 @@ export class PlayerZombie extends PlayerBaseOneD { * @override * gameLoop helper: Update Player jump height, replaces PlayerBase updateJump using settings from GameEnv */ - updateJump() { + updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; + jumpHeightFactor = 0.04; + } else { + jumpHeightFactor = 0.05; } - if (GameEnv.currentLevel.tag == "boss") { - jumpHeightFactor = 0.50; - } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + this.yv = -this.bottom * jumpHeightFactor; + this.y += this.yv; + this.setY(this.y); } /** * @override @@ -247,11 +248,11 @@ export class PlayerZombie extends PlayerBaseOneD { // GoombaBounce deals with player.js and goomba.js if (GameEnv.goombaBounce === true) { GameEnv.goombaBounce = false; - this.y = this.y - 100; + this.y = -10; } if (GameEnv.goombaBounce1 === true) { GameEnv.goombaBounce1 = false; - this.y = this.y - 250 + this.y = -25; } // 2. Player touches goomba sides of goomba } else if (this.collisionData.touchPoints.this.right || this.collisionData.touchPoints.this.left) { From 31c87cf8fccf9ada915a1dc7193f9141be65a4f4 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Tue, 28 May 2024 20:34:38 +0000 Subject: [PATCH 7/9] Movement Update 1 --- assets/js/platformer3x/PlayerBase.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/js/platformer3x/PlayerBase.js b/assets/js/platformer3x/PlayerBase.js index 06dc7456..df2b643b 100644 --- a/assets/js/platformer3x/PlayerBase.js +++ b/assets/js/platformer3x/PlayerBase.js @@ -155,7 +155,6 @@ export class PlayerBase extends Character { GameEnv.PlayerPosition.playerX = this.x; GameEnv.PlayerPosition.playerY = this.y; - } /** @@ -375,8 +374,8 @@ export class PlayerBase extends Character { if (this.collisionData.touchPoints.this.top && this.collisionData.touchPoints.other.bottom) { this.state.movement = { up: false, down: false, left: true, right: true, falling: false}; this.gravityEnabled = false; + this.y -= this.yv; this.yv = 0; - this.y -= 1; // Player is touching the wall with right side } else if (this.collisionData.touchPoints.this.right) { this.state.movement = { up: false, down: false, left: true, right: false, falling: false}; @@ -396,6 +395,8 @@ export class PlayerBase extends Character { // Player is on the floor if (this.onTop) { this.state.movement = { up: false, down: false, left: true, right: true, falling: false}; + this.y -= this.yv; + this.yv = 0; // Player is falling, there are no collisions, but is in default state } else { this.state.movement = { up: false, down: false, left: true, right: true, falling: true}; From 56bc65599e1c5ed30507a932f88a0b39428e4ec2 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Wed, 29 May 2024 20:53:22 +0000 Subject: [PATCH 8/9] Greece Update Movement --- assets/js/platformer3x/PlayerGreece.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/js/platformer3x/PlayerGreece.js b/assets/js/platformer3x/PlayerGreece.js index 1404c908..0218a5c2 100644 --- a/assets/js/platformer3x/PlayerGreece.js +++ b/assets/js/platformer3x/PlayerGreece.js @@ -35,16 +35,19 @@ export class PlayerGreece extends PlayerBase { * @override * gameLoop helper: Update Player jump height, replaces PlayerBase updateJump using settings from GameEnv */ - updateJump() { + updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.50; + jumpHeightFactor = 0.05; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.40; - } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.04; } - this.setY(this.y - (this.bottom * jumpHeightFactor)); + if(GameEnv.currentLevel.tag == "boss"){ + jumpHeightFactor = 0; + } + this.yv = -this.bottom * jumpHeightFactor + this.y += this.yv; + this.setY(this.y); } drawHpBox() { //Hp box // Position and size of the health bar From 4c9e026e23c791beb0bbb46dc67a9a7dcbdb7b04 Mon Sep 17 00:00:00 2001 From: Frogpants Date: Wed, 29 May 2024 21:03:25 +0000 Subject: [PATCH 9/9] Character Update --- assets/js/platformer3x/Character.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/assets/js/platformer3x/Character.js b/assets/js/platformer3x/Character.js index c4f6b466..c38def1c 100644 --- a/assets/js/platformer3x/Character.js +++ b/assets/js/platformer3x/Character.js @@ -137,19 +137,24 @@ class Character extends GameObject { * Update the y posiion and update y related states */ colY() { - while(!this.bottom > this.y && this.gravityEnabled) { - this.y += 1; + while (!this.bottom > this.y) { + if (this.yv < 0) { + this.yv += 1; + } else { + this.yv -= 1; + } } } updateY() { if (this.bottom > this.y && this.gravityEnabled) { this.yv += GameEnv.gravity; + this.yv *= 0.9; this.onTop = false; } else { - this.onTop = true; - this.yv = 0; this.colY(); + this.yv = 0; + this.onTop = true; } }