Starting to do physics
This commit is contained in:
+12
-19
@@ -1,11 +1,6 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use sfml::window::Event;
|
||||
use sfml::graphics::{
|
||||
RenderTarget,
|
||||
RenderStates,
|
||||
Drawable,
|
||||
};
|
||||
|
||||
use engine::character::Character;
|
||||
|
||||
@@ -14,6 +9,7 @@ pub struct Scene {
|
||||
|
||||
/// The characters contained in the scene.
|
||||
characters: Vec<Character>,
|
||||
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
@@ -32,8 +28,15 @@ impl Scene {
|
||||
|
||||
/// Updates the whole scene.
|
||||
pub fn update(&mut self, duration: &Duration) {
|
||||
|
||||
for c in &mut self.characters {
|
||||
c.update(duration);
|
||||
|
||||
if c.position.y > 500.0 {
|
||||
c.position.y = 500.0;
|
||||
c.speed.y = 0.0;
|
||||
c.ground_collision();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,22 +46,12 @@ impl Scene {
|
||||
c.manage_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Scene {
|
||||
fn draw<'a: 'shader, 'texture, 'shader, 'shader_texture>(
|
||||
&'a self,
|
||||
target: &mut RenderTarget,
|
||||
states: RenderStates<'texture, 'shader, 'shader_texture>
|
||||
) {
|
||||
|
||||
for c in &self.characters {
|
||||
let mut s = RenderStates::default();
|
||||
s.transform = states.transform.clone();
|
||||
s.blend_mode = states.blend_mode;
|
||||
c.draw(target, s);
|
||||
}
|
||||
/// Returns a reference to the characters of the scene.
|
||||
pub fn characters(&self) -> &Vec<Character> {
|
||||
&self.characters
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Trait that needs to be implemented for everything that can be updatable.
|
||||
|
||||
Reference in New Issue
Block a user