diff src/th06/enemy.rs @ 687:ac092b70c39a

Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 17 Aug 2019 13:49:31 +0200
parents aefe5b5f481e
children 1adecaddf442
line wrap: on
line diff
--- a/src/th06/enemy.rs
+++ b/src/th06/enemy.rs
@@ -258,7 +258,7 @@ impl Enemy {
     /// Create a new enemy.
     pub fn new(pos: Position, life: i32, bonus_dropped: u32, die_score: u32, anm0: Weak<RefCell<Anm0>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> {
         let game_rc = game.upgrade().unwrap();
-        let enemy = Enemy {
+        let mut enemy = Enemy {
             pos,
             anm0,
             game,
@@ -271,8 +271,10 @@ impl Enemy {
             damageable: true,
             ..Default::default()
         };
+        let mut game = game_rc.borrow_mut();
+        enemy.prng = Rc::downgrade(&game.prng);
         let enemy = Rc::new(RefCell::new(enemy));
-        game_rc.borrow_mut().enemies.push(enemy.clone());
+        game.enemies.push(enemy.clone());
         enemy
     }