feat: add poc
This commit is contained in:
parent
43d27b04d9
commit
4a4fa05ce4
53 changed files with 6191 additions and 0 deletions
69
src/systems/PlayerControllerSystem.js
Normal file
69
src/systems/PlayerControllerSystem.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import { System } from '../core/System.js';
|
||||
|
||||
export class PlayerControllerSystem extends System {
|
||||
constructor() {
|
||||
super('PlayerControllerSystem');
|
||||
this.requiredComponents = ['Position', 'Velocity'];
|
||||
this.priority = 5;
|
||||
this.playerEntity = null;
|
||||
}
|
||||
|
||||
process(deltaTime, entities) {
|
||||
// Find player entity (first entity with player tag or specific component)
|
||||
if (!this.playerEntity) {
|
||||
this.playerEntity = entities.find(e => e.hasComponent('Evolution'));
|
||||
}
|
||||
|
||||
if (!this.playerEntity) return;
|
||||
|
||||
const inputSystem = this.engine.systems.find(s => s.name === 'InputSystem');
|
||||
if (!inputSystem) return;
|
||||
|
||||
const velocity = this.playerEntity.getComponent('Velocity');
|
||||
const position = this.playerEntity.getComponent('Position');
|
||||
if (!velocity || !position) return;
|
||||
|
||||
// Movement input
|
||||
let moveX = 0;
|
||||
let moveY = 0;
|
||||
const moveSpeed = 200;
|
||||
|
||||
if (inputSystem.isKeyPressed('w') || inputSystem.isKeyPressed('arrowup')) {
|
||||
moveY -= 1;
|
||||
}
|
||||
if (inputSystem.isKeyPressed('s') || inputSystem.isKeyPressed('arrowdown')) {
|
||||
moveY += 1;
|
||||
}
|
||||
if (inputSystem.isKeyPressed('a') || inputSystem.isKeyPressed('arrowleft')) {
|
||||
moveX -= 1;
|
||||
}
|
||||
if (inputSystem.isKeyPressed('d') || inputSystem.isKeyPressed('arrowright')) {
|
||||
moveX += 1;
|
||||
}
|
||||
|
||||
// Normalize diagonal movement
|
||||
if (moveX !== 0 && moveY !== 0) {
|
||||
moveX *= 0.707;
|
||||
moveY *= 0.707;
|
||||
}
|
||||
|
||||
// Apply movement
|
||||
velocity.vx = moveX * moveSpeed;
|
||||
velocity.vy = moveY * moveSpeed;
|
||||
|
||||
// Face mouse or movement direction
|
||||
const mouse = inputSystem.getMousePosition();
|
||||
const dx = mouse.x - position.x;
|
||||
const dy = mouse.y - position.y;
|
||||
if (Math.abs(dx) > 0.1 || Math.abs(dy) > 0.1) {
|
||||
position.rotation = Math.atan2(dy, dx);
|
||||
} else if (moveX !== 0 || moveY !== 0) {
|
||||
position.rotation = Math.atan2(moveY, moveX);
|
||||
}
|
||||
}
|
||||
|
||||
getPlayerEntity() {
|
||||
return this.playerEntity;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue