From 0eea5a6cfbca190e4f26de5c9d3d0cd67d4a555c Mon Sep 17 00:00:00 2001 From: Mathis Decoster <mathis.decoster.etu@univ-lille.fr> Date: Wed, 27 Mar 2024 16:30:28 +0100 Subject: [PATCH] =?UTF-8?q?invincibilit=C3=A9=20et=20vie=20en=20plus=20op?= =?UTF-8?q?=C3=A9rationnelles=20en=20objet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/avatar.js | 17 ++++++++++++++--- client/src/bonus.js | 6 ++++-- client/src/main.js | 22 ++++++++++++++-------- client/src/timer.js | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/client/src/avatar.js b/client/src/avatar.js index c2e7c59..5abd0b2 100644 --- a/client/src/avatar.js +++ b/client/src/avatar.js @@ -13,6 +13,7 @@ export class Avatar extends Entite { momentumX; momentumY; statut; + statutTime; constructor(nom, vitesse) { super(0, 0, new Hitbox(68, 145, 0, 0), null); @@ -28,6 +29,8 @@ export class Avatar extends Entite { this.inertie = 0.95; this.momentumX = 0; this.momentumY = 0; + this.statut = 'null'; + this.statutTime = null; } incrementScore(nb) { @@ -54,6 +57,14 @@ export class Avatar extends Entite { }); } + getStatutTime() { + return this.statutTime; + } + + setStatutTime(t) { + this.statutTime = t; + } + setImageCanvas(image, canvas) { super.image = image; this.canvas = canvas; @@ -75,12 +86,12 @@ export class Avatar extends Entite { return this.click; } - setStatut(status) { - this.statut = status; + setStatut(statut) { + this.statut = statut; } getStatus() { - return this.status; + return this.statut; } colision(x, y, image) { diff --git a/client/src/bonus.js b/client/src/bonus.js index 9973a4f..db25fa1 100644 --- a/client/src/bonus.js +++ b/client/src/bonus.js @@ -1,19 +1,21 @@ import Entite from './entite.js'; import { Hitbox } from './hitbox.js'; +import { bonusImages } from './choixBonus.js'; export default class Bonus extends Entite { nom; taille; apparition; constructor(choix, taille, x, y, image, time) { - super(x, y, new Hitbox(image.width / 2, image.height, x, y), image); + super(x, y, new Hitbox(image.width, image.height, x, y), image); this.choix = choix; this.taille = taille; this.apparition = time; + this.image.src = bonusImages[choix]; } estExpire(t) { - return t - this.apparition >= 60; + return t - this.apparition == 60; } getChoix() { diff --git a/client/src/main.js b/client/src/main.js index f98cb2d..5572b50 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -104,22 +104,29 @@ document.addEventListener('keyup', event => { avatar.changerClick(event); }); -setInterval(genererBonus, 1000); +setInterval(genererBonus, 15000); function genererBonus() { if (gameStarted) { const choix = Math.floor(Math.random() * bonusNoms.length); let randomY = Math.floor(Math.random() * canvas.height); let randomX = Math.floor(Math.random() * canvas.width); let img = new Image(); - img.src = bonusImages[choix]; - img.width = 100; - img.height = 100; + img.width = 75; + img.height = 75; const bonus = new Bonus(choix, 1, randomX, randomY, img, t.getTotalTime()); bonusArray.push(bonus); } } setInterval(() => { + console.log(t.getTotalTime() - avatar.getStatutTime() == 15); + console.log(t.getTotalTime() - avatar.getStatutTime()); + if ( + avatar.getStatus() == 'invincibilite' && + t.getTotalTime() - avatar.getStatutTime() == 15 + ) { + avatar.setStatut('null'); + } avatar.deplacer(); avatar.projectiles.forEach(projectile => projectile.deplacer()); enemis.forEach(enemi => { @@ -165,11 +172,12 @@ setInterval(() => { if (bonusNoms[bonus.getChoix()] == 'vie') { avatar.gagnerVie(); } else if (bonusNoms[bonus.getChoix()] == 'invincibilite') { - console.log('INVICIBILITE'); avatar.setStatut('invincibilite'); + avatar.setStatutTime(t.getTotalTime()); } bonusArray.splice(bonusArray.indexOf(bonus), 1); - } else if (bonus.estExpire(t.getTotalTime())) { + } + if (bonus.estExpire(t.getTotalTime())) { bonusArray.splice(bonusArray.indexOf(bonus), 1); } }); @@ -221,7 +229,6 @@ function render() { }); } bonusArray.forEach(bonus => { - console.log(bonus); if ( bonus.x <= canvas.width - bonus.image.width && bonus.y <= canvas.height && @@ -235,7 +242,6 @@ function render() { }); enemis.forEach(enemi => { - console.log(enemi.getDifficulte()); if ( enemi.x <= canvas.width - enemi.image.width && enemi.y <= canvas.height && diff --git a/client/src/timer.js b/client/src/timer.js index 14a6d13..928f8f2 100644 --- a/client/src/timer.js +++ b/client/src/timer.js @@ -17,7 +17,7 @@ export default class timer { } getTotalTime() { - return 3600 * this.getHrs() + 60 * this.getMin() + this.getSec; + return 3600 * this.hrs + 60 * this.min + this.sec; } getSec() { -- GitLab