Skip to main content

Game

Trait Game 

Source
pub trait Game {
    // Required methods
    fn init(lili: &Lili) -> Self;
    fn update(&mut self, lili: &Lili);
    fn draw(&mut self, lili: &Lili);
}
Expand description

Implement this trait for your game.

It provides methods to init, update and draw your game.

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

Required Methods§

Source

fn init(lili: &Lili) -> Self

Use this to initialize your game.

This method is only called one time before the game start or after a rest of the game.

Source

fn update(&mut self, lili: &Lili)

Use this to update your game.

This method is called once per game loop iteration, before draw is called.

Source

fn draw(&mut self, lili: &Lili)

Use this to draw your game.

This method is called once per game loop iteration, after update is called..

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§