Skip to content

Commit

Permalink
🪄Update new constant
Browse files Browse the repository at this point in the history
  • Loading branch information
huynq-fouj committed May 7, 2024
1 parent ff9a74f commit 46ad6cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions js/Fighter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Sprite } from "./Sprite.js";
import { DAMAGE, GRAVITY } from "./constant.js";
import { DAMAGE, GRAVITY, GROUNDHEIGHT } from "./constant.js";

export class Fighter extends Sprite {

Expand Down Expand Up @@ -55,10 +55,11 @@ export class Fighter extends Sprite {
}

//Gravity
const groundHeight = GROUNDHEIGHT ?? 0;
this.position.y += this.velocity.y;
if (this.position.y + this.height + this.velocity.y >= this.canvas.height - 100) {
if (this.position.y + this.height + this.velocity.y >= this.canvas.height - groundHeight) {
this.velocity.y = 0;
this.position.y = 330;
this.position.y = this.canvas.height - (groundHeight + this.height);
} else this.velocity.y += GRAVITY;
}

Expand Down
4 changes: 2 additions & 2 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const player = new Fighter({
},
offset: {
x: 90,
y:97,
y: 107,
},
imageSrc: '../images/Samurai/Idle.png',
framesMax: 6,
Expand Down Expand Up @@ -113,7 +113,7 @@ const enemy = new Fighter({
},
offset: {
x: 90,
y:100,
y:107,
},
imageSrc: '../images/Shinobi/Idle.png',
framesMax: 6,
Expand Down
3 changes: 2 additions & 1 deletion js/constant.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const GRAVITY = 0.5;
export const SPEED = 5;
export const DAMAGE = 10;
export const JUMP = 15;
export const JUMP = 15;
export const GROUNDHEIGHT = 87;

0 comments on commit 46ad6cd

Please sign in to comment.