1 #ifndef INCLUDED_JUMPNRUN_ENEMIES_H
2 #define INCLUDED_JUMPNRUN_ENEMIES_H
4 #include <badge/ui/sprite.h>
5 #include <badge/util/rectangle.h>
9 struct jumpnrun_game_state
;
10 struct jumpnrun_level
;
11 struct jumpnrun_tile_range
;
13 struct jumpnrun_enemy
;
15 typedef struct jumpnrun_enemy_type
{
16 unsigned animation_ticks_per_frame
;
17 size_t animation_length
;
18 badge_sprite
const *animation_frames
;
22 void (*collision_tiles
)(struct jumpnrun_enemy
*self
,
23 vec2d
*desired_position
,
24 struct jumpnrun_level
*lv
,
25 struct jumpnrun_tile_range
const *visible_tiles
);
26 void (*collision_player
)(struct jumpnrun_enemy
*self
,
27 struct jumpnrun_game_state
*state
);
28 void (*game_tick
)(struct jumpnrun_enemy
*self
,
29 struct jumpnrun_game_state
*state
,
30 struct jumpnrun_level
*lv
,
31 struct jumpnrun_tile_range
const *visible_tiles
);
32 } jumpnrun_enemy_type
;
34 typedef struct jumpnrun_enemy
{
39 unsigned tick_counter
;
40 unsigned current_frame
;
42 jumpnrun_enemy_type
const *type
;
45 static inline rectangle
rect_from_enemy(jumpnrun_enemy
const *enemy
) {
46 badge_sprite
const *cur_sprite
= &enemy
->type
->animation_frames
[(enemy
->tick_counter
/ enemy
->type
->animation_ticks_per_frame
) % enemy
->type
->animation_length
];
47 rectangle r
= { enemy
->current_pos
, { FIXED_POINT(cur_sprite
->width
, 0), FIXED_POINT(cur_sprite
->height
, 0) } };
52 JUMPNRUN_ENEMY_SPAWNED
= 1,
53 JUMPNRUN_ENEMY_UNAVAILABLE
= 2
57 JUMPNRUN_ENEMY_TYPE_CAT
,
59 JUMPNRUN_ENEMY_TYPE_COUNT
62 extern jumpnrun_enemy_type
const jumpnrun_enemy_type_data
[JUMPNRUN_ENEMY_TYPE_COUNT
];
64 void jumpnrun_process_enemy(jumpnrun_enemy
*self
,
65 badge_framebuffer
*fb
,
66 struct jumpnrun_game_state
*state
,
67 struct jumpnrun_level
*lv
,
68 struct jumpnrun_tile_range
const *visible_tiles
);