Moved physics to physics.
This commit is contained in:
@@ -8,9 +8,9 @@ pub struct GameObject<'a> {
|
|||||||
pub y: f32,
|
pub y: f32,
|
||||||
pub w: u32,
|
pub w: u32,
|
||||||
pub h: u32,
|
pub h: u32,
|
||||||
pub dx: f32,
|
pub dx: f32, // TODO moved to PlayerPhysicsComponent
|
||||||
pub dy: f32,
|
pub dy: f32, // TODO moved to PlayerPhysicsComponent
|
||||||
pub gravity: f32,
|
pub gravity: f32, // TODO moved to PlayerPhysicsComponent
|
||||||
pub on_ground: bool,
|
pub on_ground: bool,
|
||||||
physics: Box<Updatable + 'a>,
|
physics: Box<Updatable + 'a>,
|
||||||
graphics: Box<Renderable + 'a>
|
graphics: Box<Renderable + 'a>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use sdl2::keyboard::Keycode;
|
|||||||
pub struct KeyboardHandler {
|
pub struct KeyboardHandler {
|
||||||
pressed_keys: HashMap<Keycode, bool>,
|
pressed_keys: HashMap<Keycode, bool>,
|
||||||
released_keys: HashMap<Keycode, bool>,
|
released_keys: HashMap<Keycode, bool>,
|
||||||
held_keys: HashMap<Keycode, bool>
|
held_keys: HashMap<Keycode, bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyboardHandler {
|
impl KeyboardHandler {
|
||||||
@@ -14,7 +14,7 @@ impl KeyboardHandler {
|
|||||||
KeyboardHandler {
|
KeyboardHandler {
|
||||||
pressed_keys: HashMap::new(),
|
pressed_keys: HashMap::new(),
|
||||||
released_keys: HashMap::new(),
|
released_keys: HashMap::new(),
|
||||||
held_keys: HashMap::new()
|
held_keys: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ fn main() {
|
|||||||
|
|
||||||
let timer = Timer::new();
|
let timer = Timer::new();
|
||||||
|
|
||||||
let mut player = GameObject::new(390.0, 390.0, Box::new(PlayerPhysicsComponent), Box::new(PlayerGraphicsComponent::new(&player_sprites)));
|
let mut player = GameObject::new(390.0, 390.0, Box::new(PlayerPhysicsComponent::new()), Box::new(PlayerGraphicsComponent::new(&player_sprites)));
|
||||||
|
|
||||||
let mut keyboard = KeyboardHandler::new();
|
let mut keyboard = KeyboardHandler::new();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,21 @@ use sprite::{Sprite, StaticSprite, AnimatedSprite};
|
|||||||
use game_object::GameObject;
|
use game_object::GameObject;
|
||||||
use component::{Updatable, Renderable};
|
use component::{Updatable, Renderable};
|
||||||
|
|
||||||
pub struct PlayerPhysicsComponent;
|
pub struct PlayerPhysicsComponent {
|
||||||
|
pub dx: f32,
|
||||||
|
pub dy: f32,
|
||||||
|
pub gravity: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerPhysicsComponent {
|
||||||
|
pub fn new() -> PlayerPhysicsComponent {
|
||||||
|
PlayerPhysicsComponent {
|
||||||
|
dx: 0.0,
|
||||||
|
dy: 0.0,
|
||||||
|
gravity: 0.3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Updatable for PlayerPhysicsComponent {
|
impl Updatable for PlayerPhysicsComponent {
|
||||||
fn update(&self, _: &GameObject) {
|
fn update(&self, _: &GameObject) {
|
||||||
|
|||||||
Reference in New Issue
Block a user