add typeentity and some file for the future ennemies

This commit is contained in:
Mylloon 2022-11-24 20:16:48 +01:00
parent a807d9de0d
commit 9b980000dd
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 38 additions and 10 deletions

View file

@ -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();
}
});
};
/**

7
js/Pique.js Normal file
View file

@ -0,0 +1,7 @@
import { Triangle } from "./Triangle.js";
export class Pique extends Triangle {
constructor() {
super();
}
}

7
js/Triangle.js Normal file
View file

@ -0,0 +1,7 @@
import { Element } from "./Element.js";
export class Triangle extends Element {
constructor() {
super();
}
}

View file

@ -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