CLKDIV-Durchlauf für Sync zum Messen.
[hackover2013-badge-firmware.git] / badge / jumpnrun / enemies.h
1 #ifndef INCLUDED_JUMPNRUN_ENEMIES_H
2 #define INCLUDED_JUMPNRUN_ENEMIES_H
3
4 #include "../ui/sprite.h"
5 #include "../util/rectangle.h"
6
7 #include "tiles.h"
8
9 struct jumpnrun_game_state;
10 struct jumpnrun_level;
11 struct jumpnrun_tile_range;
12
13 struct jumpnrun_enemy;
14
15 typedef struct jumpnrun_enemy_type {
16 unsigned animation_ticks_per_frame;
17 size_t animation_length;
18 badge_sprite const *animation_frames;
19
20 vec2d spawn_inertia;
21
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;
33
34 typedef struct jumpnrun_enemy {
35 vec2d spawn_pos;
36 vec2d current_pos;
37 vec2d inertia;
38 unsigned flags;
39 unsigned tick_counter;
40 unsigned current_frame;
41
42 jumpnrun_enemy_type const *type;
43 } jumpnrun_enemy;
44
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) } };
48 return r;
49 }
50
51 enum {
52 JUMPNRUN_ENEMY_SPAWNED = 1,
53 JUMPNRUN_ENEMY_UNAVAILABLE = 2
54 };
55
56 enum {
57 JUMPNRUN_ENEMY_TYPE_CAT,
58 JUMPNRUN_ENEMY_TYPE_MUSHROOM,
59
60 JUMPNRUN_ENEMY_TYPE_COUNT
61 };
62
63 extern jumpnrun_enemy_type const jumpnrun_enemy_type_data[JUMPNRUN_ENEMY_TYPE_COUNT];
64
65 void jumpnrun_process_enemy(jumpnrun_enemy *self,
66 badge_framebuffer *fb,
67 struct jumpnrun_game_state *state,
68 struct jumpnrun_level *lv,
69 struct jumpnrun_tile_range const *visible_tiles);
70 #endif
This page took 0.049558 seconds and 5 git commands to generate.