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 {
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) {
......
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() {
......
......@@ -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 &&
......
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment