GameObjectBehavior

Trait GameObjectBehavior 

Source
pub trait GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>: GameObjectBehaviorClone<Img, Snd, Fnt, Spr, Rm, Data>{
    // Required methods
    fn state(&self) -> GameObjectState<Img, Spr, Data>;
    fn set_state(&mut self, new_state: &GameObjectState<Img, Spr, Data>);
    fn on_reset(&mut self) -> bool;

    // Provided methods
    fn update(
        &mut self,
        _delta: f64,
        _ctl_objs: &Vec<Box<dyn ControlObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>>,
        _others: &Vec<Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>>,
    ) -> (Option<Rm>, Vec<Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>>) { ... }
    fn handle_sdl_event(&mut self, _event: &Event) { ... }
    fn on_collision(
        &mut self,
        _other: &Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>,
    ) { ... }
    fn render(
        &mut self,
        cnv: &mut Canvas<Window>,
        imgs: &HashMap<Img, Image<'_>>,
        _snds: &HashMap<Snd, Sound<'_>>,
        _fonts: &HashMap<Fnt, Font<'_, '_>>,
        _creator: &TextureCreator<WindowContext>,
        elapsed: f64,
    ) -> Result<(), String> { ... }
    fn should_remove(&self) -> bool { ... }
}
Expand description

All game objects should implement these

Note: the generic types refer to custom enums for indexing items:

  • Img -> Id for going between the various Images loaded in
  • Snd -> Same but for sounds
  • Fnt -> Font
  • Spr -> Sprites
  • Rm -> Rooms
  • Data -> Custom data for each object

Required Methods§

Source

fn state(&self) -> GameObjectState<Img, Spr, Data>

Source

fn set_state(&mut self, new_state: &GameObjectState<Img, Spr, Data>)

Source

fn on_reset(&mut self) -> bool

Let game objects reset their data on room load. If you return true, the object is removed from the room

Provided Methods§

Source

fn update( &mut self, _delta: f64, _ctl_objs: &Vec<Box<dyn ControlObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>>, _others: &Vec<Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>>, ) -> (Option<Rm>, Vec<Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>>)

Let game objects modify their state every loop. Return a room to change to and objects to add to the room.

Source

fn handle_sdl_event(&mut self, _event: &Event)

Source

fn on_collision( &mut self, _other: &Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>, )

Source

fn render( &mut self, cnv: &mut Canvas<Window>, imgs: &HashMap<Img, Image<'_>>, _snds: &HashMap<Snd, Sound<'_>>, _fonts: &HashMap<Fnt, Font<'_, '_>>, _creator: &TextureCreator<WindowContext>, elapsed: f64, ) -> Result<(), String>

Source

fn should_remove(&self) -> bool

Trait Implementations§

Source§

impl<Img, Snd, Fnt, Spr, Rm, Data> Clone for Box<dyn GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§