]> git.lizzy.rs Git - dungeon_game.git/blob - plugins/game/game.h
d5457a9eb9e7973e50cfcd6a13267817c5ebed53
[dungeon_game.git] / plugins / game / game.h
1 #ifndef _GAME_H_
2 #define _GAME_H_
3
4 #include <stdbool.h>
5 #define MAP_HEIGHT 1000
6 #define MAP_WIDTH 1000
7 #define LIGHT 10
8
9 /* Type definitions */
10
11 struct color
12 {
13         unsigned char r, g, b;
14 };
15
16 struct material
17 {
18         bool solid;
19         struct color color;
20 };
21
22 struct node
23 {
24         struct material *material;
25 };
26
27 struct entity_step_data
28 {
29         double dtime;
30         int dx;
31         int dy;
32         bool visible;
33 };
34
35 struct entity
36 {
37         const char *name;
38         int x, y;
39         struct color color;
40         const char *texture;
41         bool remove;
42         void *meta;
43         int health;
44         int max_health;
45         bool collide_with_entities;
46
47         void (*on_step)(struct entity *self, struct entity_step_data stepdata);
48         void (*on_collide)(struct entity *self, int x, int y);
49         void (*on_collide_with_entity)(struct entity *self, struct entity *other);
50         void (*on_spawn)(struct entity *self);
51         void (*on_remove)(struct entity *self);
52         void (*on_death)(struct entity *self);
53         void (*on_damage)(struct entity *self, int damage);
54 };
55
56 struct list
57 {
58         void *element;
59         struct list *next;
60 };
61
62 typedef struct entity *render_entity_list[LIGHT * 2 + 1][LIGHT * 2 + 1];
63
64 struct generator_function
65 {
66         int chance;
67         void (*callback)(int x, int y);
68 };
69
70 extern int score;
71
72 extern struct color black;
73
74 extern struct material wall;
75 extern struct material air;
76 extern struct material outside;
77
78 extern struct node map[MAP_WIDTH][MAP_HEIGHT];
79
80 extern struct entity player;
81 extern struct list *entities;
82
83 extern struct entity *entity_collision_map[MAP_WIDTH][MAP_HEIGHT];
84
85 extern struct list *air_functions;
86
87 void quit();
88 struct color get_color(const char *str);
89 bool is_outside(int x, int y);
90 struct node get_node(int x, int y);
91 bool is_solid(int x, int y);
92 bool move(struct entity *entity, int xoff, int yoff);
93 void spawn(struct entity def, int x, int y);
94 void add_health(struct entity *entity, int health);
95 void add_score(int s);
96 bool player_dead();
97 void set_color(struct color color, bool bg);
98 void light_color(struct color *color, double light);
99 void mix_color(struct color *color, struct color other, double ratio);
100 void register_air_function(struct generator_function func);
101 struct list *add_element(struct list *list, void *element);
102
103 #endif