Skip to main content

Lili

Struct Lili 

Source
pub struct Lili { /* private fields */ }
Expand description

This struct give access to the main api of the musi lili engine.

It can be used to check current states of buttons, keys and the mouse.

It can be used to draw on the screen.

§Example

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"));
}

Implementations§

Source§

impl Lili

Source

pub fn clear(&self, color: u8)

Sets all pixel of the screen to the given color.

  • color: the color to fill the screen with (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        // clears the screen with color 0
        lili.clear(0);
    }
Source

pub fn cam(&self, x: i32, y: i32)

Sets the position of the camera.

  • x: the x offset of the camera.
  • y: the y offset of the camera.
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        lili.cam(5, 5);
        // the rect starts now at (6/6) instead of (5/5)
        lili.rect(1, 1, 5, 5, 3);
    }
Source

pub fn tra(&self, color: Option<u8>)

Defines a color that is ignored during drawing operations.

  • color: the color that should be ignored. Set it to None to reset the ignored color.
§Example
    fn draw(&mut self, lili: &Lili) {
        // clears the screen with color 0
        lili.clear(0);
        lili.tra(Some(1));
        // now only the second rect with color 2 is visible
       lili.rect(0, 0, 5, 5, 1);
       lili.rect(1, 1, 4, 4, 2);
    }
Source

pub fn clip(&self, x: i32, y: i32, width: u32, height: u32)

Defines a clipping region. It will be drawn only the stuff that is inside of the defined area.

  • x: the x coordinate of the clipping area.
  • y: the y coordinate of the clipping area.
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        lili.clip(2, 2, 10, 10);
        // on the screen only the part of the rect is visible that is inside the clipping area.
        lili.fill_rect(0, 0, 14, 14, 3);
    }
Source

pub fn res_clip(&self)

Resets the current clipping region. Check clip.

§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        lili.clip(2, 2, 10, 10);
        // on the screen only the part of the rect is visible that is inside the clipping area.
        lili.fill_rect(0, 0, 14, 14, 3);
        lili.res_clip();
        // this rect is now full visible
        lili.fill_rect(0, 0, 12, 12, 2);
    }
Source

pub fn pix(&self, x: i32, y: i32, color: u8)

Draws a single pixel on the given coordinate.

  • x: the x coordinate of the pixel.
  • y: the y coordinate of the pixel.
  • color: the color of the pixel (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws a pixel on (2/3) with color 3.
        lili.pix(0, 0, 3);
    }
Source

