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 libraries, and use them with other gaming frontends or backends.
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 libraries.
Re-exports§
pub use paste;
Modules§
- algorithm
- disjoint-set data structure, astar Here integrates some common algorithms e.g. disjoint-set data structure, A*.
- asset
- resource manager, supporting async load to better compatible with wasm mode Asset module provides the resource manager. It supports async loading. It calls JavaScript methods to load resources asynchronously when running in WASM mode. https://www.reddit.com/r/rust/comments/8ymzwg/common_data_and_behavior/
- audio
- calls audio module to play sounds Audio module provides sound playback functionality for RustPixel games.
- 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. A 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 center and a global timer center.
For comparison testing: thread_local! + Rc<RefCell
> vs Mutex + lazy_static - event_
mutex - comparison module for event system benchmarking Mutex + lazy_static implementation for comparison This is the original implementation using Mutex
- game
- integrates model and render, encapsulates the main loop Game encapsulates 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 module 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 Utilities for random, rect, PointU16… and a simple object pool: objpool.rs Some primitive algorithms: shape.rs
Macros§
- asset2sprite
- Used to simplify the call to set_content_by_asset method
- asset2sprite_
raw - New macro specifically for handling raw paths (no path processing)
- only_
graphics_ mode - only_
terminal_ mode - pixel_
game - pixel_game macro for creating game applications
Constants§
- GAME_
FRAME - framerate per second, set to moderate number to save CPUs
- LOGO_
FRAME