]> git.lizzy.rs Git - dungeon_game.git/blob - plugins/game/game.h
Modularize rendering
[dungeon_game.git] / plugins / game / game.h
1 #ifndef _GAME_H_
2 #define _GAME_H_
3
4 #include <stdbool.h>
5 #include <sys/ioctl.h>
6 #define MAP_HEIGHT 1000
7 #define MAP_WIDTH 1000
8 #define LIGHT 10
9
10 /* Type definitions */
11
12 struct color
13 {
14         unsigned char r, g, b;
15 };
16
17 struct material
18 {
19         bool solid;
20         struct color color;
21 };
22
23 struct node
24 {
25         struct material *material;
26 };
27
28 struct entity_step_data
29 {
30         double dtime;
31         int dx;
32         int dy;
33         bool visible;
34 };
35
36 struct entity
37 {
38         const char *name;
39         int x, y;
40         struct color color;
41         const char *texture;
42         bool remove;
43         void *meta;
44         int health;
45         int max_health;
46         bool collide_with_entities;
47
48         void (*on_step)(struct entity *self, struct entity_step_data stepdata);
49         void (*on_collide)(struct entity *self, int x, int y);
50         void (*on_collide_with_entity)(struct entity *self, struct entity *other);
51         void (*on_spawn)(struct entity *self, void *data);
52         void (*on_remove)(struct entity *self);
53         void (*on_death)(struct entity *self);
54         void (*on_damage)(struct entity *self, int damage);
55 };
56
57 struct list
58 {
59         void *element;
60         struct list *next;
61 };
62
63 struct generator_function
64 {
65         int chance;
66         void (*callback)(int x, int y);
67 };
68
69 struct input_handler
70 {
71         bool run_if_dead;
72         void (*callback)();
73 };
74
75 enum direction
76 {
77         UP,
78         LEFT,
79         DOWN,
80         RIGHT,
81 };
82
83 extern struct color black;
84
85 extern struct material wall;
86 extern struct material air;
87 extern struct material outside;
88
89 extern struct node map[MAP_WIDTH][MAP_HEIGHT];
90
91 extern struct entity player;
92 extern struct list *entities;
93
94 extern struct entity *entity_collision_map[MAP_WIDTH][MAP_HEIGHT];
95
96 struct color get_color(const char *str);
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 dir_to_xy(enum direction dir, int *x, int *y);
101 struct list *add_element(struct list *list, void *element);
102 int clamp(int v, int max, int min);
103 int max(int a, int b);
104 int min(int a, int b);
105
106 void quit();
107 bool player_dead();
108
109 struct node get_node(int x, int y);
110 bool is_outside(int x, int y);
111 bool is_solid(int x, int y);
112
113 bool spawn(struct entity def, int x, int y, void *data);
114 bool move(struct entity *entity, int xoff, int yoff);
115 void add_health(struct entity *entity, int health);
116
117 void register_air_function(struct generator_function arg);
118 void register_input_handler(unsigned char c, struct input_handler arg);
119 void register_render_component(void (*arg)(struct winsize ws));
120
121 #endif