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_lt(rectangle_right(&state
->player
.current_box
), rectangle_left(enemy_box(self
)))) {
284 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
285 } else if(fixed_point_gt(rectangle_left(&state
->player
.current_box
), rectangle_right(enemy_box(self
)))) {
286 self
->base
.inertia
.x
= fixed_point_neg(self
->type
->spawn_inertia
.x
);
289 enemy_animation_advance(self
);
292 void enemy_tick_swing_up_and_down(struct jumpnrun_enemy
*self
,
293 struct jumpnrun_game_state
*state
,
294 struct jumpnrun_level
*lv
,
295 struct jumpnrun_tile_range
const *visible_tiles
,
296 vec2d
*player_inertia_mod
) {
297 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
299 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
300 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
304 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
305 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
306 self
->type
->collision_player(self
, state
, player_inertia_mod
);
307 rectangle_move_to(&self
->base
.current_box
, new_pos
);
309 self
->base
.inertia
.y
=
310 fixed_point_add(fixed_point_add(self
->base
.inertia
.y
,
311 fixed_point_div(self
->type
->spawn_inertia
.y
, FIXED_INT(3))),
312 fixed_point_mul(FIXED_POINT(0, 5),
313 fixed_point_sub(self
->spawn_pos
.y
,
314 enemy_position(self
).y
)));
316 enemy_animation_advance(self
);
319 void enemy_tick_stationary(struct jumpnrun_enemy
*self
,
320 struct jumpnrun_game_state
*state
,
321 struct jumpnrun_level
*lv
,
322 struct jumpnrun_tile_range
const *visible_tiles
,
323 vec2d
*player_inertia_mod
) {
324 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
326 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
327 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
331 self
->type
->collision_tiles(self
, &self
->base
.current_box
.pos
, lv
, visible_tiles
);
332 self
->type
->collision_player(self
, state
, player_inertia_mod
);
334 enemy_animation_advance(self
);
337 void enemy_tick_jumper(jumpnrun_enemy
*self
,
338 jumpnrun_game_state
*state
,
340 jumpnrun_tile_range
const *visible_tiles
,
341 vec2d
*player_inertia_mod
) {
342 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
344 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
345 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
349 jumpnrun_passive_movement(&self
->base
.inertia
);
351 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
352 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
353 self
->type
->collision_player(self
, state
, player_inertia_mod
);
354 rectangle_move_to(&self
->base
.current_box
, new_pos
);
356 if(self
->base
.touching_ground
) {
357 self
->base
.inertia
.y
= self
->type
->spawn_inertia
.y
;
360 enemy_animation_advance(self
);
363 void enemy_tick_dog(jumpnrun_enemy
*self
,
364 jumpnrun_game_state
*state
,
366 jumpnrun_tile_range
const *visible_tiles
,
367 vec2d
*player_inertia_mod
) {
368 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
370 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
371 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
375 jumpnrun_passive_movement(&self
->base
.inertia
);
377 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
378 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
379 self
->type
->collision_player(self
, state
, player_inertia_mod
);
380 rectangle_move_to(&self
->base
.current_box
, new_pos
);
382 if(self
->base
.tick_minor
% self
->type
->animation_ticks_per_frame
== 0) {
383 switch(self
->base
.tick_minor
/ self
->type
->animation_ticks_per_frame
) {
385 self
->base
.tick_minor
= 0;
390 self
->base
.anim_frame
= 0;
391 if(self
->flags
& JUMPNRUN_ENEMY_FACING_RIGHT
) {
392 self
->base
.inertia
.x
= fixed_point_neg(self
->type
->spawn_inertia
.x
);
394 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
403 self
->base
.anim_frame
= 1;
404 if(self
->flags
& JUMPNRUN_ENEMY_FACING_RIGHT
) {
405 self
->base
.inertia
.x
= fixed_point_neg(self
->type
->spawn_inertia
.x
);
407 self
->base
.inertia
.x
= self
->type
->spawn_inertia
.x
;
413 self
->base
.anim_frame
= 2;
414 self
->base
.inertia
.x
= FIXED_INT(0);
419 self
->base
.anim_frame
= 3;
420 self
->base
.inertia
.x
= FIXED_INT(0);
425 ++self
->base
.tick_minor
;
426 if (fixed_point_lt(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
&= ~JUMPNRUN_ENEMY_FACING_RIGHT
; }
427 else if(fixed_point_ne(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
|= JUMPNRUN_ENEMY_FACING_RIGHT
; }
430 void enemy_tick_giraffe(jumpnrun_enemy
*self
,
431 jumpnrun_game_state
*state
,
433 jumpnrun_tile_range
const *visible_tiles
,
434 vec2d
*player_inertia_mod
) {
435 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
437 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
438 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
442 bool was_on_ground
= self
->base
.touching_ground
;
444 jumpnrun_passive_movement(&self
->base
.inertia
);
446 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
447 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
448 self
->type
->collision_player(self
, state
, player_inertia_mod
);
449 rectangle_move_to(&self
->base
.current_box
, new_pos
);
451 if(self
->base
.touching_ground
) {
453 enemy_animation_advance(self
);
454 if(self
->base
.anim_frame
== 0) {
455 self
->base
.inertia
= self
->type
->spawn_inertia
;
457 if(fixed_point_gt(rectangle_mid_x(&state
->player
.current_box
), rectangle_mid_x(enemy_box(self
)))) {
458 self
->base
.inertia
.x
= fixed_point_neg(self
->base
.inertia
.x
);
462 self
->base
.tick_minor
= 0;
463 self
->base
.anim_frame
= 3;
464 self
->base
.inertia
.x
= FIXED_INT(0);
466 } else if(was_on_ground
) {
467 self
->base
.tick_minor
= 0;
468 self
->base
.anim_frame
= 1;
469 } else if(self
->base
.anim_frame
== 1) {
470 enemy_animation_advance(self
);
473 ++self
->base
.tick_minor
;
474 if (fixed_point_lt(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
&= ~JUMPNRUN_ENEMY_FACING_RIGHT
; }
475 else if(fixed_point_ne(self
->base
.inertia
.x
, FIXED_INT(0))) { self
->flags
|= JUMPNRUN_ENEMY_FACING_RIGHT
; }
478 void enemy_tick_fly_straight(struct jumpnrun_enemy
*self
,
479 struct jumpnrun_game_state
*state
,
480 struct jumpnrun_level
*lv
,
481 struct jumpnrun_tile_range
const *visible_tiles
,
482 vec2d
*player_inertia_mod
) {
483 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
485 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
486 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
490 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);
491 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
492 self
->type
->collision_player(self
, state
, player_inertia_mod
);
493 rectangle_move_to(&self
->base
.current_box
, new_pos
);
495 enemy_animation_advance(self
);
498 void enemy_tick_fly_straight_and_dip(struct jumpnrun_enemy
*self
,
499 struct jumpnrun_game_state
*state
,
500 struct jumpnrun_level
*lv
,
501 struct jumpnrun_tile_range
const *visible_tiles
,
502 vec2d
*player_inertia_mod
) {
503 int screenpos
= fixed_point_cast_int(rectangle_left(&self
->base
.current_box
));
505 if(screenpos
+ JUMPNRUN_MAX_SPAWN_MARGIN
< state
->left
||
506 screenpos
>= state
->left
+ BADGE_DISPLAY_WIDTH
+ JUMPNRUN_MAX_SPAWN_MARGIN
) {
510 if(fixed_point_lt(fixed_point_abs(fixed_point_sub(enemy_position(self
).x
,
511 state
->player
.current_box
.pos
.x
)),
513 self
->flags
|= JUMPNRUN_ENEMY_EVENT_TRIGGER1
;
516 if(self
->flags
& JUMPNRUN_ENEMY_EVENT_TRIGGER1
) {
517 self
->base
.inertia
.y
=
518 fixed_point_add(fixed_point_add(self
->base
.inertia
.y
,
519 fixed_point_div(self
->type
->spawn_inertia
.y
, FIXED_INT(3))),
520 fixed_point_mul(FIXED_POINT(0, 5),
521 fixed_point_sub(self
->spawn_pos
.y
,
522 enemy_position(self
).y
)));
524 self
->base
.inertia
.y
= FIXED_INT(0);
527 vec2d new_pos
= vec2d_add(enemy_position(self
), self
->base
.inertia
);;
528 self
->type
->collision_tiles(self
, &new_pos
, lv
, visible_tiles
);
529 self
->type
->collision_player(self
, state
, player_inertia_mod
);
530 rectangle_move_to(&self
->base
.current_box
, new_pos
);
532 enemy_animation_advance(self
);
535 jumpnrun_enemy_type
const jumpnrun_enemy_type_data
[JUMPNRUN_ENEMY_TYPE_COUNT
] = {
537 .animation_ticks_per_frame
= 18,
538 .animation_length
= ARRAY_SIZE(anim_cat
),
539 .animation_frames
= anim_cat
,
540 .extent
= { FIXED_INT_I(8), FIXED_INT_I(5) },
541 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(2) },
542 { FIXED_INT_I(6), FIXED_INT_I(3) } },
543 .spawn_inertia
= { FIXED_POINT_I(0, -200), FIXED_INT_I(0) },
544 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
545 .collision_player
= enemy_collision_player_jumpable
,
546 .collision_shots
= enemy_collision_shots_die
,
547 .move_tick
= enemy_tick_straight_ahead
549 .animation_ticks_per_frame
= 12,
550 .animation_length
= ARRAY_SIZE(anim_mushroom
),
551 .animation_frames
= anim_mushroom
,
552 .extent
= { FIXED_INT_I(7), FIXED_INT_I(7) },
553 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
554 { FIXED_INT_I(5), FIXED_INT_I(4) } },
555 .spawn_inertia
= { FIXED_POINT_I(0, -80), FIXED_INT_I(0) },
556 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
557 .collision_player
= enemy_collision_player_jumpable
,
558 .collision_shots
= enemy_collision_shots_die
,
559 .move_tick
= enemy_tick_straight_follow
561 .animation_ticks_per_frame
= 9,
562 .animation_length
= ARRAY_SIZE(anim_bunny
),
563 .animation_frames
= anim_bunny
,
564 .extent
= { FIXED_INT_I(7), FIXED_INT_I(5) },
565 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(2) },
566 { FIXED_INT_I(5), FIXED_INT_I(3) } },
567 .spawn_inertia
= { FIXED_POINT_I(0, -80), FIXED_POINT_I(0, -800) },
568 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
569 .collision_player
= enemy_collision_player_jumpable
,
570 .collision_shots
= enemy_collision_shots_die
,
571 .move_tick
= enemy_tick_jumper
573 .animation_ticks_per_frame
= 6,
574 .animation_length
= ARRAY_SIZE(anim_snake
),
575 .animation_frames
= anim_snake
,
576 .extent
= { FIXED_INT_I(10), FIXED_INT_I(6) },
577 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(4) },
578 { FIXED_INT_I(8), FIXED_INT_I(2) } },
579 .spawn_inertia
= { FIXED_POINT_I(0, -150), FIXED_INT_I(0) },
580 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
581 .collision_player
= enemy_collision_player_jumpable
,
582 .collision_shots
= enemy_collision_shots_die
,
583 .move_tick
= enemy_tick_straight_ahead
585 .animation_ticks_per_frame
= 6,
586 .animation_length
= ARRAY_SIZE(anim_spiral
),
587 .animation_frames
= anim_spiral
,
588 .extent
= { FIXED_INT_I(10), FIXED_INT_I(10) },
589 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
590 { FIXED_INT_I(8), FIXED_INT_I(8) } },
591 .spawn_inertia
= { FIXED_INT_I(0), FIXED_POINT_I(0, -200) },
592 .collision_tiles
= enemy_collision_tiles_pass_through
,
593 .collision_player
= enemy_collision_player_deadly
,
594 .collision_shots
= enemy_collision_shots_dontcare
,
595 .move_tick
= enemy_tick_swing_up_and_down
597 .animation_ticks_per_frame
= 5,
598 .animation_length
= ARRAY_SIZE(anim_rotor
),
599 .animation_frames
= anim_rotor
,
600 .extent
= { FIXED_INT_I(9), FIXED_INT_I(9) },
601 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
602 { FIXED_INT_I(7), FIXED_INT_I(7) } },
603 .spawn_inertia
= { FIXED_INT_I(0), FIXED_POINT_I(0, 0) },
604 .collision_tiles
= enemy_collision_tiles_pass_through
,
605 .collision_player
= enemy_collision_player_deadly
,
606 .collision_shots
= enemy_collision_shots_dontcare
,
607 .move_tick
= enemy_tick_stationary
609 .animation_ticks_per_frame
= 18,
610 .animation_length
= ARRAY_SIZE(anim_dog
),
611 .animation_frames
= anim_dog
,
612 .extent
= { FIXED_INT_I(8), FIXED_INT_I(5) },
613 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(1) },
614 { FIXED_INT_I(6), FIXED_INT_I(4) } },
615 .spawn_inertia
= { FIXED_POINT_I(0, -200), FIXED_POINT_I(0, 0) },
616 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
617 .collision_player
= enemy_collision_player_jumpable
,
618 .collision_shots
= enemy_collision_shots_die
,
619 .move_tick
= enemy_tick_dog
621 .animation_ticks_per_frame
= 36,
622 .animation_length
= ARRAY_SIZE(anim_giraffe
),
623 .animation_frames
= anim_giraffe
,
624 .extent
= { FIXED_INT_I(7), FIXED_INT_I(10) },
625 .hitbox
= { { FIXED_INT_I(2), FIXED_INT_I(1) },
626 { FIXED_INT_I(4), FIXED_INT_I(9) } },
627 .spawn_inertia
= { FIXED_POINT_I(0, -150), FIXED_POINT_I(-1, -200) },
628 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
629 .collision_player
= enemy_collision_player_jumpable
,
630 .collision_shots
= enemy_collision_shots_bounce
,
631 .move_tick
= enemy_tick_giraffe
633 .animation_ticks_per_frame
= 24,
634 .animation_length
= ARRAY_SIZE(anim_bird
),
635 .animation_frames
= anim_bird
,
636 .extent
= { FIXED_INT_I(9), FIXED_INT_I(7) },
637 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(3) },
638 { FIXED_INT_I(7), FIXED_INT_I(3) } },
639 .spawn_inertia
= { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, -150) },
640 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
641 .collision_player
= enemy_collision_player_jumpable
,
642 .collision_shots
= enemy_collision_shots_die
,
643 .move_tick
= enemy_tick_swing_up_and_down
645 .animation_ticks_per_frame
= 24,
646 .animation_length
= ARRAY_SIZE(anim_bird
),
647 .animation_frames
= anim_bird
,
648 .extent
= { FIXED_INT_I(9), FIXED_INT_I(7) },
649 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(3) },
650 { FIXED_INT_I(7), FIXED_INT_I(3) } },
651 .spawn_inertia
= { FIXED_POINT_I(0, -400), FIXED_INT_I(0) },
652 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
653 .collision_player
= enemy_collision_player_jumpable
,
654 .collision_shots
= enemy_collision_shots_die
,
655 .move_tick
= enemy_tick_fly_straight
657 .animation_ticks_per_frame
= 24,
658 .animation_length
= ARRAY_SIZE(anim_bird
),
659 .animation_frames
= anim_bird
,
660 .extent
= { FIXED_INT_I(9), FIXED_INT_I(7) },
661 .hitbox
= { { FIXED_INT_I(1), FIXED_INT_I(3) },
662 { FIXED_INT_I(7), FIXED_INT_I(3) } },
663 .spawn_inertia
= { FIXED_POINT_I(0, -400), FIXED_POINT_I(0, 200) },
664 .collision_tiles
= enemy_collision_tiles_bounce_horiz
,
665 .collision_player
= enemy_collision_player_jumpable
,
666 .collision_shots
= enemy_collision_shots_die
,
667 .move_tick
= enemy_tick_fly_straight_and_dip