Crate rust_pixel

source ·
Expand description

RustPixel is a rust 2d mini-game engine. It is ideal for fast prototyping of 2d pixel style games it is also a perfect choice for developing and debugging CPU-heavy game core algorithms You can compile your core algorithms to ffi or wasm libs, and used by other gaming frontend or backend

It supports two rendering mode: text mode and graphical mode. Text mode runs in a terminal. Graphical mode supports SDL running in a OS window or wasm on a webpage.

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.

Modules§

  • disjoint-set data structure, astar here integrates some common algorithms e.g. disjoint-set data structure, astar
  • resource manager, supporting async load to better compatible with wasm web 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/
  • calls audio module to play sounds audio provides playing music and sound effect, reference https://docs.rs/rodio
  • 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.
  • 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
  • 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 provides various log functions, reference https://docs.rs/log4rs
  • Render module, it supports two rendering mode: text mode and graphical mode. adapter: render adapter interface (crossterm, sdl, web). cell: a bse 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 graphical mode.
  • 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§

  • Used to simplify the call to set_content_by_asset method

Constants§