#define _GAME_H_
#include <stdbool.h>
+#include <sys/ioctl.h>
+#include <stddef.h>
+#include <time.h>
#define MAP_HEIGHT 1000
#define MAP_WIDTH 1000
#define LIGHT 10
struct entity
{
- const char *name;
+ char *name;
int x, y;
struct color color;
- const char *texture;
+ bool use_color;
+ char *texture;
bool remove;
void *meta;
int health;
void (*on_step)(struct entity *self, struct entity_step_data stepdata);
void (*on_collide)(struct entity *self, int x, int y);
void (*on_collide_with_entity)(struct entity *self, struct entity *other);
- void (*on_spawn)(struct entity *self);
+ void (*on_spawn)(struct entity *self, void *data);
void (*on_remove)(struct entity *self);
void (*on_death)(struct entity *self);
void (*on_damage)(struct entity *self, int damage);
struct list *next;
};
-typedef struct entity *render_entity_list[LIGHT * 2 + 1][LIGHT * 2 + 1];
-
struct generator_function
{
int chance;
void (*callback)(int x, int y);
};
-extern int score;
+struct input_handler
+{
+ bool run_if_dead;
+ void (*callback)();
+};
+
+struct globalstep
+{
+ bool run_if_dead;
+ void (*callback)(double dtime);
+};
+
+enum direction
+{
+ UP,
+ LEFT,
+ DOWN,
+ RIGHT,
+};
extern struct color black;
extern struct entity *entity_collision_map[MAP_WIDTH][MAP_HEIGHT];
-extern struct list *air_functions;
+struct color get_color(const char *str);
+void set_color(struct color color, bool bg);
+void light_color(struct color *color, double light);
+void mix_color(struct color *color, struct color other, double ratio);
+void dir_to_xy(enum direction dir, int *x, int *y);
+struct list *add_element(struct list *list, void *element);
+int clamp(int v, int max, int min);
+int max(int a, int b);
+int min(int a, int b);
+void *make_buffer(void *ptr, size_t size);
+double calculate_dtime(struct timespec from, struct timespec to);
+void get_roman_numeral(int number, char **ptr, size_t *len);
void quit();
-struct color get_color(const char *str);
-bool is_outside(int x, int y);
+bool player_dead();
+
struct node get_node(int x, int y);
+bool is_outside(int x, int y);
bool is_solid(int x, int y);
+
+bool spawn(struct entity def, int x, int y, void *data);
bool move(struct entity *entity, int xoff, int yoff);
-void spawn(struct entity def, int x, int y);
void add_health(struct entity *entity, int health);
-void add_score(int s);
-bool player_dead();
-void set_color(struct color color, bool bg);
-void light_color(struct color *color, double light);
-void mix_color(struct color *color, struct color other, double ratio);
+
void register_air_function(struct generator_function func);
-struct list *add_element(struct list *list, void *element);
+void register_input_handler(unsigned char c, struct input_handler handler);
+void register_render_component(void (*callback)(struct winsize ws));
+void register_globalstep(struct globalstep step);
#endif