pub trait GameObjectBehavior<Img, Snd, Fnt, Spr, Rm, Data>: GameObjectBehaviorClone<Img, Snd, Fnt, Spr, Rm, Data>where
Spr: IndexRestriction,
Img: IndexRestriction,
Snd: IndexRestriction,
Fnt: IndexRestriction,
Rm: IndexRestriction,
Data: Clone,{
// 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§
fn state(&self) -> GameObjectState<Img, Spr, Data>
fn set_state(&mut self, new_state: &GameObjectState<Img, Spr, Data>)
Provided Methods§
Sourcefn 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 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.