An open API service indexing awesome lists of open source software.

https://github.com/cey0225/kon

Kon: A modular 2D game engine for Rust, built with a focus on ECS performance and simplicity.
https://github.com/cey0225/kon

2d-game-engine data-oriented ecs entity-component-system game-engine gamedev performance rust

Last synced: 28 days ago
JSON representation

Kon: A modular 2D game engine for Rust, built with a focus on ECS performance and simplicity.

Awesome Lists containing this project

README

          


Kon Engine

A modular 2D game engine in Rust with a custom SparseSet-based ECS. Built from scratch to learn how game engines actually work.

> ⚠️ **Heads up:** This is an experimental/educational project. I'm building this to understand engine internals, not to compete with existing engines.

## What's Inside

The project is split into workspace crates:

**Currently Working**
- **`kon_core`** - App lifecycle, plugins, events
- **`kon_ecs`** - Custom ECS
- **`kon_macros`** - Proc macros for `#[system]` and `#[component]`
- **`kon_window`** - Winit-based window management
- **`kon_input`** - Input handling
- **`kon_math`** - Math stuff with Glam integration
- **`kon_renderer`** - WGPU-based 2D renderer

**Still Cooking 🍳**
- **`kon_scene`** - Scene management and hierarchies (WIP)
- **`kon_ui`** - Immediate-mode UI toolkit (WIP)
- **`kon_audio`** - Sound and music playback (Planned)
- **`kon_animation`** - Sprite animation (Planned)
- **`kon_physics`** - 2D physics (Planned)
- **`kon_editor`** - Editor tools (Planned)

## Features

- [x] Plugin-based architecture
- [x] Custom SparseSet ECS with O(1) component access
- [x] Write systems as regular Rust functions
- [x] Ergonomic query API
- [x] Event system for decoupled communication
- [x] Window context management
- [x] Keyboard/mouse input
- [x] Hardware-accelerated 2D rendering
- [x] Texture loading and management
- [x] Immediate-mode shape drawing
- [ ] Scene hierarchies and parent-child transforms
- [ ] Sprite animation and atlas support
- [ ] UI system with common widgets
- [ ] Audio playback
- [ ] Collision detection and physics
- [ ] Integrated editor

## Quick Example

Here's how you write a simple simulation:

```rust
use kon::prelude::*;

#[system]
fn setup(ctx: &mut Context) {
ctx.window().set_config(WindowConfig::default().with_title("Example"));

let texture = ctx.renderer().load_texture(&[255, 0, 0, 255], 1, 1);

ctx.world()
.spawn()
.insert(Transform::from_xy(500.0, 500.0))
.insert(Sprite::new(texture).size(400.0, 100.0));
}

#[system]
fn draw(ctx: &mut Context) {
let h = ctx.window().size().height as f32;

ctx.renderer()
.draw_rect(10.0, h - 105.0, 100.0, 100.0, Color::TEAL);
ctx.renderer()
.draw_rounded_rect(120.0, h - 105.0, 100.0, 100.0, 10.0, Color::CYAN);
ctx.renderer()
.draw_circle(275.0, h - 55.0, 50.0, Color::TURQUOISE);
}

#[system]
fn update(ctx: &mut Context) {
if ctx.input().just_key_pressed(KeyCode::Escape) {
ctx.quit();
}

ctx.on::(|_, context| {
context.quit();
});
}

fn main() {
Kon::new()
.add_plugin(DefaultPlugins)
.add_startup_system(setup)
.add_system(draw)
.add_system(update)
.run();
}
```

## How to Use

**As a dependency:**

```bash
cargo add kon-engine
```

Or in your `Cargo.toml`:

```toml
[dependencies]
kon-engine = "0.3.2"
```

**From source:**

```bash
git clone https://github.com/cey0225/kon.git
cd kon

# Run examples
# Linux/macOS
./kon.sh simple_demo

# Windows
./kon.ps1 simple_demo
```

## License

Dual-licensed under MIT or Apache 2.0, pick whichever works for you.

- MIT: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
- Apache 2.0: [LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0