comparison src/th06/enemy.rs @ 738:817c453b7223

stagerunner: Add a binary able to run multiple enemies.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Dec 2019 23:53:09 +0100
parents 0977d479e37d
children 3555845f8cf4
comparison
equal deleted inserted replaced
737:0977d479e37d 738:817c453b7223
278 pub(crate) collidable: bool, 278 pub(crate) collidable: bool,
279 pub(crate) damageable: bool, 279 pub(crate) damageable: bool,
280 pub(crate) boss: bool, 280 pub(crate) boss: bool,
281 pub(crate) automatic_orientation: bool, 281 pub(crate) automatic_orientation: bool,
282 pub(crate) delay_attack: bool, 282 pub(crate) delay_attack: bool,
283 // Actually part of type_ atm.
284 pub(crate) mirror: bool,
283 285
284 // Tuples. 286 // Tuples.
285 pub(crate) difficulty_coeffs: DifficultyCoeffs, 287 pub(crate) difficulty_coeffs: DifficultyCoeffs,
286 pub(crate) bullet_attributes: BulletAttributes, 288 pub(crate) bullet_attributes: BulletAttributes,
287 pub(crate) bullet_offset: Offset, 289 pub(crate) bullet_offset: Offset,
313 pub(crate) hitbox_half_size: [f32; 2], 315 pub(crate) hitbox_half_size: [f32; 2],
314 } 316 }
315 317
316 impl Enemy { 318 impl Enemy {
317 /// Create a new enemy. 319 /// Create a new enemy.
318 pub fn new(pos: Position, life: i32, bonus_dropped: u32, die_score: u32, 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>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> {
319 let game_rc = game.upgrade().unwrap(); 321 let game_rc = game.upgrade().unwrap();
320 let mut enemy = Enemy { 322 let mut enemy = Enemy {
321 pos, 323 pos,
322 anm0, 324 anm0,
323 game, 325 game,
324 visible: true, 326 visible: true,
325 bonus_dropped, 327 // XXX: shouldn’t be u32, since that can be -1.
328 bonus_dropped: bonus_dropped as u32,
326 die_score, 329 die_score,
327 life: if life < 0 { 1 } else { life as u32 }, 330 life: if life < 0 { 1 } else { life as u32 },
328 touchable: true, 331 touchable: true,
329 collidable: true, 332 collidable: true,
330 damageable: true, 333 damageable: true,
334 mirror,
331 ..Default::default() 335 ..Default::default()
332 }; 336 };
333 let mut game = game_rc.borrow_mut(); 337 let mut game = game_rc.borrow_mut();
334 enemy.prng = Rc::downgrade(&game.prng); 338 enemy.prng = Rc::downgrade(&game.prng);
335 let enemy = Rc::new(RefCell::new(enemy)); 339 let enemy = Rc::new(RefCell::new(enemy));
455 speed 459 speed
456 }; 460 };
457 461
458 let dx = self.angle.cos() * speed; 462 let dx = self.angle.cos() * speed;
459 let dy = self.angle.sin() * speed; 463 let dy = self.angle.sin() * speed;
460 if self.type_ & 2 != 0 { 464 if self.mirror {
461 x -= dx; 465 x -= dx;
462 } else { 466 } else {
463 x += dx; 467 x += dx;
464 } 468 }
465 y += dy; 469 y += dy;