Skip to content
Snippets Groups Projects
Commit 0eea5a6c authored by Mathis Decoster's avatar Mathis Decoster :apple:
Browse files

invincibilité et vie en plus opérationnelles en objet

parent 4cb2b7d8
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ export class Avatar extends Entite { ...@@ -13,6 +13,7 @@ export class Avatar extends Entite {
momentumX; momentumX;
momentumY; momentumY;
statut; statut;
statutTime;
constructor(nom, vitesse) { constructor(nom, vitesse) {
super(0, 0, new Hitbox(68, 145, 0, 0), null); super(0, 0, new Hitbox(68, 145, 0, 0), null);
...@@ -28,6 +29,8 @@ export class Avatar extends Entite { ...@@ -28,6 +29,8 @@ export class Avatar extends Entite {
this.inertie = 0.95; this.inertie = 0.95;
this.momentumX = 0; this.momentumX = 0;
this.momentumY = 0; this.momentumY = 0;
this.statut = 'null';
this.statutTime = null;
} }
incrementScore(nb) { incrementScore(nb) {
...@@ -54,6 +57,14 @@ export class Avatar extends Entite { ...@@ -54,6 +57,14 @@ export class Avatar extends Entite {
}); });
} }
getStatutTime() {
return this.statutTime;
}
setStatutTime(t) {
this.statutTime = t;
}
setImageCanvas(image, canvas) { setImageCanvas(image, canvas) {
super.image = image; super.image = image;
this.canvas = canvas; this.canvas = canvas;
...@@ -75,12 +86,12 @@ export class Avatar extends Entite { ...@@ -75,12 +86,12 @@ export class Avatar extends Entite {
return this.click; return this.click;
} }
setStatut(status) { setStatut(statut) {
this.statut = status; this.statut = statut;
} }
getStatus() { getStatus() {
return this.status; return this.statut;
} }
colision(x, y, image) { colision(x, y, image) {
......
import Entite from './entite.js'; import Entite from './entite.js';
import { Hitbox } from './hitbox.js'; import { Hitbox } from './hitbox.js';
import { bonusImages } from './choixBonus.js';
export default class Bonus extends Entite { export default class Bonus extends Entite {
nom; nom;
taille; taille;
apparition; apparition;
constructor(choix, taille, x, y, image, time) { 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.choix = choix;
this.taille = taille; this.taille = taille;
this.apparition = time; this.apparition = time;
this.image.src = bonusImages[choix];
} }
estExpire(t) { estExpire(t) {
return t - this.apparition >= 60; return t - this.apparition == 60;
} }
getChoix() { getChoix() {
......
...@@ -104,22 +104,29 @@ document.addEventListener('keyup', event => { ...@@ -104,22 +104,29 @@ document.addEventListener('keyup', event => {
avatar.changerClick(event); avatar.changerClick(event);
}); });
setInterval(genererBonus, 1000); setInterval(genererBonus, 15000);
function genererBonus() { function genererBonus() {
if (gameStarted) { if (gameStarted) {
const choix = Math.floor(Math.random() * bonusNoms.length); const choix = Math.floor(Math.random() * bonusNoms.length);
let randomY = Math.floor(Math.random() * canvas.height); let randomY = Math.floor(Math.random() * canvas.height);
let randomX = Math.floor(Math.random() * canvas.width); let randomX = Math.floor(Math.random() * canvas.width);
let img = new Image(); let img = new Image();
img.src = bonusImages[choix]; img.width = 75;
img.width = 100; img.height = 75;
img.height = 100;
const bonus = new Bonus(choix, 1, randomX, randomY, img, t.getTotalTime()); const bonus = new Bonus(choix, 1, randomX, randomY, img, t.getTotalTime());
bonusArray.push(bonus); bonusArray.push(bonus);
} }
} }
setInterval(() => { 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.deplacer();
avatar.projectiles.forEach(projectile => projectile.deplacer()); avatar.projectiles.forEach(projectile => projectile.deplacer());
enemis.forEach(enemi => { enemis.forEach(enemi => {
...@@ -165,11 +172,12 @@ setInterval(() => { ...@@ -165,11 +172,12 @@ setInterval(() => {
if (bonusNoms[bonus.getChoix()] == 'vie') { if (bonusNoms[bonus.getChoix()] == 'vie') {
avatar.gagnerVie(); avatar.gagnerVie();
} else if (bonusNoms[bonus.getChoix()] == 'invincibilite') { } else if (bonusNoms[bonus.getChoix()] == 'invincibilite') {
console.log('INVICIBILITE');
avatar.setStatut('invincibilite'); avatar.setStatut('invincibilite');
avatar.setStatutTime(t.getTotalTime());
} }
bonusArray.splice(bonusArray.indexOf(bonus), 1); bonusArray.splice(bonusArray.indexOf(bonus), 1);
} else if (bonus.estExpire(t.getTotalTime())) { }
if (bonus.estExpire(t.getTotalTime())) {
bonusArray.splice(bonusArray.indexOf(bonus), 1); bonusArray.splice(bonusArray.indexOf(bonus), 1);
} }
}); });
...@@ -221,7 +229,6 @@ function render() { ...@@ -221,7 +229,6 @@ function render() {
}); });
} }
bonusArray.forEach(bonus => { bonusArray.forEach(bonus => {
console.log(bonus);
if ( if (
bonus.x <= canvas.width - bonus.image.width && bonus.x <= canvas.width - bonus.image.width &&
bonus.y <= canvas.height && bonus.y <= canvas.height &&
...@@ -235,7 +242,6 @@ function render() { ...@@ -235,7 +242,6 @@ function render() {
}); });
enemis.forEach(enemi => { enemis.forEach(enemi => {
console.log(enemi.getDifficulte());
if ( if (
enemi.x <= canvas.width - enemi.image.width && enemi.x <= canvas.width - enemi.image.width &&
enemi.y <= canvas.height && enemi.y <= canvas.height &&
......
...@@ -17,7 +17,7 @@ export default class timer { ...@@ -17,7 +17,7 @@ export default class timer {
} }
getTotalTime() { getTotalTime() {
return 3600 * this.getHrs() + 60 * this.getMin() + this.getSec; return 3600 * this.hrs + 60 * this.min + this.sec;
} }
getSec() { getSec() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment