Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
map.h@14:7225da81314a, 2021-12-03 (annotated)
- Committer:
- nasiromar
- Date:
- Fri Dec 03 08:45:49 2021 +0000
- Revision:
- 14:7225da81314a
- Parent:
- 13:798a4dd14c7e
- Child:
- 16:06a88c0110ff
NasLand Almost Done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:35660d7952f7 | 1 | #ifndef MAP_H |
rconnorlawson | 0:35660d7952f7 | 2 | #define MAP_H |
rconnorlawson | 0:35660d7952f7 | 3 | |
rconnorlawson | 0:35660d7952f7 | 4 | #include "hash_table.h" |
rconnorlawson | 0:35660d7952f7 | 5 | |
rconnorlawson | 0:35660d7952f7 | 6 | /** |
rconnorlawson | 0:35660d7952f7 | 7 | * A structure to represent the map. The implementation is private. |
rconnorlawson | 0:35660d7952f7 | 8 | */ |
rconnorlawson | 0:35660d7952f7 | 9 | struct Map; |
rconnorlawson | 0:35660d7952f7 | 10 | |
rconnorlawson | 0:35660d7952f7 | 11 | // A function pointer type for drawing MapItems. |
rconnorlawson | 0:35660d7952f7 | 12 | // All tiles are 11x11 blocks. |
rconnorlawson | 0:35660d7952f7 | 13 | // u,v is the top left corner pixel of the block |
rconnorlawson | 0:35660d7952f7 | 14 | typedef void (*DrawFunc)(int u, int v); |
rconnorlawson | 0:35660d7952f7 | 15 | |
rconnorlawson | 0:35660d7952f7 | 16 | /** |
rconnorlawson | 0:35660d7952f7 | 17 | * The data for elements in the map. Each item in the map HashTable is a |
rconnorlawson | 0:35660d7952f7 | 18 | * MapItem. |
rconnorlawson | 0:35660d7952f7 | 19 | */ |
rconnorlawson | 0:35660d7952f7 | 20 | typedef struct { |
rconnorlawson | 0:35660d7952f7 | 21 | /** |
rconnorlawson | 0:35660d7952f7 | 22 | * Indicates the "type" of the MapItem: WALL, DOOR, PLANT, etc. This is |
rconnorlawson | 0:35660d7952f7 | 23 | * useful for determining how to interact with the object when updating the |
rconnorlawson | 0:35660d7952f7 | 24 | * game state. |
rconnorlawson | 0:35660d7952f7 | 25 | */ |
rconnorlawson | 0:35660d7952f7 | 26 | int type; |
rconnorlawson | 0:35660d7952f7 | 27 | |
rconnorlawson | 0:35660d7952f7 | 28 | /** |
rconnorlawson | 0:35660d7952f7 | 29 | * A function pointer to the drawing function for this item. Used by draw_game. |
rconnorlawson | 0:35660d7952f7 | 30 | */ |
rconnorlawson | 0:35660d7952f7 | 31 | DrawFunc draw; |
rconnorlawson | 0:35660d7952f7 | 32 | |
rconnorlawson | 0:35660d7952f7 | 33 | /** |
rconnorlawson | 0:35660d7952f7 | 34 | * If zero, this item should block character motion. |
rconnorlawson | 0:35660d7952f7 | 35 | */ |
rconnorlawson | 0:35660d7952f7 | 36 | int walkable; |
rconnorlawson | 0:35660d7952f7 | 37 | |
rconnorlawson | 0:35660d7952f7 | 38 | /** |
rconnorlawson | 0:35660d7952f7 | 39 | * Arbitrary extra data for the MapItem. Could be useful for keeping up with |
rconnorlawson | 0:35660d7952f7 | 40 | * special information, like where a set of stairs should take the player. |
rconnorlawson | 0:35660d7952f7 | 41 | * |
rconnorlawson | 0:35660d7952f7 | 42 | * Iterpretation of this can depend on the type of the MapItem. For example, |
rconnorlawson | 0:35660d7952f7 | 43 | * a WALL probably doesn't need to use this (it can be NULL), where an NPC |
rconnorlawson | 0:35660d7952f7 | 44 | * might use it to store game state (have I given the player the key yet?). |
rconnorlawson | 0:35660d7952f7 | 45 | */ |
nasiromar | 9:cbb9cfb1f6c5 | 46 | int data; |
rconnorlawson | 0:35660d7952f7 | 47 | } MapItem; |
rconnorlawson | 0:35660d7952f7 | 48 | |
rconnorlawson | 0:35660d7952f7 | 49 | typedef struct { |
rconnorlawson | 0:35660d7952f7 | 50 | int tm; |
rconnorlawson | 0:35660d7952f7 | 51 | int tx, ty; |
rconnorlawson | 0:35660d7952f7 | 52 | } StairsData; |
rconnorlawson | 0:35660d7952f7 | 53 | |
rconnorlawson | 0:35660d7952f7 | 54 | // MapItem types |
rconnorlawson | 0:35660d7952f7 | 55 | // Define more of these! |
rconnorlawson | 0:35660d7952f7 | 56 | #define WALL 0 |
rconnorlawson | 0:35660d7952f7 | 57 | #define PLANT 1 |
nasiromar | 6:c9695079521d | 58 | #define NPC 2 |
nasiromar | 6:c9695079521d | 59 | #define CHEST 3 |
nasiromar | 14:7225da81314a | 60 | #define CHESTT 16 |
nasiromar | 6:c9695079521d | 61 | #define CASTL 4 |
nasiromar | 6:c9695079521d | 62 | #define PORTAL 5 |
nasiromar | 7:862062ffca62 | 63 | #define DOOR 6 |
nasiromar | 7:862062ffca62 | 64 | #define DRAGON 7 |
nasiromar | 7:862062ffca62 | 65 | #define PORTAl 8 |
nasiromar | 7:862062ffca62 | 66 | #define KINDOM 9 |
nasiromar | 9:cbb9cfb1f6c5 | 67 | #define FRUIT 10 |
nasiromar | 11:6cd02a8539d1 | 68 | #define VILL 11 |
nasiromar | 11:6cd02a8539d1 | 69 | #define NPCT 12 |
nasiromar | 13:798a4dd14c7e | 70 | #define ENEMY1 13 |
nasiromar | 13:798a4dd14c7e | 71 | #define ENEMY2 14 |
nasiromar | 13:798a4dd14c7e | 72 | #define ENEMY 15 |
nasiromar | 6:c9695079521d | 73 | |
nasiromar | 6:c9695079521d | 74 | |
nasiromar | 6:c9695079521d | 75 | |
rconnorlawson | 0:35660d7952f7 | 76 | |
rconnorlawson | 0:35660d7952f7 | 77 | /** |
rconnorlawson | 0:35660d7952f7 | 78 | * Initializes the internal structures for all maps. This does not populate |
rconnorlawson | 0:35660d7952f7 | 79 | * the map with items, but allocates space for them, initializes the hash tables, |
rconnorlawson | 0:35660d7952f7 | 80 | * and sets the width and height. |
rconnorlawson | 0:35660d7952f7 | 81 | */ |
rconnorlawson | 0:35660d7952f7 | 82 | void maps_init(); |
rconnorlawson | 0:35660d7952f7 | 83 | |
rconnorlawson | 0:35660d7952f7 | 84 | /** |
rconnorlawson | 0:35660d7952f7 | 85 | * Returns a pointer to the active map. |
rconnorlawson | 0:35660d7952f7 | 86 | */ |
rconnorlawson | 0:35660d7952f7 | 87 | Map* get_active_map(); |
rconnorlawson | 0:35660d7952f7 | 88 | |
nasiromar | 10:e18685911e84 | 89 | int get_current_map(); |
nasiromar | 10:e18685911e84 | 90 | |
rconnorlawson | 0:35660d7952f7 | 91 | /** |
rconnorlawson | 0:35660d7952f7 | 92 | * Sets the active map to map m, where m is the index of the map to activate. |
rconnorlawson | 0:35660d7952f7 | 93 | * Returns a pointer to the new active map. |
rconnorlawson | 0:35660d7952f7 | 94 | */ |
rconnorlawson | 0:35660d7952f7 | 95 | Map* set_active_map(int m); |
rconnorlawson | 0:35660d7952f7 | 96 | |
rconnorlawson | 0:35660d7952f7 | 97 | /** |
rconnorlawson | 0:35660d7952f7 | 98 | * Returns the map m, regardless of whether it is the active map. This function |
rconnorlawson | 0:35660d7952f7 | 99 | * does not change the active map. |
rconnorlawson | 0:35660d7952f7 | 100 | */ |
nasiromar | 11:6cd02a8539d1 | 101 | int get_map(int m); |
rconnorlawson | 0:35660d7952f7 | 102 | |
rconnorlawson | 0:35660d7952f7 | 103 | /** |
rconnorlawson | 0:35660d7952f7 | 104 | * Print the active map to the serial console. |
rconnorlawson | 0:35660d7952f7 | 105 | */ |
rconnorlawson | 0:35660d7952f7 | 106 | void print_map(); |
rconnorlawson | 0:35660d7952f7 | 107 | |
rconnorlawson | 0:35660d7952f7 | 108 | // Access |
rconnorlawson | 0:35660d7952f7 | 109 | /** |
rconnorlawson | 0:35660d7952f7 | 110 | * Returns the width of the active map. |
rconnorlawson | 0:35660d7952f7 | 111 | */ |
rconnorlawson | 0:35660d7952f7 | 112 | int map_width(); |
rconnorlawson | 0:35660d7952f7 | 113 | |
rconnorlawson | 0:35660d7952f7 | 114 | /** |
rconnorlawson | 0:35660d7952f7 | 115 | * Returns the heigh of the active map. |
rconnorlawson | 0:35660d7952f7 | 116 | */ |
rconnorlawson | 0:35660d7952f7 | 117 | int map_height(); |
rconnorlawson | 0:35660d7952f7 | 118 | |
rconnorlawson | 0:35660d7952f7 | 119 | /** |
rconnorlawson | 0:35660d7952f7 | 120 | * Returns the total number of cells in the active map. |
rconnorlawson | 0:35660d7952f7 | 121 | */ |
rconnorlawson | 0:35660d7952f7 | 122 | int map_area(); |
rconnorlawson | 0:35660d7952f7 | 123 | |
rconnorlawson | 0:35660d7952f7 | 124 | /** |
rconnorlawson | 0:35660d7952f7 | 125 | * Returns the MapItem immediately above the given location. |
rconnorlawson | 0:35660d7952f7 | 126 | */ |
rconnorlawson | 0:35660d7952f7 | 127 | MapItem* get_north(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 128 | |
rconnorlawson | 0:35660d7952f7 | 129 | /** |
rconnorlawson | 0:35660d7952f7 | 130 | * Returns the MapItem immediately below the given location. |
rconnorlawson | 0:35660d7952f7 | 131 | */ |
rconnorlawson | 0:35660d7952f7 | 132 | MapItem* get_south(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 133 | |
rconnorlawson | 0:35660d7952f7 | 134 | /** |
rconnorlawson | 0:35660d7952f7 | 135 | * Returns the MapItem immediately to the right of the given location. |
rconnorlawson | 0:35660d7952f7 | 136 | */ |
rconnorlawson | 0:35660d7952f7 | 137 | MapItem* get_east(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 138 | |
rconnorlawson | 0:35660d7952f7 | 139 | /** |
rconnorlawson | 0:35660d7952f7 | 140 | * Returns the MapItem immediately to the left of the given location. |
rconnorlawson | 0:35660d7952f7 | 141 | */ |
rconnorlawson | 0:35660d7952f7 | 142 | MapItem* get_west(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 143 | |
rconnorlawson | 0:35660d7952f7 | 144 | /** |
rconnorlawson | 0:35660d7952f7 | 145 | * Returns the MapItem at the given location. |
rconnorlawson | 0:35660d7952f7 | 146 | */ |
rconnorlawson | 0:35660d7952f7 | 147 | MapItem* get_here(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 148 | |
rconnorlawson | 0:35660d7952f7 | 149 | // Directions, for using the modification functions |
rconnorlawson | 0:35660d7952f7 | 150 | #define HORIZONTAL 0 |
rconnorlawson | 0:35660d7952f7 | 151 | #define VERTICAL 1 |
rconnorlawson | 0:35660d7952f7 | 152 | |
rconnorlawson | 0:35660d7952f7 | 153 | /** |
rconnorlawson | 0:35660d7952f7 | 154 | * If there is a MapItem at (x,y), remove it from the map. |
rconnorlawson | 0:35660d7952f7 | 155 | */ |
rconnorlawson | 0:35660d7952f7 | 156 | void map_erase(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 157 | |
nasiromar | 11:6cd02a8539d1 | 158 | void map_delete(int x, int y); |
nasiromar | 11:6cd02a8539d1 | 159 | |
rconnorlawson | 0:35660d7952f7 | 160 | /** |
rconnorlawson | 0:35660d7952f7 | 161 | * Add WALL items in a line of length len beginning at (x,y). |
rconnorlawson | 0:35660d7952f7 | 162 | * If dir == HORIZONTAL, the line is in the direction of increasing x. |
rconnorlawson | 0:35660d7952f7 | 163 | * If dir == VERTICAL, the line is in the direction of increasing y. |
rconnorlawson | 0:35660d7952f7 | 164 | * |
rconnorlawson | 0:35660d7952f7 | 165 | * If there are already items in the map that collide with this line, they are |
rconnorlawson | 0:35660d7952f7 | 166 | * erased. |
rconnorlawson | 0:35660d7952f7 | 167 | */ |
rconnorlawson | 0:35660d7952f7 | 168 | void add_wall(int x, int y, int dir, int len); |
rconnorlawson | 0:35660d7952f7 | 169 | |
nasiromar | 6:c9695079521d | 170 | //, int dir, int len |
nasiromar | 6:c9695079521d | 171 | |
nasiromar | 7:862062ffca62 | 172 | void add_castle(int x, int y, int dir, int len); |
nasiromar | 7:862062ffca62 | 173 | |
nasiromar | 7:862062ffca62 | 174 | void add_kindom(int x, int y); |
nasiromar | 6:c9695079521d | 175 | |
nasiromar | 11:6cd02a8539d1 | 176 | void add_fire(int x, int y); |
nasiromar | 11:6cd02a8539d1 | 177 | |
nasiromar | 6:c9695079521d | 178 | void add_chest(int x, int y); |
nasiromar | 6:c9695079521d | 179 | |
nasiromar | 14:7225da81314a | 180 | void add_chest2(int x, int y); |
nasiromar | 14:7225da81314a | 181 | |
nasiromar | 6:c9695079521d | 182 | void add_npc(int x, int y); |
nasiromar | 6:c9695079521d | 183 | |
nasiromar | 11:6cd02a8539d1 | 184 | void add_npc2(int x, int y); |
nasiromar | 11:6cd02a8539d1 | 185 | |
nasiromar | 11:6cd02a8539d1 | 186 | void add_store(int x, int y); |
nasiromar | 11:6cd02a8539d1 | 187 | |
nasiromar | 11:6cd02a8539d1 | 188 | void add_merch(int x, int y); |
nasiromar | 11:6cd02a8539d1 | 189 | |
nasiromar | 11:6cd02a8539d1 | 190 | void add_eye(int x, int y); |
nasiromar | 11:6cd02a8539d1 | 191 | |
nasiromar | 13:798a4dd14c7e | 192 | void add_goblin(int x, int y, int type); |
nasiromar | 9:cbb9cfb1f6c5 | 193 | |
nasiromar | 6:c9695079521d | 194 | void add_portal(int x, int y); |
nasiromar | 6:c9695079521d | 195 | |
nasiromar | 7:862062ffca62 | 196 | void add_portal2(int x, int y); |
nasiromar | 7:862062ffca62 | 197 | |
nasiromar | 7:862062ffca62 | 198 | void add_door(int x, int y); |
nasiromar | 7:862062ffca62 | 199 | |
nasiromar | 7:862062ffca62 | 200 | void add_dragon(int x, int y); |
nasiromar | 7:862062ffca62 | 201 | |
nasiromar | 7:862062ffca62 | 202 | |
rconnorlawson | 0:35660d7952f7 | 203 | /** |
rconnorlawson | 0:35660d7952f7 | 204 | * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it |
rconnorlawson | 0:35660d7952f7 | 205 | * before adding the plant. |
rconnorlawson | 0:35660d7952f7 | 206 | */ |
rconnorlawson | 0:35660d7952f7 | 207 | void add_plant(int x, int y); |
rconnorlawson | 0:35660d7952f7 | 208 | |
rconnorlawson | 0:35660d7952f7 | 209 | #endif //MAP_H |