-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.h
207 lines (175 loc) · 5.05 KB
/
map.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//=================================================================
// The map header file.
//
// Copyright 2023 Georgia Tech. All rights reserved.
// The materials provided by the instructor in this course are for
// the use of the students currently enrolled in the course.
// Copyrighted course materials may not be further disseminated.
// This file must NOT be made publicly available anywhere.
//==================================================================
#ifndef MAP_H
#define MAP_H
#include "hash_table.h"
/**
* A structure to represent the map. The implementation is private.
*/
struct Map;
// A function pointer type for drawing MapItems.
// All tiles are 11x11 blocks.
// u,v is the top left corner pixel of the block
typedef void (*DrawFunc)(int u, int v);
/**
* The data for elements in the map. Each item in the map HashTable is a
* MapItem.
*/
typedef struct {
/**
* Indicates the "type" of the MapItem: WALL, DOOR, PLANT, etc. This is
* useful for determining how to interact with the object when updating the
* game state.
*/
int type;
/**
* A function pointer to the drawing function for this item. Used by draw_game.
*/
DrawFunc draw;
/**
* If zero, this item should block character motion.
*/
int walkable;
/**
* Arbitrary extra data for the MapItem. Could be useful for keeping up with
* special information, like where a set of stairs should take the player.
*
* Iterpretation of this can depend on the type of the MapItem. For example,
* a WALL probably doesn't need to use this (it can be NULL), where an NPC
* might use it to store game state (have I given the player the key yet?).
*/
void* data;
} MapItem;
typedef struct {
int tm;
int tx, ty;
} StairsData;
typedef struct {
} CaveData;
// MapItem types
// Define more of these!
#define WALL 0
#define DOOR 1
#define PLANT 2
#define WATER 3
#define KEY 4
#define CHEST 5
#define NPC 6
#define CLEAR 7
#define STAIRS 8
#define CAVE 9
#define MUD 10
#define FIRE 11
#define EARTH 12
#define BUZZ 13
#define WHITE_BLOCK 14
#define SPIKES 15
#define FIRE_HEALTH 16
#define BIG_TREE 17
#define FIRE_BUZZ 18
/**
* Initializes the internal structures for all maps. This does not populate
* the map with items, but allocates space for them, initializes the hash tables,
* and sets the width and height.
*/
void maps_init();
/**
* Returns a pointer to the active map.
*/
Map* get_active_map();
/**
* Sets the active map to map m, where m is the index of the map to activate.
* Returns a pointer to the new active map.
*/
Map* set_active_map(int m);
/**
* Returns the map m, regardless of whether it is the active map. This function
* does not change the active map.
*/
Map* get_map(int m);
/**
* Print the active map to the serial console.
*/
void print_map();
// Access
/**
* Returns the width of the active map.
*/
int map_width();
/**
* Returns the heigh of the active map.
*/
int map_height();
/**
* Returns the total number of cells in the active map.
*/
int map_area();
/**
* Returns the MapItem immediately above the given location.
*/
MapItem* get_north(int x, int y);
/**
* Returns the MapItem immediately below the given location.
*/
MapItem* get_south(int x, int y);
/**
* Returns the MapItem immediately to the right of the given location.
*/
MapItem* get_east(int x, int y);
/**
* Returns the MapItem immediately to the left of the given location.
*/
MapItem* get_west(int x, int y);
/**
* Returns the MapItem at the given location.
*/
MapItem* get_here(int x, int y);
// Directions, for using the modification functions
#define HORIZONTAL 0
#define VERTICAL 1
/**
* If there is a MapItem at (x,y), remove it from the map.
*/
void map_erase(int x, int y);
/**
* Add WALL items in a line of length len beginning at (x,y).
* If dir == HORIZONTAL, the line is in the direction of increasing x.
* If dir == VERTICAL, the line is in the direction of increasing y.
*
* If there are already items in the map that collide with this line, they are
* erased.
*/
void add_wall(int x, int y, int dir, int len);
/**
* Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it
* before adding the plant.
*/
void add_plant(int x, int y);
void add_door(int x, int y, int tm, int tx, int ty, int dir, int len);
void add_npc(int x, int y);
void add_stairs(int x, int y, int tm, int tx, int ty);
void add_cave(int x, int y, int n,int tm, int tx, int ty);
void add_mud(int x, int y, int dir, int len);
void add_water(int x, int y);
void add_fire(int x, int y, int type);
void add_earth(int x, int y, int dir, int len);
void add_buzz(int x, int y);
void add_slain_buzz(int x, int y);
void add_white_block(int x, int y);
void add_chest(int x, int y);
void add_spikes(int x, int y);
void add_big_tree(int x, int y);
void add_big_tree1(int x, int y);
void add_big_tree2(int x, int y);
void add_big_tree3(int x, int y);
void add_big_tree4(int x, int y);
void add_fire_buzz(int x, int y);
int get_active_map_index();
#endif //MAP_H