home · contact · privacy
1c3475f61c6862d1640a137f4bd58101a2f91ba4
[plomrogue] / src / map.h
1 /* map.h
2  *
3  * Struct for the game map and routines to manipulate it.
4  */
5
6 #ifndef MAP_H
7 #define MAP_H
8
9
10
11 #include "yx_uint16.h" /* for yx_uint16 and dir enums */
12 struct Player;
13
14
15
16 struct Map
17 {
18     struct yx_uint16 size;   /* map's height/width in number of cells */
19     struct yx_uint16 offset; /* the map scroll offset */
20     char * cells;            /* sequence of bytes encoding map cells */
21 };
22
23
24
25 /* Initialize an island map as 64 x 64 cells of "~" cells representing water and
26  * "." cells representing land. The shape of the island is generated randomly by
27  * starting with a sea containing one land cell in the middle and then going
28  * into a cycle of repeatedly selecting a random cell on the map and
29  * transforming it into a land cell if it is horizontally or vertically neighbor
30  * to one. The cycle ends when a land cell is created that is only one cell away
31  * from the edge of the map. The map scroll offset is initialized to 0,0.
32  */
33 extern struct Map init_map();
34
35 /* Scroll map into direction "dir" by changing the scroll offset if that does
36  * not push the map view beyond the size of the map window as described by
37  * "win_size".
38  */
39 extern void map_scroll(struct Map * map, enum dir d, struct yx_uint16 win_size);
40
41 /* Scroll map to center on the player by changing the scroll offset following
42  * (and constrained by) the window size as described by "win_size".
43  */
44 extern void map_center_player(struct Map * map, struct Player * player,
45                               struct yx_uint16 win_size);
46
47
48
49 #endif