Start to do collisions
This commit is contained in:
+14
-2
@@ -3,6 +3,7 @@ use std::time::Duration;
|
||||
use sfml::window::Event;
|
||||
|
||||
use engine::character::Character;
|
||||
use engine::map::Map;
|
||||
|
||||
/// Contains everything needed to play.
|
||||
pub struct Scene {
|
||||
@@ -10,6 +11,9 @@ pub struct Scene {
|
||||
/// The characters contained in the scene.
|
||||
characters: Vec<Character>,
|
||||
|
||||
/// The map of the scene.
|
||||
map: Map,
|
||||
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
@@ -18,6 +22,7 @@ impl Scene {
|
||||
pub fn new() -> Scene {
|
||||
Scene {
|
||||
characters: vec![],
|
||||
map: Map::new(30, 30),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +35,12 @@ impl Scene {
|
||||
pub fn update(&mut self, duration: &Duration) {
|
||||
|
||||
for c in &mut self.characters {
|
||||
let old = c.position;
|
||||
c.update(duration);
|
||||
|
||||
if c.position.y > 500.0 {
|
||||
c.position.y = 500.0;
|
||||
|
||||
if let Some(height) = self.map.collides(old, c.position) {
|
||||
c.position.y = height;
|
||||
c.speed.y = 0.0;
|
||||
c.ground_collision();
|
||||
}
|
||||
@@ -52,6 +59,11 @@ impl Scene {
|
||||
&self.characters
|
||||
}
|
||||
|
||||
/// Returns a reference to the map.
|
||||
pub fn map(&self) -> &Map {
|
||||
&self.map
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Trait that needs to be implemented for everything that can be updatable.
|
||||
|
||||
Reference in New Issue
Block a user