#screen #wgpu #modification #pixel-engine #decals #reproduction #old-pixel-game-engine

pixel_engine_backend

An thin layer around wgpu that allow the modification of a texutre displayed on the screen

12 releases (7 breaking)

0.8.0 Dec 29, 2022
0.6.1 Dec 2, 2022
0.5.4 Nov 27, 2022
0.4.1 Dec 21, 2021
0.2.1 Jul 26, 2020

#454 in Graphics APIs

Download history 1/week @ 2024-07-13 17/week @ 2024-09-21 3/week @ 2024-09-28

65 downloads per month
Used in 2 crates (via pixel_engine)

MIT license

37KB
765 lines

pixel_engine

A reproduction of the oldPixelGameEngine(by OneLoneCoder) written in rust This crate is split between 3 crates:

pixel_engine_backend

This is provide wrapper around wgpu. It handles the drawing of decals and the main screen

pixel_engine_draw

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

pixel_engine

This is the core of the projects, It is the main library, aimed to be used by the user. This provide the Engine struct

How to use

There are plenty of examples in the examples folder. You only need to run cargo run --bin=<NAME>, or go to 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.

Dependencies

~11–23MB
~352K SLoC