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
- 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;
136 void enemy_collision_tiles_bounce_horiz(jumpnrun_enemy
*self
,
137 vec2d
*desired_position
,
139 jumpnrun_tile_range
const *visible_tiles
) {
140 vec2d inertia_mod
= self
->base
.inertia
;
142 bool killed
= collisions_tiles_displace(desired_position
,
149 self
->flags
&= ~JUMPNRUN_ENEMY_SPAWNED
;
152 if(fixed_point_ne(inertia_mod
.x
, self
->base
.inertia
.x
)) {
153 self
->base
.inertia
.x
= fixed_point_neg(self
->base
.inertia
.x
);
157 void enemy_collision_player_deadly(struct jumpnrun_enemy
*self
,
158 struct jumpnrun_game_state
*state
,
159 vec2d
*player_inertia_mod
) {
160 (void) player_inertia_mod
;
162 rectangle rect_self
= enemy_hitbox(self
);
164 if(rectangle_intersect(&rect_self
, &state
->player
.current_box
)) {
165 state
->status
= JUMPNRUN_DEAD
;
169 void enemy_collision_player_jumpable(jumpnrun_enemy
*self
,
170 jumpnrun_game_state
*state
,
171 vec2d
*player_inertia_mod
)
173 rectangle rect_self
= enemy_hitbox(self
);
175 if(rectangle_intersect(&rect_self
, &state
->player
.current_box
)) {
176 if(fixed_point_lt(rectangle_top(&state
->player
.current_box
), rectangle_top(&rect_self
)) &&
177 fixed_point_gt(state
->player
.inertia
.y
, FIXED_POINT(0, 0)))
179 self
->flags
&= ~JUMPNRUN_ENEMY_SPAWNED
;
180 player_inertia_mod
->y
= FIXED_POINT(0, -250);
181 state
->player
.jumpable_frames
= 12;
183 state
->status
= JUMPNRUN_DEAD
;
188 void enemy_collision_tiles_pass_through(struct jumpnrun_enemy
*self
,
189 vec2d
*desired_position
,
190 struct jumpnrun_level
*lv
,
191 struct jumpnrun_tile_range
const *visible_tiles
) {
193 (void) desired_position
;
195 (void) visible_tiles
;
199 void enemy_collision_shots_die(struct jumpnrun_enemy
*self
,
200 struct jumpnrun_game_state
*state
) {
201 rectangle rect_self
= enemy_hitbox(self
);
203 for(uint8_t i
= 0; i
< JUMPNRUN_MAX_SHOTS
; ++i
) {
204 jumpnrun_shot
*shot
= &state
->shots
[i
];
206 if(jumpnrun_shot_spawned(shot
)) {
207 if(rectangle_intersect(&rect_self
, &shot
->current_box
)) {
208 self
->flags
&= ~JUMPNRUN_ENEMY_SPAWNED
;
209 jumpnrun_shot_despawn(shot
);
215 void enemy_collision_shots_bounce(struct jumpnrun_enemy
*self
,
216 struct jumpnrun_game_state
*state
) {
217 rectangle rect_self
= enemy_hitbox(self
);
219 for(uint8_t i
= 0; i
< JUMPNRUN_MAX_SHOTS
; ++i
) {
220 jumpnrun_shot
*shot
= &state
->shots
[i
];
222 if(jumpnrun_shot_spawned(shot
)) {
223 if(rectangle_intersect(&rect_self
, &shot
->current_box
)) {
224 if(fixed_point_gt(shot
->inertia
.x
, FIXED_INT(0))) {
225 rectangle_move_to_x(&shot
->current_box
, fixed_point_sub(rectangle_left(&rect_self
), rectangle_width(&shot
->current_box
)));
227 rectangle_move_to_x(&shot
->current_box
, rectangle_right(&rect_self
));
230 shot
->inertia
.x
= fixed_point_neg(shot
->inertia
.x
);
236 void enemy_collision_shots_dontcare(struct jumpnrun_enemy
*self
,
237 struct jumpnrun_game_state
*state
) {
242 void enemy_tick_straight_ahead(jumpnrun_enemy
*self
,
243 jumpnrun_game_state
*state
,
245 jumpnrun_tile_range
const *visible_tiles
,
246 vec2d
*player_inertia_mod
) {
247 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
249 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
250 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
254 jumpnrun_passive_movement(&self
->base
.inertia
);
256 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
257 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
258 self
->type
->collision_player(self
, state
, player_inertia_mod
);
259 rectangle_move_to(&self
->base
.current_box
, new_pos
);
261 enemy_animation_advance(self
);
264 void enemy_tick_straight_follow(jumpnrun_enemy
*self
,
265 jumpnrun_game_state
*state
,
267 jumpnrun_tile_range
const *visible_tiles
,
268 vec2d
*player_inertia_mod
) {
269 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
271 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
272 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
276 jumpnrun_passive_movement(&self
->base
.inertia
);
278 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
279 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
280 self
->type
->collision_player(self
, state
, player_inertia_mod
);
281 rectangle_move_to(&self
->base
.current_box
, new_pos
);
283 if(fixed_point_le(rectangle_mid_x(&state
->player
.current_box
), rectangle_mid_x(enemy_box(self
)))) {
284 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
286 self
->base
.inertia
.x
= fixed_point_neg(self
->type
->spawn_inertia
.x
);
290 enemy_animation_advance(self
);
293 void enemy_tick_swing_up_and_down(struct jumpnrun_enemy
*self
,
294 struct jumpnrun_game_state
*state
,
295 struct jumpnrun_level
*lv
,
296 struct jumpnrun_tile_range
const *visible_tiles
,
297 vec2d
*player_inertia_mod
) {
298 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
300 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
301 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
305 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
306 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
307 self
->type
->collision_player(self
, state
, player_inertia_mod
);
308 rectangle_move_to(&self
->base
.current_box
, new_pos
);
310 self
->base
.inertia
.y
=
311 fixed_point_add(fixed_point_add(self
->base
.inertia
.y
,
312 fixed_point_div(self
->type
->spawn_inertia
.y
, FIXED_INT(3))),
313 fixed_point_mul(FIXED_POINT(0, 5),
314 fixed_point_sub(self
->spawn_pos
.y
,
315 enemy_position(self
).y
)));
317 enemy_animation_advance(self
);
320 void enemy_tick_stationary(struct jumpnrun_enemy
*self
,
321 struct jumpnrun_game_state
*state
,
322 struct jumpnrun_level
*lv
,
323 struct jumpnrun_tile_range
const *visible_tiles
,
324 vec2d
*player_inertia_mod
) {
325 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
327 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
328 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
332 self
->type
->collision_tiles(self
, &self
->base
.current_box
.pos
, lv
, visible_tiles
);
333 self
->type
->collision_player(self
, state
, player_inertia_mod
);
335 enemy_animation_advance(self
);
338 void enemy_tick_jumper(jumpnrun_enemy
*self
,
339 jumpnrun_game_state
*state
,
341 jumpnrun_tile_range
const *visible_tiles
,
342 vec2d
*player_inertia_mod
) {
343 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
345 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
346 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
350 jumpnrun_passive_movement(&self
->base
.inertia
);
352 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
353 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
354 self
->type
->collision_player(self
, state
, player_inertia_mod
);
355 rectangle_move_to(&self
->base
.current_box
, new_pos
);
357 if(self
->base
.touching_ground
) {
358 self
->base
.inertia
.y
= self
->type
->spawn_inertia
.y
;
361 enemy_animation_advance(self
);
364 void enemy_tick_dog(jumpnrun_enemy
*self
,
365 jumpnrun_game_state
*state
,
367 jumpnrun_tile_range
const *visible_tiles
,
368 vec2d
*player_inertia_mod
) {
369 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
371 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
372 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
376 jumpnrun_passive_movement(&self
->base
.inertia
);
378 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
379 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
380 self
->type
->collision_player(self
, state
, player_inertia_mod
);
381 rectangle_move_to(&self
->base
.current_box
, new_pos
);
383 if(self
->base
.tick_minor
% self
->type
->animation_ticks_per_frame
== 0) {
384 switch(self
->base
.tick_minor
/ self
->type
->animation_ticks_per_frame
) {
386 self
->base
.tick_minor
= 0;
391 self
->base
.anim_frame
= 0;
392 if(self
->flags
& JUMPNRUN_ENEMY_FACING_RIGHT
) {
393 self
->base
.inertia
.x
= fixed_point_neg(self
->type
->spawn_inertia
.x
);
395 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
404 self
->base
.anim_frame
= 1;
405 if(self
->flags
& JUMPNRUN_ENEMY_FACING_RIGHT
) {
406 self
->base
.inertia
.x
= fixed_point_neg(self
->type
->spawn_inertia
.x
);
408 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
414 self
->base
.anim_frame
= 2;
415 self
->base
.inertia
.x
= FIXED_INT(0);
420 self
->base
.anim_frame
= 3;
421 self
->base
.inertia
.x
= FIXED_INT(0);
426 ++self
->base
.tick_minor
;
427 if (fixed_point_lt(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
&= ~JUMPNRUN_ENEMY_FACING_RIGHT
; }
428 else if(fixed_point_ne(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
|= JUMPNRUN_ENEMY_FACING_RIGHT
; }
431 void enemy_tick_giraffe(jumpnrun_enemy
*self
,
432 jumpnrun_game_state
*state
,
434 jumpnrun_tile_range
const *visible_tiles
,
435 vec2d
*player_inertia_mod
) {
436 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
438 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
439 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
443 bool was_on_ground
= self
->base
.touching_ground
;
445 jumpnrun_passive_movement(&self
->base
.inertia
);
447 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
448 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
449 self
->type
->collision_player(self
, state
, player_inertia_mod
);
450 rectangle_move_to(&self
->base
.current_box
, new_pos
);
452 if(self
->base
.touching_ground
) {
454 enemy_animation_advance(self
);
455 if(self
->base
.anim_frame
== 0) {
456 self
->base
.inertia
= self
->type
->spawn_inertia
;
458 if(fixed_point_gt(rectangle_mid_x(&state
->player
.current_box
), rectangle_mid_x(enemy_box(self
)))) {
459 self
->base
.inertia
.x
= fixed_point_neg(self
->base
.inertia
.x
);
463 self
->base
.tick_minor
= 0;
464 self
->base
.anim_frame
= 3;
465 self
->base
.inertia
.x
= FIXED_INT(0);
467 } else if(was_on_ground
) {
468 self
->base
.tick_minor
= 0;
469 self
->base
.anim_frame
= 1;
470 } else if(self
->base
.anim_frame
== 1) {
471 enemy_animation_advance(self
);
474 ++self
->base
.tick_minor
;
475 if (fixed_point_lt(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
&= ~JUMPNRUN_ENEMY_FACING_RIGHT
; }
476 else if(fixed_point_ne(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
|= JUMPNRUN_ENEMY_FACING_RIGHT
; }
479 void enemy_tick_fly_straight(struct jumpnrun_enemy
*self
,
480 struct jumpnrun_game_state
*state
,
481 struct jumpnrun_level
*lv
,
482 struct jumpnrun_tile_range
const *visible_tiles
,
483 vec2d
*player_inertia_mod
) {
484 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
486 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
487 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
491 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
492 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
493 self
->type
->collision_player(self
, state
, player_inertia_mod
);
494 rectangle_move_to(&self
->base
.current_box
, new_pos
);
496 enemy_animation_advance(self
);
499 void enemy_tick_fly_straight_and_dip(struct jumpnrun_enemy
*self
,
500 struct jumpnrun_game_state
*state
,
501 struct jumpnrun_level
*lv
,
502 struct jumpnrun_tile_range
const *visible_tiles
,
503 vec2d
*player_inertia_mod
) {
504 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
506 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
507 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
511 if(fixed_point_lt(fixed_point_abs(fixed_point_sub(enemy_position(self
).x
,
512 state
->player
.current_box
.pos
.x
)),
514 self
->flags
|= JUMPNRUN_ENEMY_EVENT_TRIGGER1
;
517 if(self
->flags
& JUMPNRUN_ENEMY_EVENT_TRIGGER1
) {
518 self
->base
.inertia
.y
=
519 fixed_point_add(fixed_point_add(self
->base
.inertia
.y
,
520 fixed_point_div(self
->type
->spawn_inertia
.y
, FIXED_INT(3))),
521 fixed_point_mul(FIXED_POINT(0, 5),
522 fixed_point_sub(self
->spawn_pos
.y
,
523 enemy_position(self
).y
)));
525 self
->base
.inertia
.y
= FIXED_INT(0);
528 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);;
529 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
530 self
->type
->collision_player(self
, state
, player_inertia_mod
);
531 rectangle_move_to(&self
->base
.current_box
, new_pos
);
533 enemy_animation_advance(self
);
536 jumpnrun_enemy_type
const jumpnrun_enemy_type_data
[JUMPNRUN_ENEMY_TYPE_COUNT
] = {
538 .animation_ticks_per_frame
= 18,
539 .animation_length
= ARRAY_SIZE(anim_cat
),
540 .animation_frames
= anim_cat
,
541 .extent
= { FIXED_INT_I(8), FIXED_INT_I(5) },
542 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(2) },
543 { FIXED_INT_I(6), FIXED_INT_I(3) } },
544 .spawn_inertia
= { FIXED_POINT_I(0, -200), FIXED_INT_I(0) },
545 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
546 .collision_player
= enemy_collision_player_jumpable
,
547 .collision_shots
= enemy_collision_shots_die
,
548 .move_tick
= enemy_tick_straight_ahead
550 .animation_ticks_per_frame
= 12,
551 .animation_length
= ARRAY_SIZE(anim_mushroom
),
552 .animation_frames
= anim_mushroom
,
553 .extent
= { FIXED_INT_I(7), FIXED_INT_I(7) },
554 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
555 { FIXED_INT_I(5), FIXED_INT_I(4) } },
556 .spawn_inertia
= { FIXED_POINT_I(0, -50), FIXED_INT_I(0) },
557 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
558 .collision_player
= enemy_collision_player_jumpable
,
559 .collision_shots
= enemy_collision_shots_die
,
560 .move_tick
= enemy_tick_straight_follow
562 .animation_ticks_per_frame
= 9,
563 .animation_length
= ARRAY_SIZE(anim_bunny
),
564 .animation_frames
= anim_bunny
,
565 .extent
= { FIXED_INT_I(7), FIXED_INT_I(5) },
566 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(2) },
567 { FIXED_INT_I(5), FIXED_INT_I(3) } },
568 .spawn_inertia
= { FIXED_POINT_I(0, -80), FIXED_POINT_I(0, -800) },
569 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
570 .collision_player
= enemy_collision_player_jumpable
,
571 .collision_shots
= enemy_collision_shots_die
,
572 .move_tick
= enemy_tick_jumper
574 .animation_ticks_per_frame
= 6,
575 .animation_length
= ARRAY_SIZE(anim_snake
),
576 .animation_frames
= anim_snake
,
577 .extent
= { FIXED_INT_I(10), FIXED_INT_I(6) },
578 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(4) },
579 { FIXED_INT_I(8), FIXED_INT_I(2) } },
580 .spawn_inertia
= { FIXED_POINT_I(0, -150), FIXED_INT_I(0) },
581 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
582 .collision_player
= enemy_collision_player_jumpable
,
583 .collision_shots
= enemy_collision_shots_die
,
584 .move_tick
= enemy_tick_straight_ahead
586 .animation_ticks_per_frame
= 6,
587 .animation_length
= ARRAY_SIZE(anim_spiral
),
588 .animation_frames
= anim_spiral
,
589 .extent
= { FIXED_INT_I(10), FIXED_INT_I(10) },
590 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
591 { FIXED_INT_I(8), FIXED_INT_I(8) } },
592 .spawn_inertia
= { FIXED_INT_I(0), FIXED_POINT_I(0, -200) },
593 .collision_tiles
= enemy_collision_tiles_pass_through
,
594 .collision_player
= enemy_collision_player_deadly
,
595 .collision_shots
= enemy_collision_shots_dontcare
,
596 .move_tick
= enemy_tick_swing_up_and_down
598 .animation_ticks_per_frame
= 5,
599 .animation_length
= ARRAY_SIZE(anim_rotor
),
600 .animation_frames
= anim_rotor
,
601 .extent
= { FIXED_INT_I(9), FIXED_INT_I(9) },
602 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
603 { FIXED_INT_I(7), FIXED_INT_I(7) } },
604 .spawn_inertia
= { FIXED_INT_I(0), FIXED_POINT_I(0, 0) },
605 .collision_tiles
= enemy_collision_tiles_pass_through
,
606 .collision_player
= enemy_collision_player_deadly
,
607 .collision_shots
= enemy_collision_shots_dontcare
,
608 .move_tick
= enemy_tick_stationary
610 .animation_ticks_per_frame
= 18,
611 .animation_length
= ARRAY_SIZE(anim_dog
),
612 .animation_frames
= anim_dog
,
613 .extent
= { FIXED_INT_I(8), FIXED_INT_I(5) },
614 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
615 { FIXED_INT_I(6), FIXED_INT_I(4) } },
616 .spawn_inertia
= { FIXED_POINT_I(0, -200), FIXED_POINT_I(0, 0) },
617 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
618 .collision_player
= enemy_collision_player_jumpable
,
619 .collision_shots
= enemy_collision_shots_die
,
620 .move_tick
= enemy_tick_dog
622 .animation_ticks_per_frame
= 36,
623 .animation_length
= ARRAY_SIZE(anim_giraffe
),
624 .animation_frames
= anim_giraffe
,
625 .extent
= { FIXED_INT_I(7), FIXED_INT_I(10) },
626 .hitbox
= { { FIXED_INT_I(2), FIXED_INT_I(1) },
627 { FIXED_INT_I(4), FIXED_INT_I(9) } },
628 .spawn_inertia
= { FIXED_POINT_I(0, -150), FIXED_POINT_I(-1, -200) },
629 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
630 .collision_player
= enemy_collision_player_jumpable
,
631 .collision_shots
= enemy_collision_shots_bounce
,
632 .move_tick
= enemy_tick_giraffe
634 .animation_ticks_per_frame
= 24,
635 .animation_length
= ARRAY_SIZE(anim_bird
),
636 .animation_frames
= anim_bird
,
637 .extent
= { FIXED_INT_I(9), FIXED_INT_I(7) },
638 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(3) },
639 { FIXED_INT_I(7), FIXED_INT_I(3) } },
640 .spawn_inertia
= { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, -150) },
641 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
642 .collision_player
= enemy_collision_player_jumpable
,
643 .collision_shots
= enemy_collision_shots_die
,
644 .move_tick
= enemy_tick_swing_up_and_down
646 .animation_ticks_per_frame
= 24,
647 .animation_length
= ARRAY_SIZE(anim_bird
),
648 .animation_frames
= anim_bird
,
649 .extent
= { FIXED_INT_I(9), FIXED_INT_I(7) },
650 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(3) },
651 { FIXED_INT_I(7), FIXED_INT_I(3) } },
652 .spawn_inertia
= { FIXED_POINT_I(0, -400), FIXED_INT_I(0) },
653 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
654 .collision_player
= enemy_collision_player_jumpable
,
655 .collision_shots
= enemy_collision_shots_die
,
656 .move_tick
= enemy_tick_fly_straight
658 .animation_ticks_per_frame
= 24,
659 .animation_length
= ARRAY_SIZE(anim_bird
),
660 .animation_frames
= anim_bird
,
661 .extent
= { FIXED_INT_I(9), FIXED_INT_I(7) },
662 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(3) },
663 { FIXED_INT_I(7), FIXED_INT_I(3) } },
664 .spawn_inertia
= { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, 200) },
665 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
666 .collision_player
= enemy_collision_player_jumpable
,
667 .collision_shots
= enemy_collision_shots_die
,
668 .move_tick
= enemy_tick_fly_straight_and_dip