use sdl2::rect::Rect; use sdl2::render::Canvas; use sdl2::video::Window; use component::{Renderable, Updatable}; pub struct GameObject<'a> { pub x: f32, pub y: f32, pub w: u32, pub h: u32, pub dx: f32, // TODO moved to PlayerPhysicsComponent pub dy: f32, // TODO moved to PlayerPhysicsComponent pub gravity: f32, // TODO moved to PlayerPhysicsComponent pub on_ground: bool, physics: Box, graphics: Box, } impl<'a> GameObject<'a> { pub fn new( x: f32, y: f32, physics: Box, graphics: Box, ) -> GameObject<'a> { GameObject { x: x, y: y, w: 32, h: 32, dx: 0.0, dy: 0.0, gravity: 0.3, on_ground: false, physics: physics, graphics: graphics, } } #[inline] pub fn update(&self) { self.physics.update(self); } #[inline] pub fn render(&self, elapsed: f64, renderer: &mut Canvas, destination: &Rect) { self.graphics.render(self, elapsed, renderer, destination); } #[inline] pub fn to_rect(&self) -> Rect { Rect::new(self.x as i32, self.y as i32, 32, 32) } }