Crates.io | pixel_engine_draw |
lib.rs | pixel_engine_draw |
version | 0.7.0 |
source | src |
created_at | 2020-07-06 11:42:53.451177 |
updated_at | 2022-12-23 23:22:57.814165 |
description | The graphics crate used by the pixel_engine |
homepage | |
repository | https://github.com/maix0/pixel_engine |
max_upload_size | |
id | 261923 |
size | 80,188 |
A reproduction of the oldPixelGameEngine(by OneLoneCoder) written in rust This crate is split between 3 crates:
This is provide wrapper around wgpu. It handles the drawing of decals and the main screen
This crate provide Traits to handle the Drawing. You only need to implement one trait (The SmartDrawing trait) and the other trait are just supertrait, so you have them for free
This is the core of the projects, It is the main library, aimed to be used by the user. This provide the Engine struct
There are plenty of examples in the examples
folder.
You only need to run cargo run --bin=<NAME>
, or go to (https://maix.me)[https://maix.me/] to get a list of example code.
extern crate pixel_engine as px;
use px::traits::*;
fn main() {
px::launch(async move { // the launch function is just a utility function to block on async, even on the web
let game = px::EngineWrapper::new("Lines".to_owned(), (25, 25, 20));
let mut start = (0, 0);
let mut end = (5i32, 5i32);
game.run(move |game: &mut engine::Engine| {
// Drawing to the screen:
game.clear([0, 0, 0].into());
game.draw_line(
start,
end,
[1.0, 1.0, 1.0].into(),
);
game.draw(start, [0, 255, 0].into());
game.draw(end, [255, 0, 0].into());
some_failible_function()?; // You can return errors, but it will crash the program and print the error message
// Handling inputs
game.get_key(px::inputs::Keycodes::Escape).any() {
return Ok(false); // Returning Ok(false) is the only way to do a clean shutdown
}
Ok(true) // Continue to next frame
});
});
}
This is the stripped-down code of the line
example.
There are some examples that aren't really useful (like the input.rs
). They are here to make sure I don't break stuff.