diff src/th06/enemy.rs @ 741:3555845f8cf4

Make it so we can use more than a single anm0 in an EclRunner.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 07 Jan 2020 00:06:18 +0100
parents 817c453b7223
children
line wrap: on
line diff
--- a/src/th06/enemy.rs
+++ b/src/th06/enemy.rs
@@ -308,7 +308,7 @@ pub struct Enemy {
     pub(crate) speed_interpolator: Option<Interpolator1<f32>>,
 
     // Misc stuff, do we need them?
-    pub(crate) anm0: Weak<RefCell<Anm0>>,
+    pub(crate) anm0: Weak<RefCell<[Anm0; 2]>>,
     process: Rc<RefCell<Process>>,
     pub(crate) game: Weak<RefCell<Game>>,
     pub(crate) prng: Weak<RefCell<Prng>>,
@@ -317,7 +317,7 @@ pub struct Enemy {
 
 impl Enemy {
     /// Create a new enemy.
-    pub fn new(pos: Position, life: i16, bonus_dropped: i16, die_score: u32, mirror: bool, anm0: Weak<RefCell<Anm0>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> {
+    pub fn new(pos: Position, life: i16, bonus_dropped: i16, die_score: u32, mirror: bool, anm0: Weak<RefCell<[Anm0; 2]>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> {
         let game_rc = game.upgrade().unwrap();
         let mut enemy = Enemy {
             pos,
@@ -346,7 +346,7 @@ impl Enemy {
         let anm0 = self.anm0.upgrade().unwrap();
         let game = self.game.upgrade().unwrap();
         let sprite = Rc::new(RefCell::new(Sprite::new()));
-        let anmrunner = AnmRunner::new(&*anm0.borrow(), index, sprite, self.prng.clone(), 0);
+        let anmrunner = AnmRunner::new(anm0, index, sprite, self.prng.clone(), 0);
         let anmrunner = Rc::new(RefCell::new(anmrunner));
         self.anmrunner = Rc::downgrade(&anmrunner);
         (*game.borrow_mut()).anmrunners.push(anmrunner);
@@ -550,7 +550,15 @@ mod tests {
         file.read_to_end(&mut buf).unwrap();
         let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
         let anm0 = anms.pop().unwrap();
-        let anm0 = Rc::new(RefCell::new(anm0));
+
+        let file = File::open("EoSD/ST/stg1enm2.anm").unwrap();
+        let mut file = io::BufReader::new(file);
+        let mut buf = vec![];
+        file.read_to_end(&mut buf).unwrap();
+        let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
+        let anm0_bis = anms.pop().unwrap();
+
+        let anm0 = Rc::new(RefCell::new([anm0, anm0_bis]));
         let prng = Rc::new(RefCell::new(Prng::new(0)));
         let game = Game::new(prng, Rank::EASY);
         let game = Rc::new(RefCell::new(game));