factor player direction as component property

This commit is contained in:
JOLIMAITRE Matthieu 2024-10-20 22:43:16 +02:00
parent e502ca00de
commit fb85af7c40
2 changed files with 15 additions and 10 deletions

View file

@ -55,9 +55,10 @@ export class Session {
move(direction: Vec2) {
const pos = this.entity.get_force(CompPos);
pos.move_collide(this.engine, direction);
const player = this.entity.get_force(CompPlayer);
const display = this.entity.get_force(CompDisplay);
if (direction.x() > 0) display.update("P/");
if (direction.x() < 0) display.update("\\P");
if (direction.x() > 0) player.direction = Dir.Right, display.update("P/");
if (direction.x() < 0) player.direction = Dir.Left, display.update("\\P");
}
}
@ -67,15 +68,18 @@ export function sys_spawn_player(position: Vec2) {
entity.insert(
new CompPlayer(),
new CompPos(entity, position),
new CompDisplay("P/"),
new CompDisplay("\\P"),
)
);
};
}
export class CompPlayer {
life;
constructor() {
this.life = 10;
}
enum Dir {
Left,
Right,
}
export class CompPlayer {
life = 10;
direction = Dir.Left;
}