407f09135382ce3b227588bd8e14475b789b5b94
[hackover2013-badge-firmware.git] / badge / jumpnrun / enemies.c
1 #include "enemies.h"
2
3 #include "collision.h"
4 #include "tiles.h"
5 #include "jumpnrun.h"
6
7 static badge_sprite const anim_cat[] = {
8 { 8, 5, (uint8_t const *) "\xc7\x3f\xce\x38\x11" },
9 { 8, 5, (uint8_t const *) "\xd7\x7d\xc6\x19\x25" }
10 };
11
12 static badge_sprite const anim_mushroom[] = {
13 { 7, 7, (uint8_t const *) "\x10\x0c\x9f\xcf\xc7\x40" },
14 { 7, 7, (uint8_t const *) "\x20\x18\x1e\x8f\x87\x81" },
15 { 7, 7, (uint8_t const *) "\x10\x0c\x9f\xcf\xc7\x40" },
16 { 7, 7, (uint8_t const *) "\x08\x86\xdf\xef\x67\x20" },
17 { 7, 7, (uint8_t const *) "\x04\xc3\xef\xf7\x33\x10" },
18 { 7, 7, (uint8_t const *) "\x04\xc3\xe7\xf3\x31\x10" }
19 };
20
21 static badge_sprite const anim_bunny[] = {
22 { 7, 5, (uint8_t const *) "\x60\x30\xbe\x31\x02" },
23 { 7, 5, (uint8_t const *) "\x42\x30\xbe\x31\x01" },
24 { 7, 5, (uint8_t const *) "\x42\x30\xae\x35\x01" },
25 { 7, 5, (uint8_t const *) "\x60\x30\xae\x35\x02" },
26 { 7, 5, (uint8_t const *) "\x60\x30\xbe\x31\x01" }
27 };
28
29 static badge_sprite const anim_snake[] = {
30 { 10, 6, (uint8_t const *) "\x10\x86\x83\x30\x04\x83\xa2\x07" },
31 { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x0c\xc1\xa2\x07" },
32 { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x82\xe0\x07" },
33 { 10, 6, (uint8_t const *) "\x10\x86\x83\x20\x08\x86\xe1\x07" }
34 };
35
36 static badge_sprite const anim_spiral[] = {
37 { 10, 10, (uint8_t const *) "\xff\x07\xd8\x6f\xa1\xb5\xf6\x1a\xe8\xbf\x00\xfe\x0f" },
38 { 10, 10, (uint8_t const *) "\xff\x07\xd8\x6f\xa1\xb5\xd6\xda\x69\xb0\x7f\x02\x0c" },
39 { 10, 10, (uint8_t const *) "\xff\x07\xd8\x6f\xa1\xb5\xd6\x5a\x6a\xaf\x81\xfe\x0b" },
40 { 10, 10, (uint8_t const *) "\xff\x07\xd8\x4f\x61\x35\xd5\x55\x54\x5f\x01\xfd\x07" },
41 { 10, 10, (uint8_t const *) "\xff\x07\xd0\x7f\x81\xf5\xd6\x5a\x68\xbf\x01\xfe\x0f" },
42 { 10, 10, (uint8_t const *) "\x03\xe4\xdf\x60\xb9\xb5\xd6\x5a\x68\xbf\x01\xfe\x0f" },
43 { 10, 10, (uint8_t const *) "\xfd\x17\x58\x6f\xa5\xb5\xd6\x5a\x68\xbf\x01\xfe\x0f" },
44 { 10, 10, (uint8_t const *) "\xfe\x0b\xa8\xaf\xa2\xba\xca\x6a\x28\xbf\x01\xfe\x0f" }
45 };
46
47 static badge_sprite const anim_rotor[] = {
48 { 9, 9, (uint8_t const *) "\x00\x00\x00\x00\xf0\xe1\x42\x0c\x18\x70\x00" },
49 { 9, 9, (uint8_t const *) "\x1c\x30\x60\x80\xf0\xe1\x40\x00\x00\x00\x00" },
50 { 9, 9, (uint8_t const *) "\x1c\x30\x60\x84\x0e\x1f\x00\x00\x00\x00\x00" },
51 { 9, 9, (uint8_t const *) "\x00\x00\x00\x04\x0e\x1f\x02\x0c\x18\x70\x00" }
52 };
53
54 static badge_sprite const anim_dog[] = {
55 { 8, 5, (uint8_t const *) "\xc1\xf8\xc6\xb8\x08" },
56 { 8, 5, (uint8_t const *) "\xc1\xba\xce\x99\x0c" },
57 { 8, 5, (uint8_t const *) "\xc1\xf8\xc6\xb8\x10" },
58 { 8, 5, (uint8_t const *) "\xc1\xf8\xc6\xb8\x20" }
59 };
60
61 static badge_sprite const anim_giraffe[] = {
62 { 8, 10, (uint8_t const *) "\x00\x10\x60\x80\xff\xc1\x00\x03\x3c\x08" },
63 { 8, 10, (uint8_t const *) "\x00\x10\x60\xa0\x7f\xc1\x00\x03\x1c\x88" },
64 { 9, 10, (uint8_t const *) "\x00\x10\x68\x90\x3f\xc1\x00\x03\x0c\x48\x00\x02" },
65 { 8, 10, (uint8_t const *) "\x00\x10\x60\xb0\x3f\xc1\x00\x03\x0c\xc8" },
66 { 8, 10, (uint8_t const *) "\x08\x30\xc0\x81\xfc\xc0\x00\x03\x3c\x08" },
67 { 8, 10, (uint8_t const *) "\x00\x10\x60\x80\xff\xc1\x00\x03\x3c\x08" }
68 };
69
70 static badge_sprite const anim_bird[] = {
71 { 9, 7, (uint8_t const *) "\x10\x0c\x05\xf7\x4a\xa9\x58\x10" },
72 { 9, 7, (uint8_t const *) "\x10\x0c\x05\x87\x47\xa2\x70\x10" }
73 /*
74 { 10, 8, (uint8_t const *) "\x10\x10\x18\x14\x38\x2e\x29\x29\x2e\x10" },
75 { 10, 8, (uint8_t const *) "\x10\x10\x18\x14\x38\x78\xa8\xa8\x78\x10" }
76 */
77 };
78
79 static void enemy_animation_advance(jumpnrun_enemy *enemy) {
80 ++enemy->base.tick_minor;
81 if(enemy->base.tick_minor == enemy->type->animation_ticks_per_frame) {
82 enemy->base.tick_minor = 0;
83
84 ++enemy->base.anim_frame;
85 if(enemy->base.anim_frame >= enemy->type->animation_length) {
86 enemy->base.anim_frame = 0;
87 }
88 }
89 }
90
91 void jumpnrun_process_enemy(jumpnrun_enemy *self,
92 badge_framebuffer *fb,
93 struct jumpnrun_game_state *state,
94 struct jumpnrun_level *lv,
95 struct jumpnrun_tile_range const *visible_tiles,
96 vec2d *player_inertia_mod) {
97 int const spawn_margin = 1 + self->type->animation_frames[self->base.anim_frame].width;
98
99 if(self->flags & JUMPNRUN_ENEMY_SPAWNED) {
100 if(fixed_point_lt(rectangle_left(enemy_box(self)), FIXED_POINT(state->left - spawn_margin, 0)) ||
101 fixed_point_gt(rectangle_left(enemy_box(self)), FIXED_POINT(state->left + BADGE_DISPLAY_WIDTH + spawn_margin, 0)) ||
102 fixed_point_gt(rectangle_top (enemy_box(self)), FIXED_POINT(BADGE_DISPLAY_HEIGHT , 0))) {
103 self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
104 } else {
105 self->type->move_tick(self, state, lv, visible_tiles, player_inertia_mod);
106 self->type->collision_shots(self, state);
107
108 if(fb) {
109 badge_framebuffer_blt(fb,
110 fixed_point_cast_int(rectangle_left(enemy_box(self))) - state->left,
111 fixed_point_cast_int(rectangle_top (enemy_box(self))),
112 enemy_sprite(self),
113 enemy_render_flags(self));
114 }
115 }
116 } else if(self->flags & JUMPNRUN_ENEMY_UNAVAILABLE) {
117 if(state->left > fixed_point_cast_int(self->spawn_pos.x) + spawn_margin ||
118 state->left + BADGE_DISPLAY_WIDTH + spawn_margin < fixed_point_cast_int(self->spawn_pos.x)) {
119 self->flags &= ~JUMPNRUN_ENEMY_UNAVAILABLE;
120 }
121 } else if((fixed_point_gt(self->spawn_pos.x, FIXED_POINT(state->left - spawn_margin, 0)) &&
122 fixed_point_lt(self->spawn_pos.x, FIXED_POINT(state->left - spawn_margin / 2, 0))) ||
123 (fixed_point_lt(self->spawn_pos.x, FIXED_POINT(state->left + BADGE_DISPLAY_WIDTH + spawn_margin, 0)) &&
124 fixed_point_gt(self->spawn_pos.x, FIXED_POINT(state->left + BADGE_DISPLAY_WIDTH, 0)))) {
125 // enemy unspawned, available and in spawn zone.
126 self->flags = JUMPNRUN_ENEMY_SPAWNED | JUMPNRUN_ENEMY_UNAVAILABLE;
127 self->base.current_box = rectangle_new(self->spawn_pos, self->type->extent);
128 self->base.inertia = self->type->spawn_inertia;
129 self->base.anim_frame = 0;
130 self->base.tick_minor = 0;
131 self->base.touching_ground = false;
132 self->base.jumpable_frames = 0;
133 }
134 }
135
136 void enemy_collision_tiles_bounce_horiz(jumpnrun_enemy *self,
137 vec2d *desired_position,
138 jumpnrun_level *lv,
139 jumpnrun_tile_range const *visible_tiles) {
140 vec2d inertia_mod = self->base.inertia;
141
142 collisions_tiles_displace(desired_position,
143 &self->base,
144 lv,
145 visible_tiles,
146 &inertia_mod);
147
148 if(fixed_point_ne(inertia_mod.x, self->base.inertia.x)) {
149 self->base.inertia.x = fixed_point_neg(self->base.inertia.x);
150 }
151 }
152
153 void enemy_collision_player_deadly(struct jumpnrun_enemy *self,
154 struct jumpnrun_game_state *state,
155 vec2d *player_inertia_mod) {
156 (void) player_inertia_mod;
157
158 rectangle rect_self = enemy_hitbox(self);
159
160 if(rectangle_intersect(&rect_self, &state->player.current_box)) {
161 state->status = JUMPNRUN_DEAD;
162 }
163 }
164
165 void enemy_collision_player_jumpable(jumpnrun_enemy *self,
166 jumpnrun_game_state *state,
167 vec2d *player_inertia_mod)
168 {
169 rectangle rect_self = enemy_hitbox(self);
170
171 if(rectangle_intersect(&rect_self, &state->player.current_box)) {
172 if(fixed_point_lt(rectangle_top(&state->player.current_box), rectangle_top(&rect_self)) &&
173 fixed_point_gt(state->player.inertia.y, FIXED_POINT(0, 0)))
174 {
175 self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
176 player_inertia_mod->y = FIXED_POINT(0, -250);
177 state->player.jumpable_frames = 12;
178 } else {
179 state->status = JUMPNRUN_DEAD;
180 }
181 }
182 }
183
184 void enemy_collision_tiles_pass_through(struct jumpnrun_enemy *self,
185 vec2d *desired_position,
186 struct jumpnrun_level *lv,
187 struct jumpnrun_tile_range const *visible_tiles) {
188 (void) self;
189 (void) desired_position;
190 (void) lv;
191 (void) visible_tiles;
192 return;
193 }
194
195 void enemy_collision_shots_die(struct jumpnrun_enemy *self,
196 struct jumpnrun_game_state *state) {
197 rectangle rect_self = enemy_hitbox(self);
198
199 for(uint8_t i = 0; i < JUMPNRUN_MAX_SHOTS; ++i) {
200 jumpnrun_shot *shot = &state->shots[i];
201
202 if(jumpnrun_shot_spawned(shot)) {
203 if(rectangle_intersect(&rect_self, &shot->current_box)) {
204 self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
205 jumpnrun_shot_despawn(shot);
206 }
207 }
208 }
209 }
210
211 void enemy_collision_shots_bounce(struct jumpnrun_enemy *self,
212 struct jumpnrun_game_state *state) {
213 rectangle rect_self = enemy_hitbox(self);
214
215 for(uint8_t i = 0; i < JUMPNRUN_MAX_SHOTS; ++i) {
216 jumpnrun_shot *shot = &state->shots[i];
217
218 if(jumpnrun_shot_spawned(shot)) {
219 if(rectangle_intersect(&rect_self, &shot->current_box)) {
220 if(fixed_point_gt(shot->inertia.x, FIXED_INT(0))) {
221 rectangle_move_to_x(&shot->current_box, fixed_point_sub(rectangle_left(&rect_self), rectangle_width(&shot->current_box)));
222 } else {
223 rectangle_move_to_x(&shot->current_box, rectangle_right(&rect_self));
224 }
225
226 shot->inertia.x = fixed_point_neg(shot->inertia.x);
227 }
228 }
229 }
230 }
231
232 void enemy_collision_shots_dontcare(struct jumpnrun_enemy *self,
233 struct jumpnrun_game_state *state) {
234 (void) self;
235 (void) state;
236 }
237
238 void enemy_tick_straight_ahead(jumpnrun_enemy *self,
239 jumpnrun_game_state *state,
240 jumpnrun_level *lv,
241 jumpnrun_tile_range const *visible_tiles,
242 vec2d *player_inertia_mod) {
243 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
244
245 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
246 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
247 return;
248 }
249
250 jumpnrun_passive_movement(&self->base.inertia);
251
252 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
253 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
254 self->type->collision_player(self, state, player_inertia_mod);
255 rectangle_move_to(&self->base.current_box, new_pos);
256
257 enemy_animation_advance(self);
258 }
259
260 void enemy_tick_swing_up_and_down(struct jumpnrun_enemy *self,
261 struct jumpnrun_game_state *state,
262 struct jumpnrun_level *lv,
263 struct jumpnrun_tile_range const *visible_tiles,
264 vec2d *player_inertia_mod) {
265 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
266
267 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
268 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
269 return;
270 }
271
272 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
273 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
274 self->type->collision_player(self, state, player_inertia_mod);
275 rectangle_move_to(&self->base.current_box, new_pos);
276
277 self->base.inertia.y =
278 fixed_point_add(fixed_point_add(self->base.inertia.y,
279 fixed_point_div(self->type->spawn_inertia.y, FIXED_INT(3))),
280 fixed_point_mul(FIXED_POINT(0, 5),
281 fixed_point_sub(self->spawn_pos.y,
282 enemy_position(self).y)));
283
284 enemy_animation_advance(self);
285 }
286
287 void enemy_tick_stationary(struct jumpnrun_enemy *self,
288 struct jumpnrun_game_state *state,
289 struct jumpnrun_level *lv,
290 struct jumpnrun_tile_range const *visible_tiles,
291 vec2d *player_inertia_mod) {
292 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
293
294 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
295 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
296 return;
297 }
298
299 self->type->collision_tiles(self, &self->base.current_box.pos, lv, visible_tiles);
300 self->type->collision_player(self, state, player_inertia_mod);
301
302 enemy_animation_advance(self);
303 }
304
305 void enemy_tick_jumper(jumpnrun_enemy *self,
306 jumpnrun_game_state *state,
307 jumpnrun_level *lv,
308 jumpnrun_tile_range const *visible_tiles,
309 vec2d *player_inertia_mod) {
310 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
311
312 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
313 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
314 return;
315 }
316
317 jumpnrun_passive_movement(&self->base.inertia);
318
319 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
320 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
321 self->type->collision_player(self, state, player_inertia_mod);
322 rectangle_move_to(&self->base.current_box, new_pos);
323
324 if(self->base.touching_ground) {
325 self->base.inertia.y = self->type->spawn_inertia.y;
326 }
327
328 enemy_animation_advance(self);
329 }
330
331 void enemy_tick_dog(jumpnrun_enemy *self,
332 jumpnrun_game_state *state,
333 jumpnrun_level *lv,
334 jumpnrun_tile_range const *visible_tiles,
335 vec2d *player_inertia_mod) {
336 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
337
338 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
339 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
340 return;
341 }
342
343 jumpnrun_passive_movement(&self->base.inertia);
344
345 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
346 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
347 self->type->collision_player(self, state, player_inertia_mod);
348 rectangle_move_to(&self->base.current_box, new_pos);
349
350 if(self->base.tick_minor % self->type->animation_ticks_per_frame == 0) {
351 switch(self->base.tick_minor / self->type->animation_ticks_per_frame) {
352 case 12:
353 self->base.tick_minor = 0;
354 case 0:
355 case 2:
356 case 4:
357 case 6:
358 self->base.anim_frame = 0;
359 if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
360 self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
361 } else {
362 self->base.inertia.x = self->type->spawn_inertia.x;
363 }
364
365 break;
366
367 case 1:
368 case 3:
369 case 5:
370 case 7:
371 self->base.anim_frame = 1;
372 if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
373 self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
374 } else {
375 self->base.inertia.x = self->type->spawn_inertia.x;
376 }
377 break;
378
379 case 8:
380 case 10:
381 self->base.anim_frame = 2;
382 self->base.inertia.x = FIXED_INT(0);
383 break;
384
385 case 9:
386 case 11:
387 self->base.anim_frame = 3;
388 self->base.inertia.x = FIXED_INT(0);
389 break;
390 }
391 }
392
393 ++self->base.tick_minor;
394 if (fixed_point_lt(self->base.inertia.x, FIXED_INT(0))) { self->flags &= ~JUMPNRUN_ENEMY_FACING_RIGHT; }
395 else if(fixed_point_ne(self->base.inertia.x, FIXED_INT(0))) { self->flags |= JUMPNRUN_ENEMY_FACING_RIGHT; }
396 }
397
398 void enemy_tick_giraffe(jumpnrun_enemy *self,
399 jumpnrun_game_state *state,
400 jumpnrun_level *lv,
401 jumpnrun_tile_range const *visible_tiles,
402 vec2d *player_inertia_mod) {
403 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
404
405 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
406 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
407 return;
408 }
409
410 bool was_on_ground = self->base.touching_ground;
411
412 jumpnrun_passive_movement(&self->base.inertia);
413
414 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
415 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
416 self->type->collision_player(self, state, player_inertia_mod);
417 rectangle_move_to(&self->base.current_box, new_pos);
418
419 if(self->base.touching_ground) {
420 if(was_on_ground) {
421 enemy_animation_advance(self);
422 if(self->base.anim_frame == 0) {
423 if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
424 self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
425 self->base.inertia.y = self->type->spawn_inertia.y;
426 } else {
427 self->base.inertia = self->type->spawn_inertia;
428 }
429 }
430 } else {
431 self->base.tick_minor = 0;
432 self->base.anim_frame = 3;
433 self->base.inertia.x = FIXED_INT(0);
434 }
435 } else if(was_on_ground) {
436 self->base.tick_minor = 0;
437 self->base.anim_frame = 1;
438 } else if(self->base.anim_frame == 1) {
439 enemy_animation_advance(self);
440 }
441
442 ++self->base.tick_minor;
443 if (fixed_point_lt(self->base.inertia.x, FIXED_INT(0))) { self->flags &= ~JUMPNRUN_ENEMY_FACING_RIGHT; }
444 else if(fixed_point_ne(self->base.inertia.x, FIXED_INT(0))) { self->flags |= JUMPNRUN_ENEMY_FACING_RIGHT; }
445 }
446
447 void enemy_tick_fly_straight(struct jumpnrun_enemy *self,
448 struct jumpnrun_game_state *state,
449 struct jumpnrun_level *lv,
450 struct jumpnrun_tile_range const *visible_tiles,
451 vec2d *player_inertia_mod) {
452 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
453
454 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
455 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
456 return;
457 }
458
459 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
460 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
461 self->type->collision_player(self, state, player_inertia_mod);
462 rectangle_move_to(&self->base.current_box, new_pos);
463
464 enemy_animation_advance(self);
465 }
466
467 void enemy_tick_fly_straight_and_dip(struct jumpnrun_enemy *self,
468 struct jumpnrun_game_state *state,
469 struct jumpnrun_level *lv,
470 struct jumpnrun_tile_range const *visible_tiles,
471 vec2d *player_inertia_mod) {
472 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
473
474 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
475 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
476 return;
477 }
478
479 if(fixed_point_lt(fixed_point_abs(fixed_point_sub(enemy_position(self).x,
480 state->player.current_box.pos.x)),
481 FIXED_INT(20))) {
482 self->flags |= JUMPNRUN_ENEMY_EVENT_TRIGGER1;
483 }
484
485 if(self->flags & JUMPNRUN_ENEMY_EVENT_TRIGGER1) {
486 self->base.inertia.y =
487 fixed_point_add(fixed_point_add(self->base.inertia.y,
488 fixed_point_div(self->type->spawn_inertia.y, FIXED_INT(3))),
489 fixed_point_mul(FIXED_POINT(0, 5),
490 fixed_point_sub(self->spawn_pos.y,
491 enemy_position(self).y)));
492 } else {
493 self->base.inertia.y = FIXED_INT(0);
494 }
495
496 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);;
497 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
498 self->type->collision_player(self, state, player_inertia_mod);
499 rectangle_move_to(&self->base.current_box, new_pos);
500
501 enemy_animation_advance(self);
502 }
503
504 jumpnrun_enemy_type const jumpnrun_enemy_type_data[JUMPNRUN_ENEMY_TYPE_COUNT] = {
505 {
506 .animation_ticks_per_frame = 18,
507 .animation_length = ARRAY_SIZE(anim_cat),
508 .animation_frames = anim_cat,
509 .extent = { FIXED_INT_I(8), FIXED_INT_I(5) },
510 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(2) },
511 { FIXED_INT_I(6), FIXED_INT_I(3) } },
512 .spawn_inertia = { FIXED_POINT_I(0, -200), FIXED_INT_I(0) },
513 .collision_tiles = enemy_collision_tiles_bounce_horiz,
514 .collision_player = enemy_collision_player_jumpable,
515 .collision_shots = enemy_collision_shots_die,
516 .move_tick = enemy_tick_straight_ahead
517 }, {
518 .animation_ticks_per_frame = 12,
519 .animation_length = ARRAY_SIZE(anim_mushroom),
520 .animation_frames = anim_mushroom,
521 .extent = { FIXED_INT_I(7), FIXED_INT_I(7) },
522 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
523 { FIXED_INT_I(5), FIXED_INT_I(4) } },
524 .spawn_inertia = { FIXED_POINT_I(0, -50), FIXED_INT_I(0) },
525 .collision_tiles = enemy_collision_tiles_bounce_horiz,
526 .collision_player = enemy_collision_player_jumpable,
527 .collision_shots = enemy_collision_shots_die,
528 .move_tick = enemy_tick_straight_ahead
529 }, {
530 .animation_ticks_per_frame = 9,
531 .animation_length = ARRAY_SIZE(anim_bunny),
532 .animation_frames = anim_bunny,
533 .extent = { FIXED_INT_I(7), FIXED_INT_I(5) },
534 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(2) },
535 { FIXED_INT_I(5), FIXED_INT_I(3) } },
536 .spawn_inertia = { FIXED_POINT_I(0, -80), FIXED_POINT_I(0, -800) },
537 .collision_tiles = enemy_collision_tiles_bounce_horiz,
538 .collision_player = enemy_collision_player_jumpable,
539 .collision_shots = enemy_collision_shots_die,
540 .move_tick = enemy_tick_jumper
541 }, {
542 .animation_ticks_per_frame = 6,
543 .animation_length = ARRAY_SIZE(anim_snake),
544 .animation_frames = anim_snake,
545 .extent = { FIXED_INT_I(10), FIXED_INT_I(6) },
546 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(4) },
547 { FIXED_INT_I(8), FIXED_INT_I(2) } },
548 .spawn_inertia = { FIXED_POINT_I(0, -150), FIXED_INT_I(0) },
549 .collision_tiles = enemy_collision_tiles_bounce_horiz,
550 .collision_player = enemy_collision_player_jumpable,
551 .collision_shots = enemy_collision_shots_die,
552 .move_tick = enemy_tick_straight_ahead
553 }, {
554 .animation_ticks_per_frame = 6,
555 .animation_length = ARRAY_SIZE(anim_spiral),
556 .animation_frames = anim_spiral,
557 .extent = { FIXED_INT_I(10), FIXED_INT_I(10) },
558 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
559 { FIXED_INT_I(8), FIXED_INT_I(8) } },
560 .spawn_inertia = { FIXED_INT_I(0), FIXED_POINT_I(0, -200) },
561 .collision_tiles = enemy_collision_tiles_pass_through,
562 .collision_player = enemy_collision_player_deadly,
563 .collision_shots = enemy_collision_shots_dontcare,
564 .move_tick = enemy_tick_swing_up_and_down
565 }, {
566 .animation_ticks_per_frame = 5,
567 .animation_length = ARRAY_SIZE(anim_rotor),
568 .animation_frames = anim_rotor,
569 .extent = { FIXED_INT_I(9), FIXED_INT_I(9) },
570 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
571 { FIXED_INT_I(7), FIXED_INT_I(7) } },
572 .spawn_inertia = { FIXED_INT_I(0), FIXED_POINT_I(0, 0) },
573 .collision_tiles = enemy_collision_tiles_pass_through,
574 .collision_player = enemy_collision_player_deadly,
575 .collision_shots = enemy_collision_shots_dontcare,
576 .move_tick = enemy_tick_stationary
577 }, {
578 .animation_ticks_per_frame = 18,
579 .animation_length = ARRAY_SIZE(anim_dog),
580 .animation_frames = anim_dog,
581 .extent = { FIXED_INT_I(8), FIXED_INT_I(5) },
582 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
583 { FIXED_INT_I(6), FIXED_INT_I(4) } },
584 .spawn_inertia = { FIXED_POINT_I(0, -200), FIXED_POINT_I(0, 0) },
585 .collision_tiles = enemy_collision_tiles_bounce_horiz,
586 .collision_player = enemy_collision_player_jumpable,
587 .collision_shots = enemy_collision_shots_die,
588 .move_tick = enemy_tick_dog
589 }, {
590 .animation_ticks_per_frame = 36,
591 .animation_length = ARRAY_SIZE(anim_giraffe),
592 .animation_frames = anim_giraffe,
593 .extent = { FIXED_INT_I(7), FIXED_INT_I(10) },
594 .hitbox = { { FIXED_INT_I(2), FIXED_INT_I(1) },
595 { FIXED_INT_I(4), FIXED_INT_I(9) } },
596 .spawn_inertia = { FIXED_POINT_I(0, -150), FIXED_POINT_I(-1, -200) },
597 .collision_tiles = enemy_collision_tiles_bounce_horiz,
598 .collision_player = enemy_collision_player_jumpable,
599 .collision_shots = enemy_collision_shots_bounce,
600 .move_tick = enemy_tick_giraffe
601 }, {
602 .animation_ticks_per_frame = 24,
603 .animation_length = ARRAY_SIZE(anim_bird),
604 .animation_frames = anim_bird,
605 .extent = { FIXED_INT_I(9), FIXED_INT_I(7) },
606 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(3) },
607 { FIXED_INT_I(7), FIXED_INT_I(3) } },
608 .spawn_inertia = { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, -150) },
609 .collision_tiles = enemy_collision_tiles_bounce_horiz,
610 .collision_player = enemy_collision_player_jumpable,
611 .collision_shots = enemy_collision_shots_die,
612 .move_tick = enemy_tick_swing_up_and_down
613 }, {
614 .animation_ticks_per_frame = 24,
615 .animation_length = ARRAY_SIZE(anim_bird),
616 .animation_frames = anim_bird,
617 .extent = { FIXED_INT_I(9), FIXED_INT_I(7) },
618 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(3) },
619 { FIXED_INT_I(7), FIXED_INT_I(3) } },
620 .spawn_inertia = { FIXED_POINT_I(0, -400), FIXED_INT_I(0) },
621 .collision_tiles = enemy_collision_tiles_bounce_horiz,
622 .collision_player = enemy_collision_player_jumpable,
623 .collision_shots = enemy_collision_shots_die,
624 .move_tick = enemy_tick_fly_straight
625 }, {
626 .animation_ticks_per_frame = 24,
627 .animation_length = ARRAY_SIZE(anim_bird),
628 .animation_frames = anim_bird,
629 .extent = { FIXED_INT_I(9), FIXED_INT_I(7) },
630 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(3) },
631 { FIXED_INT_I(7), FIXED_INT_I(3) } },
632 .spawn_inertia = { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, 200) },
633 .collision_tiles = enemy_collision_tiles_bounce_horiz,
634 .collision_player = enemy_collision_player_jumpable,
635 .collision_shots = enemy_collision_shots_die,
636 .move_tick = enemy_tick_fly_straight_and_dip
637 }
638 };
This page took 0.101428 seconds and 3 git commands to generate.