Did stuff.
This commit is contained in:
@@ -3,6 +3,7 @@ use sdl2::render::Renderer;
|
||||
|
||||
use component::{Updatable, Renderable};
|
||||
|
||||
|
||||
pub struct GameObject<'a> {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
@@ -13,11 +14,15 @@ pub struct GameObject<'a> {
|
||||
pub gravity: f32, // TODO moved to PlayerPhysicsComponent
|
||||
pub on_ground: bool,
|
||||
physics: Box<Updatable + 'a>,
|
||||
graphics: Box<Renderable + 'a>
|
||||
graphics: Box<Renderable + 'a>,
|
||||
}
|
||||
|
||||
impl<'a> GameObject<'a> {
|
||||
pub fn new(x: f32, y: f32, physics: Box<Updatable + 'a>, graphics: Box<Renderable + 'a>) -> GameObject<'a> {
|
||||
pub fn new(x: f32,
|
||||
y: f32,
|
||||
physics: Box<Updatable + 'a>,
|
||||
graphics: Box<Renderable + 'a>)
|
||||
-> GameObject<'a> {
|
||||
GameObject {
|
||||
x: x,
|
||||
y: y,
|
||||
@@ -28,18 +33,21 @@ impl<'a> GameObject<'a> {
|
||||
gravity: 0.3,
|
||||
on_ground: false,
|
||||
physics: physics,
|
||||
graphics: graphics
|
||||
graphics: graphics,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update(&self) {
|
||||
self.physics.update(self);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn render(&self, elapsed: f64, renderer: &mut Renderer, 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user