1 #ifndef INCLUDED_JUMPNRUN_ENEMIES_H
2 #define INCLUDED_JUMPNRUN_ENEMIES_H
4 #include "../ui/sprite.h"
5 #include "../util/rectangle.h"
10 struct jumpnrun_game_state
;
11 struct jumpnrun_level
;
12 struct jumpnrun_tile_range
;
14 struct jumpnrun_enemy
;
16 typedef struct jumpnrun_enemy_type
{
17 unsigned animation_ticks_per_frame
;
18 size_t animation_length
;
19 badge_sprite
const *animation_frames
;
25 void (*collision_tiles
)(struct jumpnrun_enemy
*self
,
26 vec2d
*desired_position
,
27 struct jumpnrun_level
*lv
,
28 struct jumpnrun_tile_range
const *visible_tiles
);
29 void (*collision_player
)(struct jumpnrun_enemy
*self
,
30 struct jumpnrun_game_state
*state
,
31 vec2d
*player_inertia_mod
);
32 void (*collision_shots
)(struct jumpnrun_enemy
*self
,
33 struct jumpnrun_game_state
*state
);
35 void (*move_tick
)(struct jumpnrun_enemy
*self
,
36 struct jumpnrun_game_state
*state
,
37 struct jumpnrun_level
*lv
,
38 struct jumpnrun_tile_range
const *visible_tiles
,
39 vec2d
*player_inertia_mod
);
40 } jumpnrun_enemy_type
;
42 typedef struct jumpnrun_enemy
{
43 jumpnrun_moveable base
;
47 jumpnrun_enemy_type
const *type
;
51 JUMPNRUN_ENEMY_SPAWNED
= 1,
52 JUMPNRUN_ENEMY_UNAVAILABLE
= 2,
53 JUMPNRUN_ENEMY_FACING_RIGHT
= 4
56 static inline rectangle
const *enemy_box (jumpnrun_enemy
const *enemy
) { return &enemy
->base
.current_box
; }
57 static inline vec2d
enemy_position (jumpnrun_enemy
const *enemy
) { return enemy
->base
.current_box
.pos
; }
58 static inline rectangle
enemy_hitbox (jumpnrun_enemy
const *enemy
) { rectangle r
= enemy
->type
->hitbox
; rectangle_move_rel(&r
, enemy_position(enemy
)); return r
; }
59 static inline badge_sprite
const *enemy_sprite (jumpnrun_enemy
const *enemy
) { return &enemy
->type
->animation_frames
[enemy
->base
.anim_frame
]; }
61 static inline bool enemy_facing_right(jumpnrun_enemy
const *enemy
) { return (enemy
->flags
& JUMPNRUN_ENEMY_FACING_RIGHT
) || fixed_point_gt(enemy
->base
.inertia
.x
, FIXED_INT(0)); }
62 static inline uint8_t enemy_render_flags(jumpnrun_enemy
const *enemy
) { return enemy_facing_right(enemy
) ? BADGE_BLT_MIRRORED
: 0; }
65 JUMPNRUN_ENEMY_TYPE_CAT
,
66 JUMPNRUN_ENEMY_TYPE_MUSHROOM
,
67 JUMPNRUN_ENEMY_TYPE_BUNNY
,
68 JUMPNRUN_ENEMY_TYPE_SNAKE
,
69 JUMPNRUN_ENEMY_TYPE_SPIRAL
,
70 JUMPNRUN_ENEMY_TYPE_ROTOR
,
71 JUMPNRUN_ENEMY_TYPE_DOG
,
72 JUMPNRUN_ENEMY_TYPE_GIRAFFE
,
73 JUMPNRUN_ENEMY_TYPE_BIRD
,
75 JUMPNRUN_ENEMY_TYPE_COUNT
78 extern jumpnrun_enemy_type
const jumpnrun_enemy_type_data
[JUMPNRUN_ENEMY_TYPE_COUNT
];
80 void jumpnrun_process_enemy(jumpnrun_enemy
*self
,
81 badge_framebuffer
*fb
,
82 struct jumpnrun_game_state
*state
,
83 struct jumpnrun_level
*lv
,
84 struct jumpnrun_tile_range
const *visible_tiles
,
85 vec2d
*player_inertia_mod
);