diff --git a/client/src/avatar.js b/client/src/avatar.js index 938ae232d96e0e32e5b0542e317ef07e044f5244..a695173960245d2c6a1307a4502bfefbf3f59828 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 0000000000000000000000000000000000000000..f110993e8e6c215f748bb27cbaab3e93c788bbd0 --- /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 d32b2253b4604df442666390ab39bd6a7f2c3353..655ef098dfcdcb7a7203a75015c1994b3d5e4022 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é; }