comparison 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
comparison
equal deleted inserted replaced
660:31fc0d881105 661:598f3125cbac
89 anmrunner.run_frame(); 89 anmrunner.run_frame();
90 } 90 }
91 } 91 }
92 92
93 /// Returns a list of all sprites currently being displayed on screen. 93 /// Returns a list of all sprites currently being displayed on screen.
94 pub fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>> { 94 pub fn get_sprites(&self) -> Vec<(f32, f32, f32, Rc<RefCell<Sprite>>)> {
95 let mut sprites = vec![]; 95 let mut sprites = vec![];
96 for anmrunner in self.anmrunners.iter() { 96 for enemy in self.enemies.iter() {
97 let enemy = enemy.borrow();
98 let anmrunner = enemy.anmrunner.upgrade().unwrap();
97 let anmrunner = anmrunner.borrow(); 99 let anmrunner = anmrunner.borrow();
98 let sprite = anmrunner.get_sprite(); 100 let sprite = anmrunner.get_sprite();
99 sprites.push(sprite); 101 sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite));
100 } 102 }
101 sprites 103 sprites
102 } 104 }
103 } 105 }
104 106
137 pub(crate) low_life_trigger: Option<u32>, 139 pub(crate) low_life_trigger: Option<u32>,
138 pub(crate) timeout: Option<u32>, 140 pub(crate) timeout: Option<u32>,
139 pub(crate) remaining_lives: u32, 141 pub(crate) remaining_lives: u32,
140 pub(crate) bullet_launch_interval: u32, 142 pub(crate) bullet_launch_interval: u32,
141 pub(crate) bullet_launch_timer: u32, 143 pub(crate) bullet_launch_timer: u32,
142 pub(crate) death_anim: u32, 144 pub(crate) death_anim: i32,
143 pub(crate) direction: u32, 145 pub(crate) direction: u32,
144 pub(crate) update_mode: u32, 146 pub(crate) update_mode: u32,
145 147
146 // Bools. 148 // Bools.
147 pub(crate) visible: bool, 149 pub(crate) visible: bool,
243 let game = game.borrow(); 245 let game = game.borrow();
244 game.difficulty 246 game.difficulty
245 } 247 }
246 } 248 }
247 249
250 trait Renderable {
251 fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>>;
252 }
253
254 impl Renderable for Enemy {
255 fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>> {
256 let anmrunner = self.anmrunner.upgrade().unwrap();
257 let anmrunner = anmrunner.borrow();
258 vec![anmrunner.get_sprite()]
259 }
260 }
261
248 #[cfg(test)] 262 #[cfg(test)]
249 mod tests { 263 mod tests {
250 use super::*; 264 use super::*;
251 use std::io::{self, Read}; 265 use std::io::{self, Read};
252 use std::fs::File; 266 use std::fs::File;