1.1.9 • Published 1 year ago

@farbour/piko-engine v1.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Piko Engine

A powerful and flexible 2D game engine built in JavaScript with a focus on performance and modularity.

Features

Core Engine

  • Entity Component System (ECS) architecture
  • Scene management and game state handling
  • Asset loading and resource management
  • Camera system with viewport control

Physics and Collision

  • Rigid body physics simulation
  • Collision detection and resolution
  • Shape detection for various geometries
  • Physics presets for common game objects

AI and Behavior

  • Behavior tree system for AI logic
  • Pathfinding with multiple algorithms:
    • Attack vector calculation
    • Flocking behavior
    • Freeform movement
  • Navigation grid system

Graphics and Animation

  • Sprite rendering and management
  • Particle system for effects
  • Skeleton-based animations
  • Text rendering system

Components

  • Transform (position, rotation, scale)
  • Sprite and Animation
  • RigidBody for physics
  • Health system
  • AI and Behavior Tree
  • Pathfinding
  • Particle Emitter
  • Text
  • Skeleton for animations
  • Loot and inventory systems

Systems

  • Render system for graphics
  • Physics system for simulation
  • AI system for behavior processing
  • Animation system
  • Particle system
  • Health system
  • Debug rendering
  • Text rendering
  • Loot management

Utilities

  • Event emitter for communication
  • Math utilities
  • Object pooling for performance
  • Random number generation
  • Logger for debugging

Plugins

  • AI plugin for advanced behaviors
  • Debug plugin for development
  • Editor plugin for game creation
  • Plugin manager for extensibility

Installation

npm install piko-engine

Basic Usage

import { Game, Scene, Entity, SpriteComponent, TransformComponent } from 'piko-engine';

// Create a new game instance
const game = new Game({
  canvas: document.getElementById('gameCanvas'),
  width: 800,
  height: 600
});

// Create a scene
class GameScene extends Scene {
  init() {
    // Create a player entity
    const player = new Entity();
    
    // Add components
    player.addComponent(new TransformComponent({
      x: 400,
      y: 300,
      rotation: 0
    }));
    
    player.addComponent(new SpriteComponent({
      src: 'player.png'
    }));
    
    // Add entity to scene
    this.addEntity(player);
  }
  
  update(deltaTime) {
    // Update game logic
  }
}

// Start the game
game.setScene(new GameScene());
game.start();

Advanced Features

Physics System

import { RigidBodyComponent, PhysicsSystem } from 'piko-engine';

// Add physics to an entity
entity.addComponent(new RigidBodyComponent({
  mass: 1,
  velocity: { x: 0, y: 0 },
  acceleration: { x: 0, y: 0 }
}));

// The physics system will automatically handle movement and collisions

Particle Effects

import { ParticleEmitterComponent } from 'piko-engine';

// Create a particle effect
entity.addComponent(new ParticleEmitterComponent({
  particleCount: 100,
  lifetime: 1000,
  speed: 5,
  spread: 45,
  color: '#ff0000'
}));

AI Behavior Trees

import { BehaviorTreeComponent, Sequence, Selector } from 'piko-engine';

// Create an AI behavior tree
const behaviorTree = new BehaviorTreeComponent({
  root: new Sequence([
    new Selector([
      // Define AI behaviors
    ])
  ])
});

entity.addComponent(behaviorTree);

Plugin System

Create custom plugins to extend engine functionality:

import { Plugin } from 'piko-engine';

class CustomPlugin extends Plugin {
  init() {
    // Plugin initialization
  }
  
  update(deltaTime) {
    // Plugin update logic
  }
}

game.plugins.add(new CustomPlugin());

Performance Optimization

The engine includes several performance optimization features:

  • Object pooling for entity recycling
  • Efficient component storage and access
  • Optimized collision detection
  • Batch rendering for sprites
  • Event system for decoupled communication

Development Tools

Debug tools are available through the debug plugin:

import { DebugPlugin } from 'piko-engine';

game.plugins.add(new DebugPlugin({
  showFPS: true,
  showColliders: true,
  showGrid: true
}));

Contributing

Contributions are welcome! Please feel free to submit pull requests.

License

MIT License - feel free to use this engine in your projects.