From 46ad6cdeaaca893ef92cc61bee53b5ebd26230a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Quang=20Huy?= Date: Tue, 7 May 2024 17:44:40 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=84Update=20new=20constant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/Fighter.js | 7 ++++--- js/app.js | 4 ++-- js/constant.js | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/js/Fighter.js b/js/Fighter.js index 82a314f..ec2dba1 100644 --- a/js/Fighter.js +++ b/js/Fighter.js @@ -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 { @@ -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; } diff --git a/js/app.js b/js/app.js index 4be890c..6beb83c 100644 --- a/js/app.js +++ b/js/app.js @@ -31,7 +31,7 @@ const player = new Fighter({ }, offset: { x: 90, - y:97, + y: 107, }, imageSrc: '../images/Samurai/Idle.png', framesMax: 6, @@ -113,7 +113,7 @@ const enemy = new Fighter({ }, offset: { x: 90, - y:100, + y:107, }, imageSrc: '../images/Shinobi/Idle.png', framesMax: 6, diff --git a/js/constant.js b/js/constant.js index d812c14..039d29c 100644 --- a/js/constant.js +++ b/js/constant.js @@ -1,4 +1,5 @@ export const GRAVITY = 0.5; export const SPEED = 5; export const DAMAGE = 10; -export const JUMP = 15; \ No newline at end of file +export const JUMP = 15; +export const GROUNDHEIGHT = 87; \ No newline at end of file