Did stuff.

This commit is contained in:
2017-02-03 10:00:07 +01:00
parent 8178b415ae
commit ec42cb33e0
13 changed files with 277 additions and 111 deletions

View File

@@ -12,7 +12,7 @@ pub struct StaticSprite<'a> {
x: i32,
y: i32,
pub flip_horizontal: bool,
pub flip_vertical: bool
pub flip_vertical: bool,
}
impl<'a> StaticSprite<'a> {
@@ -22,14 +22,20 @@ impl<'a> StaticSprite<'a> {
x: x,
y: y,
flip_horizontal: false,
flip_vertical: false
flip_vertical: false,
}
}
}
impl<'a> Sprite for StaticSprite<'a> {
fn render(&self, _: f64, drawer: &mut Renderer, destination: &Rect) {
let _ = drawer.copy_ex(self.texture, Some(Rect::new(self.x, self.y, 16, 16)), Some(*destination), 0.0, None, self.flip_horizontal, self.flip_vertical);
let _ = drawer.copy_ex(self.texture,
Some(Rect::new(self.x, self.y, 16, 16)),
Some(*destination),
0.0,
None,
self.flip_horizontal,
self.flip_vertical);
}
}
@@ -42,7 +48,7 @@ pub struct AnimatedSprite<'a> {
frames: u32,
frame_time: f64,
frame: RefCell<u32>,
time: RefCell<f64>
time: RefCell<f64>,
}
impl<'a> AnimatedSprite<'a> {
@@ -56,7 +62,7 @@ impl<'a> AnimatedSprite<'a> {
frame: RefCell::new(0),
frames: frames,
time: RefCell::new(0.0),
frame_time: 1000.0 / fps as f64
frame_time: 1000.0 / fps as f64,
}
}
}
@@ -73,6 +79,12 @@ impl<'a> Sprite for AnimatedSprite<'a> {
let x = self.x + (*frame * 16) as i32;
let _ = drawer.copy_ex(self.texture, Some(Rect::new(x, self.y, 16, 16)), Some(*destination), 0.0, None, self.flip_horizontal, self.flip_vertical);
let _ = drawer.copy_ex(self.texture,
Some(Rect::new(x, self.y, 16, 16)),
Some(*destination),
0.0,
None,
self.flip_horizontal,
self.flip_vertical);
}
}