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" }
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" }
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" }
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" }
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" }
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" }
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" }
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" }
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" }
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" }
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;
84 ++enemy
->base
.anim_frame
;
85 if(enemy
->base
.anim_frame
>= enemy
->type
->animation_length
) {
86 enemy
->base
.anim_frame
= 0;
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
;
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
;
105 self
->type
->move_tick(self
, state
, lv
, visible_tiles
, player_inertia_mod
);
106 self
->type
->collision_shots(self
, state
);
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
))),
113 enemy_render_flags(self
));
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
;
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;
134 void enemy_collision_tiles_bounce_horiz(jumpnrun_enemy
*self
,
135 vec2d
*desired_position
,
137 jumpnrun_tile_range
const *visible_tiles
) {
138 vec2d inertia_mod
= self
->base
.inertia
;
140 bool killed
= collisions_tiles_displace(desired_position
,
147 self
->flags
&= ~JUMPNRUN_ENEMY_SPAWNED
;
150 if(fixed_point_ne(inertia_mod
.x
, self
->base
.inertia
.x
)) {
151 self
->base
.inertia
.x
= fixed_point_neg(self
->base
.inertia
.x
);
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
;
160 rectangle rect_self
= enemy_hitbox(self
);
162 if(rectangle_intersect(&rect_self
, &state
->player
.current_box
)) {
163 state
->status
= JUMPNRUN_DEAD
;
167 void enemy_collision_player_jumpable(jumpnrun_enemy
*self
,
168 jumpnrun_game_state
*state
,
169 vec2d
*player_inertia_mod
)
171 rectangle rect_self
= enemy_hitbox(self
);
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)))
177 self
->flags
&= ~JUMPNRUN_ENEMY_SPAWNED
;
178 player_inertia_mod
->y
= FIXED_POINT(0, -250);
179 state
->player
.jumpable_frames
= 12;
181 state
->status
= JUMPNRUN_DEAD
;
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
) {
191 (void) desired_position
;
193 (void) visible_tiles
;
197 void enemy_collision_shots_die(struct jumpnrun_enemy
*self
,
198 struct jumpnrun_game_state
*state
) {
199 rectangle rect_self
= enemy_hitbox(self
);
201 for(uint8_t i
= 0; i
< JUMPNRUN_MAX_SHOTS
; ++i
) {
202 jumpnrun_shot
*shot
= &state
->shots
[i
];
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
);
213 void enemy_collision_shots_bounce(struct jumpnrun_enemy
*self
,
214 struct jumpnrun_game_state
*state
) {
215 rectangle rect_self
= enemy_hitbox(self
);
217 for(uint8_t i
= 0; i
< JUMPNRUN_MAX_SHOTS
; ++i
) {
218 jumpnrun_shot
*shot
= &state
->shots
[i
];
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
)));
225 rectangle_move_to_x(&shot
->current_box
, rectangle_right(&rect_self
));
228 shot
->inertia
.x
= fixed_point_neg(shot
->inertia
.x
);
234 void enemy_collision_shots_dontcare(struct jumpnrun_enemy
*self
,
235 struct jumpnrun_game_state
*state
) {
240 void enemy_tick_straight_ahead(jumpnrun_enemy
*self
,
241 jumpnrun_game_state
*state
,
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
));
247 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
248 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
252 jumpnrun_passive_movement(&self
->base
.inertia
);
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
);
259 enemy_animation_advance(self
);
262 void enemy_tick_straight_follow(jumpnrun_enemy
*self
,
263 jumpnrun_game_state
*state
,
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
));
269 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
270 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
274 jumpnrun_passive_movement(&self
->base
.inertia
);
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
);
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
);
287 enemy_animation_advance(self
);
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
));
297 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
298 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
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
);
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
)));
314 enemy_animation_advance(self
);
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
));
324 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
325 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
329 self
->type
->collision_tiles(self
, &self
->base
.current_box
.pos
, lv
, visible_tiles
);
330 self
->type
->collision_player(self
, state
, player_inertia_mod
);
332 enemy_animation_advance(self
);
335 void enemy_tick_jumper(jumpnrun_enemy
*self
,
336 jumpnrun_game_state
*state
,
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
));
342 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
343 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
347 jumpnrun_passive_movement(&self
->base
.inertia
);
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
);
354 if(self
->base
.touching_ground
) {
355 self
->base
.inertia
.y
= self
->type
->spawn_inertia
.y
;
358 enemy_animation_advance(self
);
361 void enemy_tick_dog(jumpnrun_enemy
*self
,
362 jumpnrun_game_state
*state
,
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
));
368 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
369 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
373 jumpnrun_passive_movement(&self
->base
.inertia
);
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
);
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
) {
383 self
->base
.tick_minor
= 0;
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
);
392 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
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
);
405 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
411 self
->base
.anim_frame
= 2;
412 self
->base
.inertia
.x
= FIXED_INT(0);
417 self
->base
.anim_frame
= 3;
418 self
->base
.inertia
.x
= FIXED_INT(0);
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
; }
428 void enemy_tick_giraffe(jumpnrun_enemy
*self
,
429 jumpnrun_game_state
*state
,
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
));
435 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
436 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
440 bool was_on_ground
= self
->base
.touching_ground
;
442 jumpnrun_passive_movement(&self
->base
.inertia
);
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
);
449 if(self
->base
.touching_ground
) {
451 enemy_animation_advance(self
);
452 if(self
->base
.anim_frame
== 0) {
453 self
->base
.inertia
= self
->type
->spawn_inertia
;
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
);
460 self
->base
.tick_minor
= 0;
461 self
->base
.anim_frame
= 3;
462 self
->base
.inertia
.x
= FIXED_INT(0);
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
);
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
; }
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
));
483 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
484 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
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
);
493 enemy_animation_advance(self
);
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
));
503 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
504 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
508 if(fixed_point_lt(fixed_point_abs(fixed_point_sub(enemy_position(self
).x
,
509 state
->player
.current_box
.pos
.x
)),
511 self
->flags
|= JUMPNRUN_ENEMY_EVENT_TRIGGER1
;
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
)));
522 self
->base
.inertia
.y
= FIXED_INT(0);
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
);
530 enemy_animation_advance(self
);
533 jumpnrun_enemy_type
const jumpnrun_enemy_type_data
[JUMPNRUN_ENEMY_TYPE_COUNT
] = {
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
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
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
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
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
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
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
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
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
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
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