diff --git a/client/src/avatar.js b/client/src/avatar.js index c2e7c595c5332d0a71287fdd32e22e6b6f8def49..5abd0b2a7cedfdd692a8ae69404570ce8c1075ab 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 9973a4f21ec44d49c35ff46e8dc529af36340dd0..db25fa1288f699fff2857a76358ef68a795a126e 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 f98cb2d0e7a977cd2372d0e17e2f8aae94a15da6..5572b507ed43e938a54a17bd21c7df1791d62f71 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 14a6d13e89b9cb22f737cca2f17bb5b2b3be8234..928f8f2ab15adfff84b835988636a32a56f0a48a 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() {