starting to separate platform-specific code to facilitate a PC build
[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         int xshift;
44         struct cell *cells;
45
46         struct mob *mobs;
47         struct item *items;
48
49         /* populated by calc_vis */
50         struct cell *vis[128];
51         int numvis;
52 };
53
54 struct player;
55
56 struct level *init_level(const char *descstr);
57 void free_level(struct level *lvl);
58
59 struct cell *level_cell(struct level *lvl, int cx, int cy);
60
61 void upd_vis(struct level *lvl, struct player *p);
62
63 void cell_to_pos(struct level *lvl, int cx, int cy, int32_t *px, int32_t *py);
64 void pos_to_cell(struct level *lvl, int32_t px, int32_t py, int *cx, int *cy);
65
66 #endif  /* LEVEL_H_ */