Crate rust_pixel

Source
Expand description

RustPixel is a 2D game engine & rapid prototyping tools supporting both text and graphics rendering modes. It is suitable for creating 2D pixel-style games and developing terminal applications. it is also a perfect choice for developing and debugging CPU-heavy core algorithms You can compile your core algorithms to ffi or wasm libs, and used by other gaming frontend or backend

Text Mode: Built with crossterm, runs in the terminal, and uses ASCII & Unicode Emoji for drawing. Graphical Mode (SDL2): Built with SDL2, using PETSCII & custom graphics symbols for rendering. Graphical Mode (Web): Similar to the SDL2 mode, but the core logic is compiled into WASM and rendered using WebGL and JavaScript (refer to rust-pixel/web-template/pixel.js).

In RustPixel, game scenes are rendered using individual Cell and managed by Buffer

Various modules asset, audio, event, game, log, render, algorithm, util are offered to ease game development

We also provide a base mode in which only algorithm, event and util modules are compiled. Base mode requires fewer dependencies and therefore it is a good fit for compiling to ffi or wasm libs.

Re-exports§

pub use pixel_macro;

Modules§

algorithm
disjoint-set data structure, astar here integrates some common algorithms e.g. disjoint-set data structure, astar
asset
resource manager, supporting async load to better compatible with wasm mode asset provides the resource manager. It supports async load. It calls JavaScript methods to load resources asynchronously when runs in wasm mode. https://www.reddit.com/r/rust/comments/8ymzwg/common_data_and_behavior/
audio
calls audio module to play sounds audio provides playing music and sound effect, reference https://docs.rs/rodio
context
public variables, including rendering adapter Context encapsulates several public variables including stage,state,input events, etc. For simplicity, state is set to u8 type,you can create your own states using enums in your games. Context also integrates an RNG for user’s convenience An render adapter is also provided to make it compatible with web, SDL, or terminal modes. Finally, an asset_manager is included as well.
event
processing input events, timer and other custom events this event module provides a global event centre and a global timer centre. It is based on Mutex. Mutex is easy to use despite a tiny loss of performance. Another way to achieve this is to put Event and Timer in context. However, it requires access to context from everywhere, which is again not ideal
game
integrates model and render, encapsulates the main loop Game encapsulate Model and Render classes and implements the main loop Be aware that all the Game, Model and Render instances have the same lifetime
log
log log provides various log functions, reference https://docs.rs/log4rs
render
Render module, it supports two rendering mode: text mode and graphics mode. adapter: render adapter interface (crossterm, sdl, web). cell: a base drawing unit i.e. a character. buffer: a vector comprised of cells, managing screen buffer. sprite: basic drawing component, encapsulating further the buffer. style: define drawing attributes such as fore- and back-ground colors. panel: drawing panel is compatible with text mode and graphics mode.
util
common tools and data structures: object pool, RNG, matrix, circle, dots Utils of random rect PointU16… and a simple object pool: objpool.rs some primitive algorithm: shape.rs

Macros§

asset2sprite
Used to simplify the call to set_content_by_asset method
only_graphics_mode
only_terminal_mode

Constants§

GAME_FRAME
framerate per second, set to moderate number to save CPUs
LOGO_FRAME