summaryrefslogtreecommitdiff
path: root/src/player.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-01 09:14:17 -0500
committertom barrett <spalf0@gmail.com>2019-07-01 09:14:17 -0500
commit0947ce5a918207efeaf2a4f67a1cc410795f057a (patch)
tree30d601261754e236fc064faa9138eec9d1314d7c /src/player.rs
parent4b01b87d8aca041304c927560095af92feb406da (diff)
simpilfied interfaces and added new xml properties
Diffstat (limited to 'src/player.rs')
-rw-r--r--src/player.rs10
1 files changed, 7 insertions, 3 deletions
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<Vec<(usize, Rect)>>,
+ animation: Vec<(usize, Rect)>,
animations: HashMap<PlayerState, Vec<(usize, Rect)>>,
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;