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

ajout complet objets

parent f1128361
Branches
No related tags found
No related merge requests found
client/public/images/vie.png

90 KiB

client/public/images/vie.webp

87.7 KiB

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