feat: implement ECS architecture with game entity management
- Introduced a new Entity-Component-System (ECS) architecture for the game. - Created foundational components such as Transform, Velocity, Health, and Collidable. - Developed systems for handling input, movement, collision detection, and rendering. - Added game logic for player control, coin collection, and obstacle interactions. - Implemented a performance monitor for real-time metrics display. - Enhanced game initialization and entity creation processes. This update significantly refactors the game structure, improving maintainability and scalability.
This commit is contained in:
parent
50544989ca
commit
7dd7477a3b
20 changed files with 1610 additions and 616 deletions
28
src/systems/RenderSystem.js
Normal file
28
src/systems/RenderSystem.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { System } from '../ecs/System.js';
|
||||
import { Transform } from '../components/Transform.js';
|
||||
import { MeshComponent } from '../components/MeshComponent.js';
|
||||
|
||||
/**
|
||||
* RenderSystem - syncs Three.js mesh positions with Transform components
|
||||
*/
|
||||
export class RenderSystem extends System {
|
||||
constructor(scene) {
|
||||
super();
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
update(_deltaTime) {
|
||||
const entities = this.getEntities(Transform, MeshComponent);
|
||||
|
||||
for (const entityId of entities) {
|
||||
const transform = this.getComponent(entityId, Transform);
|
||||
const meshComp = this.getComponent(entityId, MeshComponent);
|
||||
|
||||
// Sync mesh transform with component
|
||||
meshComp.mesh.position.copy(transform.position);
|
||||
meshComp.mesh.rotation.copy(transform.rotation);
|
||||
meshComp.mesh.scale.copy(transform.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue