diff --git a/client/public/images/vie.png b/client/public/images/vie.png new file mode 100644 index 0000000000000000000000000000000000000000..6437caab3754b9543dfc49990ae8f68aff7ed36b Binary files /dev/null and b/client/public/images/vie.png differ diff --git a/client/public/images/vie.webp b/client/public/images/vie.webp new file mode 100644 index 0000000000000000000000000000000000000000..8be6e7ecb930f91c622967d91e89371399a3bc52 Binary files /dev/null and b/client/public/images/vie.webp differ diff --git a/client/src/avatar.js b/client/src/avatar.js index a695173960245d2c6a1307a4502bfefbf3f59828..bfb2d49d3acab84df5cfa1473a57d37ebb66da4c 100644 --- a/client/src/avatar.js +++ b/client/src/avatar.js @@ -12,6 +12,8 @@ export class Avatar extends Entite { inertie; momentumX; momentumY; + statut; + statutTime; constructor(nom, id, canvasSize) { super(0, 0, new Hitbox(68, 145, 0, 0), null); @@ -71,6 +73,22 @@ export class Avatar extends Entite { return this.click; } + setStatut(statut) { + this.statut = statut; + } + + setStatutTime(statutTime) { + this.statutTime = statutTime; + } + + getStatut() { + return this.statut; + } + + getStatutTime() { + return this.statutTime; + } + colision(x, y, image) { this.projectiles.forEach(element => { if (element.colision(x, y, image)) { diff --git a/client/src/draw.js b/client/src/draw.js index 55185c24b71d2ed539817315790366417039aea4..1ed7143910e7bc07ff5869ca8d2f6452bd8b58ce 100644 --- a/client/src/draw.js +++ b/client/src/draw.js @@ -5,9 +5,9 @@ export default function draw(canvas, context, image, x, y) { x >= 0 && y >= 0 ) { - context.drawImage(image, x, y); + context.drawImage(image, x, y, image.width, image.height); return true; - }else{ + } else { return false; } } diff --git a/client/src/main.js b/client/src/main.js index 2296e893fb237d35214aa459fe658890277b80cc..46c4e3e47d6392d07a1dfb5fbba31f16d6b53192 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -5,6 +5,8 @@ import timer from '../../server/timer.js'; import setHtml from './setHtml.js'; import draw from './draw.js'; import { Coordinate } from './Coordinate.js'; +import { bonusImages } from './choixBonus.js'; +import Bonus from '../../server/bonus.js'; const socket = io(); let min = 0; @@ -149,7 +151,12 @@ function render() { newBonus = data; }); newBonus.forEach(bonus => { - draw(canvas, context, bonus.getImage(), bonus.getX(), bonus.getY()); + console.log(bonus); + let img = new Image(); + img.src = bonusImages[bonus.choix]; + img.width = 75; + img.height = 75; + draw(canvas, context, img, bonus.x, bonus.y); }); requestAnimationFrame(render); diff --git a/server/bonus.js b/server/bonus.js index 999d7186bb0245c00a6a18ccbaf5fd08bf3c7607..93b152b562720766b107c9ff11ef57358a060f6d 100644 --- a/server/bonus.js +++ b/server/bonus.js @@ -1,16 +1,15 @@ import Entite from '../client/src/entite.js'; -import { bonusImages } from '../client/src/choixBonus.js'; +import { Hitbox } from '../client/src/hitbox.js'; export default class Bonus extends Entite { nom; taille; apparition; - constructor(choix, taille, x, y, image, time) { - super(x, y, new Hitbox(image.width, image.height, x, y), image); + constructor(choix, taille, x, y, time) { + super(x, y, new Hitbox(75, 75, x, y), null); this.choix = choix; this.taille = taille; this.apparition = time; - this.image.src = bonusImages[choix]; } estExpire(t) { diff --git a/server/index.js b/server/index.js index 0f4d705bc1301b53418b99d39799fdadc85f6786..23577dda72b0fab6aa16462aab0122189027770c 100644 --- a/server/index.js +++ b/server/index.js @@ -124,13 +124,16 @@ let spawnIntervalLV2 = setInterval(() => { }, 800); let spawnBonusInterval = setInterval(() => { + let randomX; + let randomY; const choix = Math.floor(Math.random() * bonusNoms.length); - let randomY = Math.floor(Math.random() * canvasSize.height); - let randomX = Math.floor(Math.random() * canvasSize.width); - let img = new Image(); - img.width = 75; - img.height = 75; - const bonus = new Bonus(choix, 1, randomX, randomY, img, t.getTotalTime()); + do { + randomY = Math.random() * (canvasSize.height - 0) + 0; + } while (randomY > canvasSize.height - 75); + do { + randomX = Math.random() * (canvasSize.width - 0) + 0; + } while (randomX > canvasSize.width - 75); + const bonus = new Bonus(choix, 1, randomX, randomY, t.getTotalTime()); bonusArray.push(bonus); }, 15000); @@ -141,8 +144,17 @@ setInterval(() => { let avatarData = []; avatars.forEach(avatar => { avatar.canvasSize = canvasSize; + if ( + avatar.getStatut() == 'invincibilite' && + t.getTotalTime() - avatar.getStatutTime() == 15 + ) { + avatar.setStatut('null'); + } enemis.forEach(enemi => { - if (enemi.hitbox.colision(avatar.hitbox)) { + if ( + enemi.hitbox.colision(avatar.hitbox) && + avatar.getStatut() != 'invincibilite' + ) { if (canLostLifeAvatar) { avatar.decrementScore(5); enemis.splice(enemis.indexOf(enemi), 1);