diff src/th06/enemy.rs @ 661:598f3125cbac

Implement enough instructions to execute sub 0 from stage 1.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 10 Aug 2019 21:04:54 +0200
parents 31fc0d881105
children 107bb5ca5cc8
line wrap: on
line diff
--- a/src/th06/enemy.rs
+++ b/src/th06/enemy.rs
@@ -91,12 +91,14 @@ impl Game {
     }
 
     /// Returns a list of all sprites currently being displayed on screen.
-    pub fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>> {
+    pub fn get_sprites(&self) -> Vec<(f32, f32, f32, Rc<RefCell<Sprite>>)> {
         let mut sprites = vec![];
-        for anmrunner in self.anmrunners.iter() {
+        for enemy in self.enemies.iter() {
+            let enemy = enemy.borrow();
+            let anmrunner = enemy.anmrunner.upgrade().unwrap();
             let anmrunner = anmrunner.borrow();
             let sprite = anmrunner.get_sprite();
-            sprites.push(sprite);
+            sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite));
         }
         sprites
     }
@@ -139,7 +141,7 @@ pub struct Enemy {
     pub(crate) remaining_lives: u32,
     pub(crate) bullet_launch_interval: u32,
     pub(crate) bullet_launch_timer: u32,
-    pub(crate) death_anim: u32,
+    pub(crate) death_anim: i32,
     pub(crate) direction: u32,
     pub(crate) update_mode: u32,
 
@@ -245,6 +247,18 @@ impl Enemy {
     }
 }
 
+trait Renderable {
+    fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>>;
+}
+
+impl Renderable for Enemy {
+    fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>> {
+        let anmrunner = self.anmrunner.upgrade().unwrap();
+        let anmrunner = anmrunner.borrow();
+        vec![anmrunner.get_sprite()]
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;