A Rust based Raycaster engine
This will be a full featured raycaster engine to produce games similar to Wolfenstein 3D. I needed it to create 3D dungeons for my retro RPG creator Eldiron.
The caster renders into a Vec<u8> frame. The only dependency of the crate right now is rustc-hash for a fast HashMap.
A demo application using pixels is available in the demo directory.
Features
- Textured or colored walls, ceiling and floor
- Adjustable fog color and distance
- Sprites
Todo
- Doors
- Animated textures
- Lighting
Usage
Create a world map:
use *;
let mut world = new;
// Add an image containing the tilemap to the world
let image_id = world.add_image;
// Create a textured tile and use it for the ceiling default
// The rectangle defines the tile in the tilemap
let ceiling_tile = textured;
world.set_ceiling_tile;
// Set a colored tile for the floor
world.set_floor_tile;
// Add a wall with a tile at the given location
// Add as many walls as you like
world.set_wall;
// Add a sprite at the given location.
// You can manage the sprites yourself as WorldMap::sprites is public.
let sprite = new;
world.add_sprite;
// Set the fog color and the fog distance, the distance is in tiles.
world.set_fog;
When we have set up the world we can render it:
const width: usize = 800;
const height: usize = 600;
let frame = vec!;
let mut caster = new;
// Set the position pf the player
caster.set_pos;
// Render into the given rectangle inside the frame (here the full frame), the stride (i.e. the width of the frame) and the world.
caster.render;
Acknowledgements
- Inspiration was provided by Pikumas excellent Raycaster Tutorial Series.
- The basic idea of the raycaster is based on the Lodev's Raycaster Tutorial.