ecs refactor

This commit is contained in:
Matthieu Jolimaitre 2024-04-09 04:25:34 +02:00
parent 28b026a614
commit f2e5d13000
8 changed files with 410 additions and 170 deletions

View file

@ -1,33 +1,25 @@
import { World, WorldEntity } from "../engine.ts";
import { v2, Vec2 } from "../../common/utils.ts";
import { wait } from "../../common/utils.ts";
import { Vec2 } from "../../common/utils.ts";
import { CompDisplay } from "../components/display.ts";
import { CompPos } from "../components/world.ts";
import { Engine } from "../engine.ts";
export class Enemy {
entity;
alive;
constructor(entity: WorldEntity) {
this.entity = entity;
this.alive = true;
}
static spawn(world: World, pos: Vec2) {
const entity = world.spawn_entity("èé", pos);
}
async spin() {
while (this.alive) {
await wait(500);
const target = this.find_target();
}
}
find_target() {
const world = this.entity.world;
const local_origin = this.entity.position;
const found = world.get_entities_in_range(local_origin.sub(v2(3, 3)), local_origin.add(v2(3, 3)));
for (const entity of found) {
// if (entity.compontents.get())
}
export class CompEnemy {
target;
life;
constructor() {
this.target = null as number | null;
this.life = 10;
}
}
export function sys_spawn_enemy(pos: Vec2) {
return (engine: Engine) => {
return engine.spawn((entity) =>
entity.insert(
new CompEnemy(),
new CompPos(entity, pos),
new CompDisplay("èé"),
)
);
};
}