Mercurial > touhou
comparison 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 |
comparison
equal
deleted
inserted
replaced
686:aefe5b5f481e | 687:ac092b70c39a |
---|---|
256 | 256 |
257 impl Enemy { | 257 impl Enemy { |
258 /// Create a new enemy. | 258 /// Create a new enemy. |
259 pub fn new(pos: Position, life: i32, bonus_dropped: u32, die_score: u32, anm0: Weak<RefCell<Anm0>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> { | 259 pub fn new(pos: Position, life: i32, bonus_dropped: u32, die_score: u32, anm0: Weak<RefCell<Anm0>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> { |
260 let game_rc = game.upgrade().unwrap(); | 260 let game_rc = game.upgrade().unwrap(); |
261 let enemy = Enemy { | 261 let mut enemy = Enemy { |
262 pos, | 262 pos, |
263 anm0, | 263 anm0, |
264 game, | 264 game, |
265 visible: true, | 265 visible: true, |
266 bonus_dropped, | 266 bonus_dropped, |
269 touchable: true, | 269 touchable: true, |
270 collidable: true, | 270 collidable: true, |
271 damageable: true, | 271 damageable: true, |
272 ..Default::default() | 272 ..Default::default() |
273 }; | 273 }; |
274 let mut game = game_rc.borrow_mut(); | |
275 enemy.prng = Rc::downgrade(&game.prng); | |
274 let enemy = Rc::new(RefCell::new(enemy)); | 276 let enemy = Rc::new(RefCell::new(enemy)); |
275 game_rc.borrow_mut().enemies.push(enemy.clone()); | 277 game.enemies.push(enemy.clone()); |
276 enemy | 278 enemy |
277 } | 279 } |
278 | 280 |
279 /// Sets the animation to the one indexed by index in the current anm0. | 281 /// Sets the animation to the one indexed by index in the current anm0. |
280 pub fn set_anim(&mut self, index: u8) { | 282 pub fn set_anim(&mut self, index: u8) { |