Made animated pug
authorJustin Worthe <justin@worthe-it.co.za>
Tue, 12 Jun 2018 20:19:54 +0000 (22:19 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Tue, 12 Jun 2018 20:19:54 +0000 (22:19 +0200)
src/entities/home.rs
src/main.rs
src_assets/sprites/Sleepypug1.png [new file with mode: 0644]
src_assets/sprites/Sleepypug2.png [new file with mode: 0644]
src_assets/sprites/Sleepypug3.png [new file with mode: 0644]
src_assets/sprites/Sleepypug4.png [new file with mode: 0644]

index 6f7f53d..2839f5d 100644 (file)
@@ -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 {
index c98c80e..88f0a2c 100644 (file)
@@ -50,6 +50,7 @@ impl App<AssetId> for BugBasherGame {
                     self.lives -= 1;
                 }
             }
+            self.home.advance(seconds);
             if self.lives <= 0 {
                 self.game_over = true;
             }
@@ -111,7 +112,7 @@ impl App<AssetId> for BugBasherGame {
             let mut renderer = renderer.sprite_mode();
             renderer.draw(
                 &Affine::translate(self.home.pos.x, self.home.pos.y),
-                SpriteId::Home
+                self.home.sprite
             );
             for bug in &self.bugs {
                 renderer.draw(
diff --git a/src_assets/sprites/Sleepypug1.png b/src_assets/sprites/Sleepypug1.png
new file mode 100644 (file)
index 0000000..00d275a
Binary files /dev/null and b/src_assets/sprites/Sleepypug1.png differ
diff --git a/src_assets/sprites/Sleepypug2.png b/src_assets/sprites/Sleepypug2.png
new file mode 100644 (file)
index 0000000..134b494
Binary files /dev/null and b/src_assets/sprites/Sleepypug2.png differ
diff --git a/src_assets/sprites/Sleepypug3.png b/src_assets/sprites/Sleepypug3.png
new file mode 100644 (file)
index 0000000..579e617
Binary files /dev/null and b/src_assets/sprites/Sleepypug3.png differ
diff --git a/src_assets/sprites/Sleepypug4.png b/src_assets/sprites/Sleepypug4.png
new file mode 100644 (file)
index 0000000..6bb2c5d
Binary files /dev/null and b/src_assets/sprites/Sleepypug4.png differ