# @nice2dev/game-engine

> No-code game engine and editor for React — built on the nice2dev ecosystem.

[![npm](https://img.shields.io/npm/v/@nice2dev/game-engine)](https://www.npmjs.com/package/@nice2dev/game-engine)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)

---

## Features

- **No-code first** — visual editors, drag & drop, node-based scripting
- **ECS architecture** — Entity-Component-System for flexible game logic
- **2D rendering** — Canvas 2D & WebGL with camera, sprites, shapes, particles
- **Physics** — built-in 2D physics (colliders, rigid bodies, raycasting)
- **Input** — gamepad, keyboard, mouse, touch — full controller support
- **Audio** — Web Audio API: music, SFX, spatial audio, mixer channels
- **Multiplayer** — splitscreen, couch co-op, online (via @nice2dev/rtc)
- **Templates** — 25+ game genre templates ready to use
- **AI** — behavior trees, steering, FSM, GOAP, dialog trees
- **3D runtime** — WebGL 3D world, physics, renderer
- **i18n & Accessibility** — multi-language, screen reader, colorblind modes

## Installation

```bash
npm install @nice2dev/game-engine
```

### Peer dependencies

```bash
npm install react react-dom @nice2dev/ui @nice2dev/ui-graphics
```

## Quick Start

```tsx
import { NiceGameEngine, WaveDefenseTemplate } from '@nice2dev/game-engine';

function MyGame() {
  return (
    <NiceGameEngine width={1280} height={720} maxPlayers={4}>
      <WaveDefenseTemplate />
    </NiceGameEngine>
  );
}
```

## Game Templates

| Template | Genre |
|----------|-------|
| `WaveDefenseTemplate` | Tower defense / wave survival |
| `PlatformerTemplate` | Side-scrolling platformer |
| `Match3Template` | Match-3 puzzle |
| `RPGTemplate` | Role-playing game |
| `RacingTemplate` | Top-down racing |
| `ShooterTemplate` | Shoot 'em up |
| `SandboxTemplate` | Open-world sandbox |
| + 18 more | Various genres |

## Architecture

```
@nice2dev/game-engine
├── core/          — GameLoop, Clock, Config, ServiceLocator
├── ecs/           — Entity, Component, System, World
├── input/         — InputManager, Gamepad, Keyboard, Touch
├── audio/         — AudioManager, SoundPool, MusicPlayer
├── rendering/     — Renderer2D, Camera, Sprites, Particles
├── physics/       — Colliders, RigidBody, Raycasting
├── scene/         — Scene, SceneManager, Prefabs
├── ui/            — HUD, Menus, Dialogs, Focus
├── multiplayer/   — PlayerManager, SplitScreen
├── procedural/    — Random, Noise, Waves, Loot
├── templates/     — Genre templates (wave defense, platformer, ...)
├── ai/            — Behavior trees, steering, FSM, GOAP
├── 3d/            — World3D, Renderer3D, PhysicsWorld3D
└── editor/        — NiceGameEditor (no-code visual editor)
```

## Editor

The `NiceGameEditor` provides a complete no-code visual editor with:
- Scene hierarchy and property inspector
- Tilemap editor
- Sprite animation editor
- Node-based visual scripting (`NodeLibrary`, `GraphExecutor`)
- Asset management
- Debug tools and performance profiling

```tsx
import { NiceGameEditor } from '@nice2dev/game-engine';

<NiceGameEditor
  onSave={(project) => saveProject(project)}
  onExport={(bundle) => downloadBundle(bundle)}
/>
```

## License

MIT © NiceToDev
