From 6d8852b83e8498fe220bd67a3f645146518443b3 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Tue, 12 Jun 2018 22:19:54 +0200 Subject: Made animated pug --- src/entities/home.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/entities') diff --git a/src/entities/home.rs b/src/entities/home.rs index 6f7f53d..2839f5d 100644 --- a/src/entities/home.rs +++ b/src/entities/home.rs @@ -1,9 +1,12 @@ use geometry::*; use hitbox::*; +use asset_id::*; -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct Home { - pub pos: Vec2d + pub pos: Vec2d, + pub animation_time: f64, + pub sprite: SpriteId } impl Home { @@ -12,9 +15,29 @@ impl Home { pos: Vec2d { x: x, y: y - } + }, + animation_time: 0., + sprite: SpriteId::Sleepypug1 } } + + pub fn advance(&mut self, seconds: f64) { + let scale = 0.5; + self.animation_time = (self.animation_time + scale * seconds).fract(); + self.sprite = if self.animation_time < 0.3 { + SpriteId::Sleepypug1 + } else if self.animation_time < 0.4 { + SpriteId::Sleepypug2 + } else if self.animation_time < 0.5 { + SpriteId::Sleepypug3 + } else if self.animation_time < 0.8 { + SpriteId::Sleepypug4 + } else if self.animation_time < 0.9 { + SpriteId::Sleepypug3 + } else { + SpriteId::Sleepypug2 + } ; + } } impl CircleHitbox for Home { -- cgit v1.2.3