pub fn rect(&self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Draws a bordered rectangle.

  • x0: the start x coordinate (top-left).
  • y0: the start y coordinate (top-left).
  • x1: the end x coordinate (bottom-right).
  • y1: the end y coordinate (bottom-right).
  • color: the color of the rectangles border (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws a rect with width of 2 and height of 5
        lili.rect(1, 1, 3, 6, 3);
    }
Source

pub fn fill_rect(&self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Draws a filled rectangle.

  • x0: the start x coordinate (top-left).
  • y0: the start y coordinate (top-left).
  • x1: the end x coordinate (bottom-right).
  • y1: the end y coordinate (bottom-right).
  • color: the color of the rect (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws a rect with width of 2 and height of 5
        lili.fill_rect(1, 1, 3, 6, 3);
    }
Source

pub fn circ(&self, x: i32, y: i32, radius: u32, color: u8)

Draws a bordered circle.

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • color: the color of the circles border (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws bordered circle with center (x: 5, y: 5)
        lili.circ(5, 5, 5, 3);
    }
Source

pub fn fill_circ(&self, x: i32, y: i32, radius: u32, color: u8)

Draws a filled circle.

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • color: the fill color of the circle (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws bordered circle with center (x: 5, y: 5)
        lili.fill_circ(5, 5, 5, 3);
    }
Source

pub fn line(&self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Draws a line form x0/y0 to x1/y1

  • x0: the start x coordinate (top-left).
  • y0: the start y coordinate (top-left).
  • x1: the end x coordinate (bottom-right).
  • y1: the end y coordinate (bottom-right).
  • color: the color of the line (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws a line from (1/1) to (3/6)
        lili.line(1, 1, 3, 6, 3);
    }
Source

pub fn txt(&self, text: &str, x: i32, y: i32, color: u8) -> i32

Prints a text.

  • text: the text to display.
  • x: the x coordinate of the text.
  • y: the y coordinate of the text.
  • color: the color of the text (needs to be a value between 0 and 3).
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws the word "toki" on the screen
        lili.txt("toki", 1, 1, 3);
    }
Source

pub fn spr(&self, sprite: u8, x: i32, y: i32, flip_x: bool, flip_y: bool)

Draws a sprite from the sprite sheet to the screen

  • sprite: the sprite to draw (need to be a value between 0 and 244).
  • x: the x coordinate of the sprite on the screen.
  • y: the y coordinate of the sprite on the screen.
  • flip_x: if set to true the sprite is flipped horizontal.
  • flip_y: if set to true the sprite is flipped vertical.
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws sprite 0
        lili.spr(0, 1, 1, false, false);
    }
Source

pub fn spr_ext( &self, sprite: u8, x: i32, y: i32, width: f32, height: f32, flip_x: bool, flip_y: bool, )

Draws a sprite with fractional dimensions or a range of sprites.

Supports two modes:

  1. Fractional mode: spr(sprite, x, y, width_ratio, height_ratio) - draws a portion of a single sprite
    • width_ratio: horizontal portion to draw (0.0 to 1.0)
    • height_ratio: vertical portion to draw (0.0 to 1.0)
  2. Range mode: spr(sprite, x, y, width_count, height_count) - draws multiple sprites in a grid
    • width_count: number of sprites horizontally (must be > 1.0)
    • height_count: number of sprites vertically (must be > 1.0)
  • sprite: The starting sprite index
  • x: The x coordinate to draw at
  • y: The y coordinate to draw at
  • width: Width ratio (fractional) or count (range)
  • height: Height ratio (fractional) or count (range)
  • flip_x: Whether to flip the sprite horizontally
  • flip_y: Whether to flip the sprite vertically
Source

pub fn map( &self, cell_x: u32, cell_y: u32, screen_x: i32, screen_y: i32, cell_width: u32, cell_height: u32, )

Draws the map.

  • cell_x: cell x coordinate on the map..
  • cell_y: cell y coordinate on the map.
  • screen_x: x coordinate on the screen in pixel.
  • screen_y: y coordinate on the screen in pixel.
  • cell_width: horizontal number of cells to draw.
  • cell_height: vertical number of cells to draw.
§Example
    fn draw(&mut self, lili: &Lili) {
        lili.clear(0);
        // draws the whole map
        lili.map(0, 0, 0, 0, MAP_WIDTH, MAP_HEIGHT);
    }
Source

pub fn set_tile(&self, x: u32, y: u32, tile: u8)

Sets the sprite number on the given map position.

Source

pub fn get_tile(&self, x: u32, y: u32) -> Option<u8>

Returns the

Source

pub fn set_flag(&self, sprite: u8, flag: u8, value: bool)

Sets the flag for the given sprite

Source

pub fn get_flag(&self, sprite: u8, flag: u8) -> bool

Returns if the given flag on the sprite is set.

Source

pub fn btn(&self, button: impl Into<Button>) -> bool

Returns true if the given button is pressed.

Source

pub fn get_mouse(&self) -> Point

Returns the current mouse position.

Source

pub fn get_scroll(&self) -> Point

Returns the current scroll wheel delta.

Source

pub fn key(&self, key: &Key) -> bool

Returns true if the given key is pressed.

Source

pub fn get_keys(&self) -> Vec<Key>

Returns the list of all pressed keys.

Source

pub fn set_pal(&self, palette: Palette)

Sets the current used color palette.

Source

pub fn get_pal(&self) -> Palette

Return the current used color palette.

Source

pub fn sound(&self, name: &str, samples: Vec<f32>, rate: u32)

Creates a new sound and stores it with the given name.

This function generates sound data based on the provided parameters.

§Arguments
  • name - A string slice that holds the name of the sound.
  • samples - The raw audio samples.
  • rate - The sample rate in Hz.
Source

pub fn play(&self, sound: &str, volume: f32)

Plays the sound associated with the given name.

This function retrieves the sound data associated with the given name and plays it using the sound function.

§Arguments
  • sound - A string slice that holds the name of the sound to play
  • volume - The volume of the sound. 1.0 is the normal volume.
Source

pub fn stop(&self, sound: &str)

Stops the sound associated with the given name.

This function stops the sound with the given name that was started with play.

§Arguments
  • sound - A string slice that holds the name of the sound to stop.
Source

pub fn stop_all(&self)

Stops all active sounds.

Source

pub fn save(&self, name: &str, content: &[u8])

Saves a game state with the given name and content. Save games will be created per game in the settings directory of the user.

§Paths

Linux: /home/alice/.config/{game_name}/{save_name}.save macOS: /Users/Alice/Library/Application Support/{game_name}/{save_name}.save Windows: C:\Users\Alice\AppData\Roaming\{game_name}\{save_name}.save Android: /data/data/{game_name}/{save_name}.save Web: Save games are stored and load using the Web Storage API

Source

pub fn load(&self, name: &str) -> Option<Vec<u8>>

Loads a save game by a name as identifier. Save games will be created per game in the settings directory of the user.

If there is no save game with the given name this method returns None.

§Paths

Linux: /home/alice/.config/{game_name}/{save_name}.save macOS: /Users/Alice/Library/Application Support/{game_name}/{save_name}.save Windows: C:\Users\Alice\AppData\Roaming\{game_name}\{save_name}.save Android: /data/data/{game_name}/{save_name}.save Web: Save games are stored and load using the Web Storage API

Source

pub fn rm_save(&self, name: &str)

Removes the save game with the given name

Source

pub fn save_games(&self) -> Option<Vec<String>>

Returns all names of the save games.

Source

pub fn quit(&self)

Quit the game before the next frame is executed.

Source

pub fn fullscreen(&self, fullscreen: bool)

Set or unset the window to display fullscreen.

Auto Trait Implementations§

§

impl !Freeze for Lili

§

impl !RefUnwindSafe for Lili

§

impl !Send for Lili

§

impl !Sync for Lili

§

impl !UnwindSafe for Lili

§

impl Unpin for Lili

§

impl UnsafeUnpin for Lili

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.