From 9b980000dd5a3e7bbca569a2799e8a444647567c Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 24 Nov 2022 20:16:48 +0100 Subject: [PATCH] add typeentity and some file for the future ennemies --- js/Env.js | 30 ++++++++++++++++++++++-------- js/Pique.js | 7 +++++++ js/Triangle.js | 7 +++++++ js/main.js | 4 ++-- 4 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 js/Pique.js create mode 100644 js/Triangle.js diff --git a/js/Env.js b/js/Env.js index 53283ab..d75c4a7 100644 --- a/js/Env.js +++ b/js/Env.js @@ -1,6 +1,12 @@ import { Element } from "./Element.js"; import { Quality } from "./utils.js"; +export class TypeEntity { + static other = 0; + static player = 1; + static ennemy = 2; +} + export class Env { constructor() { this.scene = new THREE.Scene(); @@ -79,21 +85,29 @@ export class Env { /** * Add an element to the scene * @param {Element} element Element + * @param {TypeEntity} type Type of the element added */ - addToScene = (element) => { - this.elements.push(element); + addToScene = (element, type) => { + if (!type) { + type = TypeEntity.other; + } + + this.elements.push([element, type]); this.scene.add(element.data); }; /** - * Animate all the elements in the environnement + * Animate all the players in the environnement */ animate = () => { - this.elements.forEach((element) => { - if (element.animation) { - element.animation(); - } - }); + this.elements + .filter((entityData) => entityData[1] == TypeEntity.player) + .map((playerData) => playerData[0]) + .forEach((player) => { + if (player.animation) { + player.animation(); + } + }); }; /** diff --git a/js/Pique.js b/js/Pique.js new file mode 100644 index 0000000..9641f17 --- /dev/null +++ b/js/Pique.js @@ -0,0 +1,7 @@ +import { Triangle } from "./Triangle.js"; + +export class Pique extends Triangle { + constructor() { + super(); + } +} diff --git a/js/Triangle.js b/js/Triangle.js new file mode 100644 index 0000000..4283b80 --- /dev/null +++ b/js/Triangle.js @@ -0,0 +1,7 @@ +import { Element } from "./Element.js"; + +export class Triangle extends Element { + constructor() { + super(); + } +} diff --git a/js/main.js b/js/main.js index e943193..3b92b08 100644 --- a/js/main.js +++ b/js/main.js @@ -1,4 +1,4 @@ -import { Env } from "./Env.js"; +import { Env, TypeEntity } from "./Env.js"; import { Plane } from "./Plane.js"; import { Player } from "./Player.js"; import { Quality } from "./utils.js"; @@ -21,7 +21,7 @@ const main = () => { // Player const player = new Player(THREE.Color.NAMES.red); - env.addToScene(player); + env.addToScene(player, TypeEntity.player); addEventListener("keypress", player.controlUser); // GUI