use std::collections::HashMap;
use winit::event::VirtualKeyCode;
pub trait GameObject: GameObjectClone + Sync + Send {
fn obj_type(&self) -> String where Self: Sized + Clone;
fn persistant(&self) -> bool where Self: Sized + Clone;
fn on_key_pressed(
&mut self, code: VirtualKeyCode,
global_objs: &Vec<Box<dyn GameObject>>,
rooms: &HashMap<String, Vec<Box<dyn GameObject>>>,
cur_room: &mut String
);
fn on_key_released(
&mut self, code: VirtualKeyCode,
global_objs: &Vec<Box<dyn GameObject>>,
rooms: &HashMap<String, Vec<Box<dyn GameObject>>>,
cur_room: &mut String
);
fn update(
&mut self, delta_time: f32,
global_objs: &Vec<Box<dyn GameObject>>,
rooms: &HashMap<String, Vec<Box<dyn GameObject>>>,
cur_room: &mut String
);
fn draw(&self, text_buf: &mut [[char; 81]; 25]);
}
pub trait GameObjectClone: {
fn clone_box(&self) -> Box<dyn GameObject>;
}
impl<T> GameObjectClone for T where T: 'static + GameObject + Clone {
fn clone_box(&self) -> Box<dyn GameObject> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn GameObject> {
fn clone(&self) -> Self {
self.clone_box()
}
}