Mercurial > touhou
comparison src/th06/enemy.rs @ 666:838d9402b12f
Implement ECL instruction 98, for directional sprites.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 12 Aug 2019 00:22:25 +0200 |
parents | 965ecdbf0316 |
children | 904849807fd8 |
comparison
equal
deleted
inserted
replaced
665:965ecdbf0316 | 666:838d9402b12f |
---|---|
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) enum Direction { | |
117 Left, | |
118 Center, | |
119 Right, | |
120 } | |
121 | |
122 impl Default for Direction { | |
123 fn default() -> Direction { | |
124 Direction::Center | |
125 } | |
113 } | 126 } |
114 | 127 |
115 /// The enemy struct, containing everything pertaining to an enemy. | 128 /// The enemy struct, containing everything pertaining to an enemy. |
116 #[derive(Default)] | 129 #[derive(Default)] |
117 pub struct Enemy { | 130 pub struct Enemy { |
141 pub(crate) timeout: Option<u32>, | 154 pub(crate) timeout: Option<u32>, |
142 pub(crate) remaining_lives: u32, | 155 pub(crate) remaining_lives: u32, |
143 pub(crate) bullet_launch_interval: u32, | 156 pub(crate) bullet_launch_interval: u32, |
144 pub(crate) bullet_launch_timer: u32, | 157 pub(crate) bullet_launch_timer: u32, |
145 pub(crate) death_anim: i32, | 158 pub(crate) death_anim: i32, |
146 pub(crate) direction: u32, | 159 pub(crate) direction: Direction, |
147 pub(crate) update_mode: u32, | 160 pub(crate) update_mode: u32, |
148 | 161 |
149 // Bools. | 162 // Bools. |
150 pub(crate) visible: bool, | 163 pub(crate) visible: bool, |
151 pub(crate) was_visible: bool, | 164 pub(crate) was_visible: bool, |
159 // Tuples. | 172 // Tuples. |
160 pub(crate) difficulty_coeffs: (f32, f32, u32, u32, u32, u32), | 173 pub(crate) difficulty_coeffs: (f32, f32, u32, u32, u32, u32), |
161 pub(crate) extended_bullet_attributes: Option<(u32, u32, u32, u32, f32, f32, f32, f32)>, | 174 pub(crate) extended_bullet_attributes: Option<(u32, u32, u32, u32, f32, f32, f32, f32)>, |
162 pub(crate) bullet_attributes: Option<(i16, i16, u32, u32, u32, f32, f32, f32, f32, u32)>, | 175 pub(crate) bullet_attributes: Option<(i16, i16, u32, u32, u32, f32, f32, f32, f32, u32)>, |
163 pub(crate) bullet_launch_offset: Offset, | 176 pub(crate) bullet_launch_offset: Offset, |
164 pub(crate) movement_dependant_sprites: Option<(f32, f32, f32, f32)>, | 177 pub(crate) movement_dependant_sprites: Option<(u8, u8, u8, u8)>, |
165 pub(crate) screen_box: Option<(f32, f32, f32, f32)>, | 178 pub(crate) screen_box: Option<(f32, f32, f32, f32)>, |
166 | 179 |
167 // Callbacks. | 180 // Callbacks. |
168 death_callback: Option<Callback>, | 181 death_callback: Option<Callback>, |
169 boss_callback: Option<Callback>, | 182 boss_callback: Option<Callback>, |
256 } else { | 269 } else { |
257 x += dx; | 270 x += dx; |
258 } | 271 } |
259 y += dy; | 272 y += dy; |
260 | 273 |
274 if let Some((end_left, end_right, left, right)) = self.movement_dependant_sprites { | |
275 if x < self.pos.x && self.direction != Direction::Left { | |
276 self.set_anim(left); | |
277 self.direction = Direction::Left; | |
278 } else if x > self.pos.x && self.direction != Direction::Right { | |
279 self.set_anim(right); | |
280 self.direction = Direction::Right; | |
281 } else if x == self.pos.x && self.direction != Direction::Center { | |
282 let anim = if self.direction == Direction::Left { | |
283 end_left | |
284 } else { | |
285 end_right | |
286 }; | |
287 self.set_anim(anim); | |
288 self.direction = Direction::Center; | |
289 } | |
290 } | |
291 | |
261 self.pos = Position { x, y }; | 292 self.pos = Position { x, y }; |
262 | 293 |
263 self.frame += 1; | 294 self.frame += 1; |
264 } | 295 } |
265 | 296 |