comparison src/th06/enemy.rs @ 677:082c39d7d1c3

Use a struct for difficulty coeffs, so that we can impl Default on it.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 15 Aug 2019 21:32:54 +0200
parents 140ee7de6d90
children 8c50a7b19425
comparison
equal deleted inserted replaced
676:826c16e5f909 677:082c39d7d1c3
108 /// Common to all elements in game. 108 /// Common to all elements in game.
109 struct Element { 109 struct Element {
110 pos: Position, 110 pos: Position,
111 removed: bool, 111 removed: bool,
112 anmrunner: AnmRunner, 112 anmrunner: AnmRunner,
113 }
114
115 #[derive(PartialEq)]
116 pub(crate) struct DifficultyCoeffs {
117 pub(crate) speed_a: f32,
118 pub(crate) speed_b: f32,
119 pub(crate) nb_a: u16,
120 pub(crate) nb_b: u16,
121 pub(crate) shots_a: u16,
122 pub(crate) shots_b: u16,
123 }
124
125 impl Default for DifficultyCoeffs {
126 fn default() -> DifficultyCoeffs {
127 DifficultyCoeffs {
128 speed_a: -0.5,
129 speed_b: 0.5,
130 nb_a: 0,
131 nb_b: 0,
132 shots_a: 0,
133 shots_b: 0,
134 }
135 }
113 } 136 }
114 137
115 #[derive(PartialEq)] 138 #[derive(PartialEq)]
116 pub(crate) enum Direction { 139 pub(crate) enum Direction {
117 Left, 140 Left,
168 pub(crate) boss: bool, 191 pub(crate) boss: bool,
169 pub(crate) automatic_orientation: bool, 192 pub(crate) automatic_orientation: bool,
170 pub(crate) delay_attack: bool, 193 pub(crate) delay_attack: bool,
171 194
172 // Tuples. 195 // Tuples.
173 pub(crate) difficulty_coeffs: (f32, f32, u32, u32, u32, u32), 196 pub(crate) difficulty_coeffs: DifficultyCoeffs,
174 pub(crate) extended_bullet_attributes: Option<(u32, u32, u32, u32, f32, f32, f32, f32)>, 197 pub(crate) extended_bullet_attributes: Option<(u32, u32, u32, u32, f32, f32, f32, f32)>,
175 pub(crate) bullet_attributes: Option<(i16, i16, u32, u32, u32, f32, f32, f32, f32, u32)>, 198 pub(crate) bullet_attributes: Option<(i16, i16, u32, u32, u32, f32, f32, f32, f32, u32)>,
176 pub(crate) bullet_launch_offset: Offset, 199 pub(crate) bullet_launch_offset: Offset,
177 pub(crate) movement_dependant_sprites: Option<(u8, u8, u8, u8)>, 200 pub(crate) movement_dependant_sprites: Option<(u8, u8, u8, u8)>,
178 pub(crate) screen_box: Option<(f32, f32, f32, f32)>, 201 pub(crate) screen_box: Option<(f32, f32, f32, f32)>,
215 die_score, 238 die_score,
216 life: if life < 0 { 1 } else { life as u32 }, 239 life: if life < 0 { 1 } else { life as u32 },
217 touchable: true, 240 touchable: true,
218 collidable: true, 241 collidable: true,
219 damageable: true, 242 damageable: true,
220 difficulty_coeffs: (-0.5, 0.5, 0, 0, 0, 0),
221 ..Default::default() 243 ..Default::default()
222 }; 244 };
223 let enemy = Rc::new(RefCell::new(enemy)); 245 let enemy = Rc::new(RefCell::new(enemy));
224 game_rc.borrow_mut().enemies.push(enemy.clone()); 246 game_rc.borrow_mut().enemies.push(enemy.clone());
225 enemy 247 enemy