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
impl Lili
Sourcepub fn clear(&self, color: u8)
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);
}
Sourcepub fn cam(&self, x: i32, y: i32)
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);
}
Sourcepub fn tra(&self, color: Option<u8>)
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 toNoneto 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);
}
Sourcepub fn clip(&self, x: i32, y: i32, width: u32, height: u32)
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);
}
Sourcepub fn res_clip(&self)
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);
}
Sourcepub fn pix(&self, x: i32, y: i32, color: u8)
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);
}
Sourcepub fn rect(&self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
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);
}
Sourcepub fn fill_rect(&self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
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);
}
Sourcepub fn circ(&self, x: i32, y: i32, radius: u32, color: u8)
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);
}
Sourcepub fn fill_circ(&self, x: i32, y: i32, radius: u32, color: u8)
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);
}
Sourcepub fn line(&self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
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);
}
Sourcepub fn txt(&self, text: &str, x: i32, y: i32, color: u8) -> i32
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);
}
Sourcepub fn spr(&self, sprite: u8, x: i32, y: i32, flip_x: bool, flip_y: bool)
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);
}
Sourcepub fn spr_ext(
&self,
sprite: u8,
x: i32,
y: i32,
width: f32,
height: f32,
flip_x: bool,
flip_y: bool,
)
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:
- 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)
- 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 indexx: The x coordinate to draw aty: The y coordinate to draw atwidth: Width ratio (fractional) or count (range)height: Height ratio (fractional) or count (range)flip_x: Whether to flip the sprite horizontallyflip_y: Whether to flip the sprite vertically
Sourcepub fn map(
&self,
cell_x: u32,
cell_y: u32,
screen_x: i32,
screen_y: i32,
cell_width: u32,
cell_height: u32,
)
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);
}
Sourcepub fn set_tile(&self, x: u32, y: u32, tile: u8)
pub fn set_tile(&self, x: u32, y: u32, tile: u8)
Sets the sprite number on the given map position.
Sourcepub fn get_flag(&self, sprite: u8, flag: u8) -> bool
pub fn get_flag(&self, sprite: u8, flag: u8) -> bool
Returns if the given flag on the sprite is set.
Sourcepub fn btn(&self, button: impl Into<Button>) -> bool
pub fn btn(&self, button: impl Into<Button>) -> bool
Returns true if the given button is pressed.
Sourcepub fn get_scroll(&self) -> Point
pub fn get_scroll(&self) -> Point
Returns the current scroll wheel delta.
Sourcepub fn sound(&self, name: &str, samples: Vec<f32>, rate: u32)
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.
Sourcepub fn play(&self, sound: &str, volume: f32)
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 playvolume- The volume of the sound. 1.0 is thenormalvolume.
Sourcepub fn stop(&self, sound: &str)
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.
Sourcepub fn save(&self, name: &str, content: &[u8])
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
Sourcepub fn load(&self, name: &str) -> Option<Vec<u8>>
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
Sourcepub fn save_games(&self) -> Option<Vec<String>>
pub fn save_games(&self) -> Option<Vec<String>>
Returns all names of the save games.
Sourcepub fn fullscreen(&self, fullscreen: bool)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.