Expand description
§musi lili
musi lili is a retro game engine for GB styled games written in Rust. Inspired by pico8.
§How to use this crate
§Add musi_lili to your Cargo.toml
file
[package]
name = "my_game"
version = "0.1.0"
edition = "2021"
[dependencies]
musi_lili = { version = "0.3" }
§Create your game
Create a struct that defines your game and implements the musi_lili::Game
trait.
After that you can start your game by calling musi_lil::run
with the type of your game.
use musi_lili::{Game, Lili};
struct MyGame;
impl Game for MyGame {
fn init(_lili: &Lili) -> Self {
Self
}
fn update(&mut self, _lili: &Lili) {
// the code to update your game
}
fn draw(&mut self, lili: &Lili) {
// draw your game
lili.clear(0);
lili.txt("toki", 5, 5, 3);
}
}
fn main() {
musi_lili::run::<MyGame>(musi_lili::load!("my-game"));
}
§Cargo Features
std
: use rust std (default).gamepad
: activate gamepad support (needslibudev
to be installed).slint-femtovg
: use winit with femtovg renderer as slint backend (default).slint-software
: use winit with software renderer as slint backend.experimental
: enable this feature to try out experimental features that are not yet ready for production.
§Used third party libraries
Library | License | Used for |
---|---|---|
Slint | GNU GPlv3, Royalty-free or Paid | Window, framebuffer and event handling |
embedded-graphics | Apache 2.0 or MIT | Pixel art drawing |
dirs-next | Apache 2.0 or MIT | Get user settings path |
serde | Apache 2.0 or MIT | Serialize / Deserialize game data |
serde-json | Apache 2.0 or MIT | Serialize / Deserialize game data |
gilrs | Apache 2.0 or MIT | Support for game controllers |
web-time | Apache 2.0 or MIT | Use Instant::now() on the web |
web-sys | Apache 2.0 or MIT | Used for web save game management |
Macros§
- load
- Loads the
GameData
from$CARGO_MANIFEST_DIR"/assets/name.lili
. Creates the file if not exists.
Structs§
- Color
- Used to define a color for of a custom
Palette
. - Game
Data - This struct is used to load and save the data of the game like sprites and map.
- Lili
- This struct give access to the main api of the musi lili engine.
- Point
- Describes a point with x ans y.
Enums§
- Button
- This enum defines an button.
- Key
- Defines a keyboard key.
- Palette
- This enum defines all available color palettes.
Constants§
- CHAR_
HEIGHT - Gets the height of a char in pixel.
- CHAR_
WIDTH - Gets the width of a char in pixel.
- DISPLAY_
HEIGHT - Gets the height of the display in pixel.
- DISPLAY_
WIDTH - Gets the width of the display in pixel.
- MAP_
HEIGHT - Defines the maximum height of the map in number of sprites.
- MAP_
WIDTH - Defines the maximum width of the map in number of sprites.
- SPRITE_
HEIGHT - Gets the height of a sprite in pixel.
- SPRITE_
WIDTH - Gest the width of a sprite in pixel.
Traits§
- Game
- Implement this trait for your game.
Functions§
- data_
from_ path - Read
GameData
from given path, creates the file if not exits. - data_
from_ str - Reads a json string and convert it to a
GameData
object. - rgb
- Used to generate a
Color
. - run
- save_
data - Saves
GameData
to the given path. - settings_
dir - This is a helper function to read the settings directory of the current user depending on the operating system.