olc_pixel_game_engine

Crates.ioolc_pixel_game_engine
lib.rsolc_pixel_game_engine
version0.6.0
sourcesrc
created_at2020-05-19 07:56:38.273132
updated_at2023-07-03 23:58:33.274378
descriptionRust bindings for olcPixelGameEngine
homepagehttps://github.com/sadikovi/olcPixelGameEngine-rs
repositoryhttps://github.com/sadikovi/olcPixelGameEngine-rs
max_upload_size
id243361
size183,310
Ivan (sadikovi)

documentation

README

olcPixelGameEngine-rs

Build Status Crates.io

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.

Commit count: 72

cargo fmt