A basic 3D game engine built with Raylib and Rust, featuring an Entity Component System (ECS) and level configuration system.
- ECS Architecture: Component-based entity system for flexible game object management
- Level Config System: Load levels from TOML or JSON files
- 3D Rendering: Built on Raylib for simple 3D graphics
- Player Control: WASD movement with mouse look
WASD- Move player horizontallySpace- Move upLeft Shift- Move downRight Mouse + Drag- Look aroundESC- Exit
src/
├── ecs/
│ ├── components.rs # Component definitions (Transform, Renderable, etc.)
│ ├── entity.rs # Entity and World management
│ ├── systems.rs # Systems (Movement, Render, Input)
│ └── mod.rs
├── level/
│ ├── config.rs # Level configuration structures
│ ├── loader.rs # Level loading/saving
│ └── mod.rs
└── main.rs # Game entry point
levels/ # Level configuration files
├── sample.toml
└── sample.json
cargo runLevels can be created in TOML or JSON format. Example:
name = "My Level"
description = "A custom level"
[camera]
position = [10.0, 10.0, 10.0]
target = [0.0, 0.0, 0.0]
up = [0.0, 1.0, 0.0]
fov = 45.0
[[entities]]
name = "Ground"
entity_type = "static"
[entities.transform]
position = [0.0, -0.5, 0.0]
scale = [20.0, 1.0, 20.0]
[entities.renderable]
type = "Cube"
size = [1.0, 1.0, 1.0]
color = [100, 100, 100, 255]Transform- Position, rotation, scaleRenderable- Visual representation (Cube, Sphere, Cylinder, Model)Velocity- Linear and angular velocityHealth- Health pointsName- Entity label
The engine includes many example components showing best practices:
Timing & Lifecycle:
Lifetime- Auto-remove entities after durationCooldown- Ability cooldown timers
Physics:
Gravity- Gravitational forceBouncy- Bounce on collisionDrag- Air resistance/friction
Combat:
Projectile- Bullets, arrows, etc.AttackAbility- Melee/ranged attacks
AI & Behavior:
FollowTarget- Chase an entityPatrolPath- Waypoint navigationStateMachine- AI state management
Visual Effects:
FadeOut- Fade alpha over lifetimeAutoRotate- Continuous rotation
Tags:
Collectible,Obstacle,Damageable,MarkedForDeath
MovementSystem- Applies velocity to transformRenderSystem- Draws all renderable entitiesPlayerInputSystem- Handles player input
Complete, documented example systems demonstrating patterns:
LifetimeSystem- Entity expirationGravitySystem- Apply gravityDragSystem- Apply air resistanceAutoRotateSystem- Rotate entitiesFadeOutSystem- Fade effectsFollowTargetSystem- AI followingPatrolSystem- Waypoint navigationProjectileCollisionSystem- Collision detection
- ECS Guide - Comprehensive guide to the ECS architecture, best practices, and patterns
- Examples - Concrete code examples for common game development tasks
- Read docs/ECS_GUIDE.md to understand ECS concepts
- Check docs/EXAMPLES.md for practical examples
- Look at
src/ecs/examples.rsfor component examples with documentation - Study
src/ecs/example_systems.rsfor system implementation patterns - Run the demo and explore the sample level
use ecs::*;
// Create a world
let mut world = World::new();
// Spawn an entity
let enemy = world.spawn()
.with_transform(Transform::new(Vector3::new(5.0, 0.0, 0.0)))
.with_renderable(Renderable::cube(Vector3::one(), Color::RED))
.with_velocity(Velocity::default())
.with_health(Health::new(100.0))
.with_gravity(Gravity::earth())
.as_enemy()
.build();
// Create and update systems
let mut gravity_system = GravitySystem;
let mut movement_system = MovementSystem;
// In game loop
gravity_system.update(&mut world, delta_time);
movement_system.update(&mut world, delta_time);MIT