From 7d59cd2510ac926edd0790de4bffb0fbb9c60e7c Mon Sep 17 00:00:00 2001 From: tom barrett Date: Fri, 28 Jun 2019 10:05:13 -0500 Subject: animation working --- src/player.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/player.rs') 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, -- cgit v1.2.3