comparison 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
comparison
equal deleted inserted replaced
740:8d29dac12219 741:3555845f8cf4
306 // Interpolators. 306 // Interpolators.
307 pub(crate) interpolator: Option<Interpolator2<f32>>, 307 pub(crate) interpolator: Option<Interpolator2<f32>>,
308 pub(crate) speed_interpolator: Option<Interpolator1<f32>>, 308 pub(crate) speed_interpolator: Option<Interpolator1<f32>>,
309 309
310 // Misc stuff, do we need them? 310 // Misc stuff, do we need them?
311 pub(crate) anm0: Weak<RefCell<Anm0>>, 311 pub(crate) anm0: Weak<RefCell<[Anm0; 2]>>,
312 process: Rc<RefCell<Process>>, 312 process: Rc<RefCell<Process>>,
313 pub(crate) game: Weak<RefCell<Game>>, 313 pub(crate) game: Weak<RefCell<Game>>,
314 pub(crate) prng: Weak<RefCell<Prng>>, 314 pub(crate) prng: Weak<RefCell<Prng>>,
315 pub(crate) hitbox_half_size: [f32; 2], 315 pub(crate) hitbox_half_size: [f32; 2],
316 } 316 }
317 317
318 impl Enemy { 318 impl Enemy {
319 /// Create a new enemy. 319 /// Create a new enemy.
320 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>> { 320 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>> {
321 let game_rc = game.upgrade().unwrap(); 321 let game_rc = game.upgrade().unwrap();
322 let mut enemy = Enemy { 322 let mut enemy = Enemy {
323 pos, 323 pos,
324 anm0, 324 anm0,
325 game, 325 game,
344 /// Sets the animation to the one indexed by index in the current anm0. 344 /// Sets the animation to the one indexed by index in the current anm0.
345 pub fn set_anim(&mut self, index: u8) { 345 pub fn set_anim(&mut self, index: u8) {
346 let anm0 = self.anm0.upgrade().unwrap(); 346 let anm0 = self.anm0.upgrade().unwrap();
347 let game = self.game.upgrade().unwrap(); 347 let game = self.game.upgrade().unwrap();
348 let sprite = Rc::new(RefCell::new(Sprite::new())); 348 let sprite = Rc::new(RefCell::new(Sprite::new()));
349 let anmrunner = AnmRunner::new(&*anm0.borrow(), index, sprite, self.prng.clone(), 0); 349 let anmrunner = AnmRunner::new(anm0, index, sprite, self.prng.clone(), 0);
350 let anmrunner = Rc::new(RefCell::new(anmrunner)); 350 let anmrunner = Rc::new(RefCell::new(anmrunner));
351 self.anmrunner = Rc::downgrade(&anmrunner); 351 self.anmrunner = Rc::downgrade(&anmrunner);
352 (*game.borrow_mut()).anmrunners.push(anmrunner); 352 (*game.borrow_mut()).anmrunners.push(anmrunner);
353 } 353 }
354 354
548 let mut file = io::BufReader::new(file); 548 let mut file = io::BufReader::new(file);
549 let mut buf = vec![]; 549 let mut buf = vec![];
550 file.read_to_end(&mut buf).unwrap(); 550 file.read_to_end(&mut buf).unwrap();
551 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); 551 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
552 let anm0 = anms.pop().unwrap(); 552 let anm0 = anms.pop().unwrap();
553 let anm0 = Rc::new(RefCell::new(anm0)); 553
554 let file = File::open("EoSD/ST/stg1enm2.anm").unwrap();
555 let mut file = io::BufReader::new(file);
556 let mut buf = vec![];
557 file.read_to_end(&mut buf).unwrap();
558 let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
559 let anm0_bis = anms.pop().unwrap();
560
561 let anm0 = Rc::new(RefCell::new([anm0, anm0_bis]));
554 let prng = Rc::new(RefCell::new(Prng::new(0))); 562 let prng = Rc::new(RefCell::new(Prng::new(0)));
555 let game = Game::new(prng, Rank::EASY); 563 let game = Game::new(prng, Rank::EASY);
556 let game = Rc::new(RefCell::new(game)); 564 let game = Rc::new(RefCell::new(game));
557 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); 565 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game));
558 let mut enemy = enemy.borrow_mut(); 566 let mut enemy = enemy.borrow_mut();