From b2634dfdb1e9e22cbeb6081c53faa03100711456 Mon Sep 17 00:00:00 2001 From: Mathis Decoster <mathis.decoster.etu@univ-lille.fr> Date: Thu, 28 Mar 2024 15:52:54 +0100 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20h=C3=A9ritage=20avec=20entite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/avatar.js | 19 +++---------------- client/src/entite.js | 29 +++++++++++++++++++++++++++++ server/enemis.js | 27 ++++++--------------------- 3 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 client/src/entite.js diff --git a/client/src/avatar.js b/client/src/avatar.js index 938ae23..a695173 100644 --- a/client/src/avatar.js +++ b/client/src/avatar.js @@ -1,31 +1,26 @@ import { Projectile } from './Projectile.js'; +import Entite from './entite.js'; import { Hitbox } from './hitbox.js'; -export class Avatar { - y; - x; +export class Avatar extends Entite { nom; vies; click; vitesse; - image; canvasSize; projectiles; score; - hitbox; inertie; momentumX; momentumY; constructor(nom, id, canvasSize) { + super(0, 0, new Hitbox(68, 145, 0, 0), null); this.nom = nom; this.score = 0; - this.y = 0; - this.x = 0; this.vies = 3; this.click = []; this.vitesse = 1; this.projectiles = []; - this.hitbox = new Hitbox(68, 145, this.x, this.y); this.inertie = 0.9; this.momentumX = 0; this.momentumY = 0; @@ -72,14 +67,6 @@ export class Avatar { return this.nom; } - getX() { - return this.x; - } - - getY() { - return this.y; - } - getClick() { return this.click; } diff --git a/client/src/entite.js b/client/src/entite.js new file mode 100644 index 0000000..f110993 --- /dev/null +++ b/client/src/entite.js @@ -0,0 +1,29 @@ +export default class Entite { + y; + x; + hitbox; + image; + + constructor(x, y, hitbox, image) { + this.x = x; + this.y = y; + this.hitbox = hitbox; + this.image = image; + } + + getX() { + return this.x; + } + + getY() { + return this.y; + } + + getImage() { + return this.image; + } + + getHitbox() { + return this.hitbox; + } +} diff --git a/server/enemis.js b/server/enemis.js index d32b225..655ef09 100644 --- a/server/enemis.js +++ b/server/enemis.js @@ -1,21 +1,19 @@ +import Entite from '../client/src/entite.js'; import { Hitbox } from '../client/src/hitbox.js'; -export default class enemi { - y; - x; +export default class enemi extends Entite { vy; vx; vies; - hitbox; - image; amplitude; direction; positionInitialeY; difficulté; constructor(x, y, image, difficulté) { - this.y = y; - this.x = x; - this.image = image; + super(x, y, new Hitbox(50 / 2, 66, x, y), image); + if (difficulté == 1) { + this.hitbox = new Hitbox(69 / 2, 57, this.x, this.y); + } this.difficulté = difficulté; this.vx = 3; this.vy = 0; @@ -23,11 +21,6 @@ export default class enemi { this.amplitude = 20; this.direction = 1; this.positionInitialeY = y; - if (difficulté == 1) { - this.hitbox = new Hitbox(69 / 2, 57, this.x, this.y); - } else { - this.hitbox = new Hitbox(50 / 2, 66, this.x, this.y); - } } colision(x, y, image) { @@ -43,14 +36,6 @@ export default class enemi { return this.vies; } - getX() { - return this.x; - } - - getY() { - return this.y; - } - getDifficulte() { return this.difficulté; } -- GitLab