Gegnerspawning an Checkpoints richtig.
[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 + BADGE_DISPLAY_WIDTH + spawn_margin, 0))) {
123 // enemy unspawned, available and in spawn zone.
124 self->flags = JUMPNRUN_ENEMY_SPAWNED | JUMPNRUN_ENEMY_UNAVAILABLE;
125 self->base.current_box = rectangle_new(self->spawn_pos, self->type->extent);
126 self->base.inertia = self->type->spawn_inertia;
127 self->base.anim_frame = 0;
128 self->base.tick_minor = 0;
129 self->base.touching_ground = false;
130 self->base.jumpable_frames = 0;
131 }
132 }
133
134 void enemy_collision_tiles_bounce_horiz(jumpnrun_enemy *self,
135 vec2d *desired_position,
136 jumpnrun_level *lv,
137 jumpnrun_tile_range const *visible_tiles) {
138 vec2d inertia_mod = self->base.inertia;
139
140 bool killed = collisions_tiles_displace(desired_position,
141 &self->base,
142 lv,
143 visible_tiles,
144 &inertia_mod);
145
146 if(killed) {
147 self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
148 }
149
150 if(fixed_point_ne(inertia_mod.x, self->base.inertia.x)) {
151 self->base.inertia.x = fixed_point_neg(self->base.inertia.x);
152 }
153 }
154
155 void enemy_collision_player_deadly(struct jumpnrun_enemy *self,
156 struct jumpnrun_game_state *state,
157 vec2d *player_inertia_mod) {
158 (void) player_inertia_mod;
159
160 rectangle rect_self = enemy_hitbox(self);
161
162 if(rectangle_intersect(&rect_self, &state->player.current_box)) {
163 state->status = JUMPNRUN_DEAD;
164 }
165 }
166
167 void enemy_collision_player_jumpable(jumpnrun_enemy *self,
168 jumpnrun_game_state *state,
169 vec2d *player_inertia_mod)
170 {
171 rectangle rect_self = enemy_hitbox(self);
172
173 if(rectangle_intersect(&rect_self, &state->player.current_box)) {
174 if(fixed_point_lt(rectangle_top(&state->player.current_box), rectangle_top(&rect_self)) &&
175 fixed_point_gt(state->player.inertia.y, FIXED_POINT(0, 0)))
176 {
177 self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
178 player_inertia_mod->y = FIXED_POINT(0, -250);
179 state->player.jumpable_frames = 12;
180 } else {
181 state->status = JUMPNRUN_DEAD;
182 }
183 }
184 }
185
186 void enemy_collision_tiles_pass_through(struct jumpnrun_enemy *self,
187 vec2d *desired_position,
188 struct jumpnrun_level *lv,
189 struct jumpnrun_tile_range const *visible_tiles) {
190 (void) self;
191 (void) desired_position;
192 (void) lv;
193 (void) visible_tiles;
194 return;
195 }
196
197 void enemy_collision_shots_die(struct jumpnrun_enemy *self,
198 struct jumpnrun_game_state *state) {
199 rectangle rect_self = enemy_hitbox(self);
200
201 for(uint8_t i = 0; i < JUMPNRUN_MAX_SHOTS; ++i) {
202 jumpnrun_shot *shot = &state->shots[i];
203
204 if(jumpnrun_shot_spawned(shot)) {
205 if(rectangle_intersect(&rect_self, &shot->current_box)) {
206 self->flags &= ~JUMPNRUN_ENEMY_SPAWNED;
207 jumpnrun_shot_despawn(shot);
208 }
209 }
210 }
211 }
212
213 void enemy_collision_shots_bounce(struct jumpnrun_enemy *self,
214 struct jumpnrun_game_state *state) {
215 rectangle rect_self = enemy_hitbox(self);
216
217 for(uint8_t i = 0; i < JUMPNRUN_MAX_SHOTS; ++i) {
218 jumpnrun_shot *shot = &state->shots[i];
219
220 if(jumpnrun_shot_spawned(shot)) {
221 if(rectangle_intersect(&rect_self, &shot->current_box)) {
222 if(fixed_point_gt(shot->inertia.x, FIXED_INT(0))) {
223 rectangle_move_to_x(&shot->current_box, fixed_point_sub(rectangle_left(&rect_self), rectangle_width(&shot->current_box)));
224 } else {
225 rectangle_move_to_x(&shot->current_box, rectangle_right(&rect_self));
226 }
227
228 shot->inertia.x = fixed_point_neg(shot->inertia.x);
229 }
230 }
231 }
232 }
233
234 void enemy_collision_shots_dontcare(struct jumpnrun_enemy *self,
235 struct jumpnrun_game_state *state) {
236 (void) self;
237 (void) state;
238 }
239
240 void enemy_tick_straight_ahead(jumpnrun_enemy *self,
241 jumpnrun_game_state *state,
242 jumpnrun_level *lv,
243 jumpnrun_tile_range const *visible_tiles,
244 vec2d *player_inertia_mod) {
245 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
246
247 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
248 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
249 return;
250 }
251
252 jumpnrun_passive_movement(&self->base.inertia);
253
254 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
255 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
256 self->type->collision_player(self, state, player_inertia_mod);
257 rectangle_move_to(&self->base.current_box, new_pos);
258
259 enemy_animation_advance(self);
260 }
261
262 void enemy_tick_straight_follow(jumpnrun_enemy *self,
263 jumpnrun_game_state *state,
264 jumpnrun_level *lv,
265 jumpnrun_tile_range const *visible_tiles,
266 vec2d *player_inertia_mod) {
267 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
268
269 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
270 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
271 return;
272 }
273
274 jumpnrun_passive_movement(&self->base.inertia);
275
276 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
277 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
278 self->type->collision_player(self, state, player_inertia_mod);
279 rectangle_move_to(&self->base.current_box, new_pos);
280
281 if(fixed_point_lt(rectangle_right(&state->player.current_box), rectangle_left(enemy_box(self)))) {
282 self->base.inertia.x = self->type->spawn_inertia.x;
283 } else if(fixed_point_gt(rectangle_left(&state->player.current_box), rectangle_right(enemy_box(self)))) {
284 self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
285 }
286
287 enemy_animation_advance(self);
288 }
289
290 void enemy_tick_swing_up_and_down(struct jumpnrun_enemy *self,
291 struct jumpnrun_game_state *state,
292 struct jumpnrun_level *lv,
293 struct jumpnrun_tile_range const *visible_tiles,
294 vec2d *player_inertia_mod) {
295 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
296
297 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
298 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
299 return;
300 }
301
302 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
303 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
304 self->type->collision_player(self, state, player_inertia_mod);
305 rectangle_move_to(&self->base.current_box, new_pos);
306
307 self->base.inertia.y =
308 fixed_point_add(fixed_point_add(self->base.inertia.y,
309 fixed_point_div(self->type->spawn_inertia.y, FIXED_INT(3))),
310 fixed_point_mul(FIXED_POINT(0, 5),
311 fixed_point_sub(self->spawn_pos.y,
312 enemy_position(self).y)));
313
314 enemy_animation_advance(self);
315 }
316
317 void enemy_tick_stationary(struct jumpnrun_enemy *self,
318 struct jumpnrun_game_state *state,
319 struct jumpnrun_level *lv,
320 struct jumpnrun_tile_range const *visible_tiles,
321 vec2d *player_inertia_mod) {
322 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
323
324 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
325 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
326 return;
327 }
328
329 self->type->collision_tiles(self, &self->base.current_box.pos, lv, visible_tiles);
330 self->type->collision_player(self, state, player_inertia_mod);
331
332 enemy_animation_advance(self);
333 }
334
335 void enemy_tick_jumper(jumpnrun_enemy *self,
336 jumpnrun_game_state *state,
337 jumpnrun_level *lv,
338 jumpnrun_tile_range const *visible_tiles,
339 vec2d *player_inertia_mod) {
340 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
341
342 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
343 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
344 return;
345 }
346
347 jumpnrun_passive_movement(&self->base.inertia);
348
349 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
350 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
351 self->type->collision_player(self, state, player_inertia_mod);
352 rectangle_move_to(&self->base.current_box, new_pos);
353
354 if(self->base.touching_ground) {
355 self->base.inertia.y = self->type->spawn_inertia.y;
356 }
357
358 enemy_animation_advance(self);
359 }
360
361 void enemy_tick_dog(jumpnrun_enemy *self,
362 jumpnrun_game_state *state,
363 jumpnrun_level *lv,
364 jumpnrun_tile_range const *visible_tiles,
365 vec2d *player_inertia_mod) {
366 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
367
368 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
369 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
370 return;
371 }
372
373 jumpnrun_passive_movement(&self->base.inertia);
374
375 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
376 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
377 self->type->collision_player(self, state, player_inertia_mod);
378 rectangle_move_to(&self->base.current_box, new_pos);
379
380 if(self->base.tick_minor % self->type->animation_ticks_per_frame == 0) {
381 switch(self->base.tick_minor / self->type->animation_ticks_per_frame) {
382 case 12:
383 self->base.tick_minor = 0;
384 case 0:
385 case 2:
386 case 4:
387 case 6:
388 self->base.anim_frame = 0;
389 if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
390 self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
391 } else {
392 self->base.inertia.x = self->type->spawn_inertia.x;
393 }
394
395 break;
396
397 case 1:
398 case 3:
399 case 5:
400 case 7:
401 self->base.anim_frame = 1;
402 if(self->flags & JUMPNRUN_ENEMY_FACING_RIGHT) {
403 self->base.inertia.x = fixed_point_neg(self->type->spawn_inertia.x);
404 } else {
405 self->base.inertia.x = self->type->spawn_inertia.x;
406 }
407 break;
408
409 case 8:
410 case 10:
411 self->base.anim_frame = 2;
412 self->base.inertia.x = FIXED_INT(0);
413 break;
414
415 case 9:
416 case 11:
417 self->base.anim_frame = 3;
418 self->base.inertia.x = FIXED_INT(0);
419 break;
420 }
421 }
422
423 ++self->base.tick_minor;
424 if (fixed_point_lt(self->base.inertia.x, FIXED_INT(0))) { self->flags &= ~JUMPNRUN_ENEMY_FACING_RIGHT; }
425 else if(fixed_point_ne(self->base.inertia.x, FIXED_INT(0))) { self->flags |= JUMPNRUN_ENEMY_FACING_RIGHT; }
426 }
427
428 void enemy_tick_giraffe(jumpnrun_enemy *self,
429 jumpnrun_game_state *state,
430 jumpnrun_level *lv,
431 jumpnrun_tile_range const *visible_tiles,
432 vec2d *player_inertia_mod) {
433 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
434
435 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
436 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
437 return;
438 }
439
440 bool was_on_ground = self->base.touching_ground;
441
442 jumpnrun_passive_movement(&self->base.inertia);
443
444 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
445 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
446 self->type->collision_player(self, state, player_inertia_mod);
447 rectangle_move_to(&self->base.current_box, new_pos);
448
449 if(self->base.touching_ground) {
450 if(was_on_ground) {
451 enemy_animation_advance(self);
452 if(self->base.anim_frame == 0) {
453 self->base.inertia = self->type->spawn_inertia;
454
455 if(fixed_point_gt(rectangle_mid_x(&state->player.current_box), rectangle_mid_x(enemy_box(self)))) {
456 self->base.inertia.x = fixed_point_neg(self->base.inertia.x);
457 }
458 }
459 } else {
460 self->base.tick_minor = 0;
461 self->base.anim_frame = 3;
462 self->base.inertia.x = FIXED_INT(0);
463 }
464 } else if(was_on_ground) {
465 self->base.tick_minor = 0;
466 self->base.anim_frame = 1;
467 } else if(self->base.anim_frame == 1) {
468 enemy_animation_advance(self);
469 }
470
471 ++self->base.tick_minor;
472 if (fixed_point_lt(self->base.inertia.x, FIXED_INT(0))) { self->flags &= ~JUMPNRUN_ENEMY_FACING_RIGHT; }
473 else if(fixed_point_ne(self->base.inertia.x, FIXED_INT(0))) { self->flags |= JUMPNRUN_ENEMY_FACING_RIGHT; }
474 }
475
476 void enemy_tick_fly_straight(struct jumpnrun_enemy *self,
477 struct jumpnrun_game_state *state,
478 struct jumpnrun_level *lv,
479 struct jumpnrun_tile_range const *visible_tiles,
480 vec2d *player_inertia_mod) {
481 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
482
483 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
484 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
485 return;
486 }
487
488 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);
489 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
490 self->type->collision_player(self, state, player_inertia_mod);
491 rectangle_move_to(&self->base.current_box, new_pos);
492
493 enemy_animation_advance(self);
494 }
495
496 void enemy_tick_fly_straight_and_dip(struct jumpnrun_enemy *self,
497 struct jumpnrun_game_state *state,
498 struct jumpnrun_level *lv,
499 struct jumpnrun_tile_range const *visible_tiles,
500 vec2d *player_inertia_mod) {
501 int screenpos = fixed_point_cast_int(rectangle_left(&self->base.current_box));
502
503 if(screenpos + JUMPNRUN_MAX_SPAWN_MARGIN < state->left ||
504 screenpos >= state->left + BADGE_DISPLAY_WIDTH + JUMPNRUN_MAX_SPAWN_MARGIN) {
505 return;
506 }
507
508 if(fixed_point_lt(fixed_point_abs(fixed_point_sub(enemy_position(self).x,
509 state->player.current_box.pos.x)),
510 FIXED_INT(20))) {
511 self->flags |= JUMPNRUN_ENEMY_EVENT_TRIGGER1;
512 }
513
514 if(self->flags & JUMPNRUN_ENEMY_EVENT_TRIGGER1) {
515 self->base.inertia.y =
516 fixed_point_add(fixed_point_add(self->base.inertia.y,
517 fixed_point_div(self->type->spawn_inertia.y, FIXED_INT(3))),
518 fixed_point_mul(FIXED_POINT(0, 5),
519 fixed_point_sub(self->spawn_pos.y,
520 enemy_position(self).y)));
521 } else {
522 self->base.inertia.y = FIXED_INT(0);
523 }
524
525 vec2d new_pos = vec2d_add(enemy_position(self), self->base.inertia);;
526 self->type->collision_tiles(self, &new_pos, lv, visible_tiles);
527 self->type->collision_player(self, state, player_inertia_mod);
528 rectangle_move_to(&self->base.current_box, new_pos);
529
530 enemy_animation_advance(self);
531 }
532
533 jumpnrun_enemy_type const jumpnrun_enemy_type_data[JUMPNRUN_ENEMY_TYPE_COUNT] = {
534 {
535 .animation_ticks_per_frame = 18,
536 .animation_length = ARRAY_SIZE(anim_cat),
537 .animation_frames = anim_cat,
538 .extent = { FIXED_INT_I(8), FIXED_INT_I(5) },
539 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(2) },
540 { FIXED_INT_I(6), FIXED_INT_I(3) } },
541 .spawn_inertia = { FIXED_POINT_I(0, -200), FIXED_INT_I(0) },
542 .collision_tiles = enemy_collision_tiles_bounce_horiz,
543 .collision_player = enemy_collision_player_jumpable,
544 .collision_shots = enemy_collision_shots_die,
545 .move_tick = enemy_tick_straight_ahead
546 }, {
547 .animation_ticks_per_frame = 12,
548 .animation_length = ARRAY_SIZE(anim_mushroom),
549 .animation_frames = anim_mushroom,
550 .extent = { FIXED_INT_I(7), FIXED_INT_I(7) },
551 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
552 { FIXED_INT_I(5), FIXED_INT_I(4) } },
553 .spawn_inertia = { FIXED_POINT_I(0, -80), FIXED_INT_I(0) },
554 .collision_tiles = enemy_collision_tiles_bounce_horiz,
555 .collision_player = enemy_collision_player_jumpable,
556 .collision_shots = enemy_collision_shots_die,
557 .move_tick = enemy_tick_straight_follow
558 }, {
559 .animation_ticks_per_frame = 9,
560 .animation_length = ARRAY_SIZE(anim_bunny),
561 .animation_frames = anim_bunny,
562 .extent = { FIXED_INT_I(7), FIXED_INT_I(5) },
563 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(2) },
564 { FIXED_INT_I(5), FIXED_INT_I(3) } },
565 .spawn_inertia = { FIXED_POINT_I(0, -80), FIXED_POINT_I(0, -800) },
566 .collision_tiles = enemy_collision_tiles_bounce_horiz,
567 .collision_player = enemy_collision_player_jumpable,
568 .collision_shots = enemy_collision_shots_die,
569 .move_tick = enemy_tick_jumper
570 }, {
571 .animation_ticks_per_frame = 6,
572 .animation_length = ARRAY_SIZE(anim_snake),
573 .animation_frames = anim_snake,
574 .extent = { FIXED_INT_I(10), FIXED_INT_I(6) },
575 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(4) },
576 { FIXED_INT_I(8), FIXED_INT_I(2) } },
577 .spawn_inertia = { FIXED_POINT_I(0, -150), FIXED_INT_I(0) },
578 .collision_tiles = enemy_collision_tiles_bounce_horiz,
579 .collision_player = enemy_collision_player_jumpable,
580 .collision_shots = enemy_collision_shots_die,
581 .move_tick = enemy_tick_straight_ahead
582 }, {
583 .animation_ticks_per_frame = 6,
584 .animation_length = ARRAY_SIZE(anim_spiral),
585 .animation_frames = anim_spiral,
586 .extent = { FIXED_INT_I(10), FIXED_INT_I(10) },
587 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
588 { FIXED_INT_I(8), FIXED_INT_I(8) } },
589 .spawn_inertia = { FIXED_INT_I(0), FIXED_POINT_I(0, -200) },
590 .collision_tiles = enemy_collision_tiles_pass_through,
591 .collision_player = enemy_collision_player_deadly,
592 .collision_shots = enemy_collision_shots_dontcare,
593 .move_tick = enemy_tick_swing_up_and_down
594 }, {
595 .animation_ticks_per_frame = 5,
596 .animation_length = ARRAY_SIZE(anim_rotor),
597 .animation_frames = anim_rotor,
598 .extent = { FIXED_INT_I(9), FIXED_INT_I(9) },
599 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
600 { FIXED_INT_I(7), FIXED_INT_I(7) } },
601 .spawn_inertia = { FIXED_INT_I(0), FIXED_POINT_I(0, 0) },
602 .collision_tiles = enemy_collision_tiles_pass_through,
603 .collision_player = enemy_collision_player_deadly,
604 .collision_shots = enemy_collision_shots_dontcare,
605 .move_tick = enemy_tick_stationary
606 }, {
607 .animation_ticks_per_frame = 18,
608 .animation_length = ARRAY_SIZE(anim_dog),
609 .animation_frames = anim_dog,
610 .extent = { FIXED_INT_I(8), FIXED_INT_I(5) },
611 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(1) },
612 { FIXED_INT_I(6), FIXED_INT_I(4) } },
613 .spawn_inertia = { FIXED_POINT_I(0, -200), FIXED_POINT_I(0, 0) },
614 .collision_tiles = enemy_collision_tiles_bounce_horiz,
615 .collision_player = enemy_collision_player_jumpable,
616 .collision_shots = enemy_collision_shots_die,
617 .move_tick = enemy_tick_dog
618 }, {
619 .animation_ticks_per_frame = 36,
620 .animation_length = ARRAY_SIZE(anim_giraffe),
621 .animation_frames = anim_giraffe,
622 .extent = { FIXED_INT_I(7), FIXED_INT_I(10) },
623 .hitbox = { { FIXED_INT_I(2), FIXED_INT_I(1) },
624 { FIXED_INT_I(4), FIXED_INT_I(9) } },
625 .spawn_inertia = { FIXED_POINT_I(0, -150), FIXED_POINT_I(-1, -200) },
626 .collision_tiles = enemy_collision_tiles_bounce_horiz,
627 .collision_player = enemy_collision_player_jumpable,
628 .collision_shots = enemy_collision_shots_bounce,
629 .move_tick = enemy_tick_giraffe
630 }, {
631 .animation_ticks_per_frame = 24,
632 .animation_length = ARRAY_SIZE(anim_bird),
633 .animation_frames = anim_bird,
634 .extent = { FIXED_INT_I(9), FIXED_INT_I(7) },
635 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(3) },
636 { FIXED_INT_I(7), FIXED_INT_I(3) } },
637 .spawn_inertia = { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, -150) },
638 .collision_tiles = enemy_collision_tiles_bounce_horiz,
639 .collision_player = enemy_collision_player_jumpable,
640 .collision_shots = enemy_collision_shots_die,
641 .move_tick = enemy_tick_swing_up_and_down
642 }, {
643 .animation_ticks_per_frame = 24,
644 .animation_length = ARRAY_SIZE(anim_bird),
645 .animation_frames = anim_bird,
646 .extent = { FIXED_INT_I(9), FIXED_INT_I(7) },
647 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(3) },
648 { FIXED_INT_I(7), FIXED_INT_I(3) } },
649 .spawn_inertia = { FIXED_POINT_I(0, -400), FIXED_INT_I(0) },
650 .collision_tiles = enemy_collision_tiles_bounce_horiz,
651 .collision_player = enemy_collision_player_jumpable,
652 .collision_shots = enemy_collision_shots_die,
653 .move_tick = enemy_tick_fly_straight
654 }, {
655 .animation_ticks_per_frame = 24,
656 .animation_length = ARRAY_SIZE(anim_bird),
657 .animation_frames = anim_bird,
658 .extent = { FIXED_INT_I(9), FIXED_INT_I(7) },
659 .hitbox = { { FIXED_INT_I(1), FIXED_INT_I(3) },
660 { FIXED_INT_I(7), FIXED_INT_I(3) } },
661 .spawn_inertia = { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, 200) },
662 .collision_tiles = enemy_collision_tiles_bounce_horiz,
663 .collision_player = enemy_collision_player_jumpable,
664 .collision_shots = enemy_collision_shots_die,
665 .move_tick = enemy_tick_fly_straight_and_dip
666 }
667 };
This page took 0.083469 seconds and 5 git commands to generate.