From 0947ce5a918207efeaf2a4f67a1cc410795f057a Mon Sep 17 00:00:00 2001 From: tom barrett Date: Mon, 1 Jul 2019 09:14:17 -0500 Subject: simpilfied interfaces and added new xml properties --- src/player.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/player.rs') diff --git a/src/player.rs b/src/player.rs index d30288b..1f941be 100644 --- a/src/player.rs +++ b/src/player.rs @@ -13,7 +13,7 @@ pub struct Player { state: PlayerState, source: Rect, timer: Instant, - animation: Option>, + animation: Vec<(usize, Rect)>, animations: HashMap>, map_height: f32, map_width: f32, @@ -26,7 +26,7 @@ impl Player { state: PlayerState::IdleLeft, source: Rect::zero(), timer: Instant::now(), - animation: None, + animation: Vec::new(), animations: Player::build_animations(tileset), map_width: dimensions.0, map_height: dimensions.1, @@ -83,7 +83,11 @@ impl Player { pub fn update(&mut self) { self.move_position(); - self.animation = self.animations.get(&self.state).cloned(); + self.animation = self + .animations + .get(&self.state) + .cloned() + .unwrap_or_default(); let (source, timer) = next_source(self.source, &self.animation, self.timer); self.source = source; self.timer = timer; -- cgit v1.2.3