6 releases (breaking)
0.6.0 | Jul 3, 2023 |
---|---|
0.5.0 | Jun 5, 2020 |
0.4.0 | May 23, 2020 |
0.3.0 | May 21, 2020 |
0.1.0 | May 19, 2020 |
#291 in Graphics APIs
58 downloads per month
55KB
1K
SLoC
olcPixelGameEngine-rs
Library offers Rust API for olcPixelGameEngine. I try keeping the methods and constants similar to the original C++ code so the API feels familiar and it is easy to follow along the tutorial videos.
The code builds on Linux, Windows, and macOS/OSX (any 10.x, including older versions, only X11 is required) and uses my mac port of pixel game engine https://github.com/sadikovi/olcPixelGameEngine-macos. MacOS users may need to install XQuartz for OpenGL support.
You can link the crate as a dependency and extend Application
trait to run the pixel game engine:
extern crate olc_pixel_game_engine;
use crate::olc_pixel_game_engine as olc;
// Very simple example application that prints "Hello, World!" on screen.
struct ExampleProgram {}
impl olc::Application for ExampleProgram {
fn on_user_create(&mut self) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserCreate`. Your code goes here.
Ok(())
}
fn on_user_update(&mut self, _elapsed_time: f32) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserUpdate`. Your code goes here.
// Clears screen and sets black colour.
olc::clear(olc::BLACK);
// Prints the string starting at the position (40, 40) and using white colour.
olc::draw_string(40, 40, "Hello, World!", olc::WHITE)?;
Ok(())
}
fn on_user_destroy(&mut self) -> Result<(), olc::Error> {
// Mirrors `olcPixelGameEngine::onUserDestroy`. Your code goes here.
Ok(())
}
}
fn main() {
let mut example = ExampleProgram {};
// Launches the program in 200x100 "pixels" screen, where each "pixel" is 4x4 pixel square,
// and starts the main game loop.
olc::start("Hello, World!", &mut example, 200, 100, 4, 4).unwrap();
}
I recommend checking out the documentation to see what APIs are available.
Examples
You can look at the examples in examples/ directory to get a sense of available APIs, make sure to also check out the docs.
I will be adding more examples in that directory. Some of them are direct ports of
olcPixelGameEngine
examples and videos. Feel free to add more as you explore the pixel game engine!
Run examples
For example, run the Isometric Tiles demo with cargo run --example isometric_tiles
.
Build
Run cargo build
to build the project.
Test
Run cargo test
for the project tests.
Docs
Run cargo doc --open
to build and view the documentation locally.
No runtime deps
~225KB