diff options
author | tom barrett <spalf0@gmail.com> | 2019-06-28 10:05:13 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-06-28 10:05:13 -0500 |
commit | 7d59cd2510ac926edd0790de4bffb0fbb9c60e7c (patch) | |
tree | 5b17c70031f57de3ba0f663018fdc41bad31f953 /src/player.rs | |
parent | 39ea81bea4a61baf8c95a33bcc979b0e65ce660e (diff) |
animation working
Diffstat (limited to 'src/player.rs')
-rw-r--r-- | src/player.rs | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/player.rs b/src/player.rs index 6e2bf06..f7db814 100644 --- a/src/player.rs +++ b/src/player.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::time::Instant; use crate::constants; -use crate::math::next_source; +use crate::math::{flip, next_source}; use crate::tileset::Tileset; pub struct Player { @@ -23,10 +23,36 @@ impl Player { pub fn new(tileset: &Tileset, dimensions: (f32, f32)) -> Player { let mut animations = HashMap::new(); - let mut source = tileset.get_rect_by_entity("player-top"); - source.h += tileset.get_rect_by_entity("player-bottom").h; + let mut source = tileset.get_tile_by_entity_keyframe("player-top", 0); + source.h += tileset.get_tile_by_entity_keyframe("player-bottom", 0).h; animations.insert(PlayerState::Idle, vec![(1, source)]); + let mut moving = tileset.get_tile_by_entity_keyframe("player-top", 1); + moving.h += tileset.get_tile_by_entity_keyframe("player-bottom", 1).h; + + animations.insert(PlayerState::MovingLeft, vec![(100, source), (100, moving)]); + animations.insert( + PlayerState::MovingUpLeft, + vec![(100, source), (100, moving)], + ); + animations.insert( + PlayerState::MovingDownLeft, + vec![(100, source), (100, moving)], + ); + + source = flip(source); + moving = flip(moving); + + animations.insert(PlayerState::MovingRight, vec![(100, source), (100, moving)]); + animations.insert( + PlayerState::MovingUpRight, + vec![(100, source), (100, moving)], + ); + animations.insert( + PlayerState::MovingDownRight, + vec![(100, source), (100, moving)], + ); + Player { position: Point2::new(0.0, 0.0), state: PlayerState::Idle, |