ed32ce1a665af9e1fc8b7cdd4cd16fa50a19026f
[gbajam22] / src / level.h
1 #ifndef LEVEL_H_
2 #define LEVEL_H_
3
4 #include <stdint.h>
5
6 /* cell size in 16.16 fixed point */
7 #define CELL_SIZE       0x20000
8
9 enum { MOBS_DEAD, MOBS_IDLE, MOBS_ENGAGE, MOBS_RUN };
10
11 struct mob {
12         uint8_t type;
13         uint8_t x, y;
14         uint8_t state;
15         struct mob *next;
16         struct mob *cellnext;
17
18         void (*update)(void);
19 };
20
21 struct item {
22         uint8_t type;
23         uint8_t x, y;
24         uint8_t pad;
25         struct item *next;
26         struct item *cellnext;
27 };
28
29 enum { CELL_SOLID, CELL_WALK };
30
31 struct cell {
32         uint8_t type;
33         uint8_t x, y;
34         uint8_t rank;
35         struct mob *mobs;
36         struct item *items;
37 };
38
39 struct level {
40         int width, height;
41         int orgx, orgy;
42         unsigned int xmask;
43         struct cell *cells;
44
45         struct mob *mobs;
46         struct item *items;
47
48         /* populated by calc_vis */
49         struct cell *vis[128];
50         int numvis;
51 };
52
53 struct player;
54
55 struct level *init_level(const char *descstr);
56 void free_level(struct level *lvl);
57
58 void upd_vis(struct level *lvl, struct player *p);
59
60 void cell_to_pos(struct level *lvl, int cx, int cy, int32_t *px, int32_t *py);
61 void pos_to_cell(struct level *lvl, int32_t px, int32_t py, int *cx, int *cy);
62
63 #endif  /* LEVEL_H_ */