1.0.5 • Published 4 months ago

ecs-library v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

ECS Library

A TypeScript Entity Component System (ECS) library for game development and simulation applications.

Features

  • Complete ECS Architecture: Entities, Components, Systems, and World management
  • Event System: Communication between systems and components
  • Spatial Partitioning: Efficient collision detection with QuadTree
  • Grid System: Grid-based movement and organization
  • Pathfinding: A* algorithm for finding paths in grid-based environments
  • State Machine: Finite state machine for entity behavior
  • Tweening: Smooth interpolation of component properties
  • Prefabs: Templates for efficient entity creation
  • Timers: Time-based events and actions
  • Game Components: Enhanced health, weapons, particles, pickups, and more
  • Behavior System: Modular AI patterns for entities
  • Wave Management: Tools for managing waves of enemies or events
  • Particle Effects: Particle emitters and visual effects

Installation

npm install ecs-library

Basic Usage

import * as ecs from 'ecs-library';

// Create a world
const world = new ecs.World();

// Add systems
world.addSystem(new ecs.MovementSystem());
world.addSystem(new ecs.CollisionSystem());

// Create an entity
const player = world.createEntity();
player.addComponent(new ecs.TransformComponent(100, 100));
player.addComponent(new ecs.VelocityComponent(0, 0));
player.addComponent(new ecs.ColliderComponent(32, 32));
player.addTag('player');

// Game loop
function gameLoop(deltaTime) {
  // Update the world
  world.update(deltaTime);
  
  // Request next frame
  requestAnimationFrame(gameLoop);
}

// Start the game loop
requestAnimationFrame(gameLoop);

Creating Custom Components

import { Component } from 'ecs-library';

class PlayerComponent extends Component {
  public score: number = 0;
  public lives: number = 3;
  
  constructor(score: number = 0, lives: number = 3) {
    super();
    this.score = score;
    this.lives = lives;
  }
  
  public clone(): PlayerComponent {
    const player = new PlayerComponent();
    player.score = this.score;
    player.lives = this.lives;
    return player;
  }
}

Creating Custom Systems

import { System } from 'ecs-library';
import { PlayerComponent } from './PlayerComponent';

class PlayerSystem extends System {
  public update(deltaTime: number): void {
    if (!this.world) return;
    
    const entities = this.world.getEntitiesWithComponent(PlayerComponent);
    
    for (const entity of entities) {
      const playerComponent = entity.getComponent(PlayerComponent);
      
      // Game logic here...
    }
  }
}

Documentation

For detailed documentation, see the ECS Library Documentation.

For API reference, see the API Reference.

Examples

Check out the examples directory for more usage examples:

License

MIT

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago