Adventure game written for ECE2035 at the Georgia Institute of Technology

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
trmontgomery
Date:
Sat Oct 26 15:44:26 2019 +0000
Revision:
5:93a4c396c1af
Parent:
4:cdc54191ff07
test

Who changed what in which revision?

UserRevisionLine numberNew 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 */
trmontgomery 3:289762133fd6 9
trmontgomery 3:289762133fd6 10 typedef struct {
trmontgomery 3:289762133fd6 11 HashTable* items;
trmontgomery 3:289762133fd6 12 int w, h;
trmontgomery 3:289762133fd6 13 } Map;
rconnorlawson 0:35660d7952f7 14
rconnorlawson 0:35660d7952f7 15 // A function pointer type for drawing MapItems.
rconnorlawson 0:35660d7952f7 16 // All tiles are 11x11 blocks.
rconnorlawson 0:35660d7952f7 17 // u,v is the top left corner pixel of the block
rconnorlawson 0:35660d7952f7 18 typedef void (*DrawFunc)(int u, int v);
rconnorlawson 0:35660d7952f7 19
rconnorlawson 0:35660d7952f7 20 /**
rconnorlawson 0:35660d7952f7 21 * The data for elements in the map. Each item in the map HashTable is a
rconnorlawson 0:35660d7952f7 22 * MapItem.
rconnorlawson 0:35660d7952f7 23 */
rconnorlawson 0:35660d7952f7 24 typedef struct {
rconnorlawson 0:35660d7952f7 25 /**
rconnorlawson 0:35660d7952f7 26 * Indicates the "type" of the MapItem: WALL, DOOR, PLANT, etc. This is
rconnorlawson 0:35660d7952f7 27 * useful for determining how to interact with the object when updating the
rconnorlawson 0:35660d7952f7 28 * game state.
rconnorlawson 0:35660d7952f7 29 */
rconnorlawson 0:35660d7952f7 30 int type;
rconnorlawson 0:35660d7952f7 31
rconnorlawson 0:35660d7952f7 32 /**
rconnorlawson 0:35660d7952f7 33 * A function pointer to the drawing function for this item. Used by draw_game.
rconnorlawson 0:35660d7952f7 34 */
rconnorlawson 0:35660d7952f7 35 DrawFunc draw;
rconnorlawson 0:35660d7952f7 36
rconnorlawson 0:35660d7952f7 37 /**
rconnorlawson 0:35660d7952f7 38 * If zero, this item should block character motion.
rconnorlawson 0:35660d7952f7 39 */
rconnorlawson 0:35660d7952f7 40 int walkable;
rconnorlawson 0:35660d7952f7 41
rconnorlawson 0:35660d7952f7 42 /**
rconnorlawson 0:35660d7952f7 43 * Arbitrary extra data for the MapItem. Could be useful for keeping up with
rconnorlawson 0:35660d7952f7 44 * special information, like where a set of stairs should take the player.
rconnorlawson 0:35660d7952f7 45 *
rconnorlawson 0:35660d7952f7 46 * Iterpretation of this can depend on the type of the MapItem. For example,
rconnorlawson 0:35660d7952f7 47 * a WALL probably doesn't need to use this (it can be NULL), where an NPC
rconnorlawson 0:35660d7952f7 48 * might use it to store game state (have I given the player the key yet?).
rconnorlawson 0:35660d7952f7 49 */
rconnorlawson 0:35660d7952f7 50 void* data;
rconnorlawson 0:35660d7952f7 51 } MapItem;
rconnorlawson 0:35660d7952f7 52
trmontgomery 2:0876296d9473 53 typedef struct{
trmontgomery 2:0876296d9473 54 int x,y; // Current locations
trmontgomery 2:0876296d9473 55 int px, py; // Previous locations
trmontgomery 2:0876296d9473 56 int quest_requested; //check to see if player has asked for quest
trmontgomery 2:0876296d9473 57 int has_key;
trmontgomery 2:0876296d9473 58 int quest_complete;
trmontgomery 2:0876296d9473 59 } NonPlayer;
trmontgomery 2:0876296d9473 60
trmontgomery 4:cdc54191ff07 61 typedef struct{
trmontgomery 4:cdc54191ff07 62 int x,y; // Current locations
trmontgomery 4:cdc54191ff07 63 int px, py; // Previous locations
trmontgomery 4:cdc54191ff07 64 int e;
trmontgomery 4:cdc54191ff07 65 } Extra;
trmontgomery 4:cdc54191ff07 66
trmontgomery 2:0876296d9473 67 typedef struct {
trmontgomery 2:0876296d9473 68 int x,y; // Current locations
trmontgomery 2:0876296d9473 69 int px, py; // Previous locations
trmontgomery 2:0876296d9473 70 int is_pushed;
trmontgomery 2:0876296d9473 71 int wall_touch;
trmontgomery 2:0876296d9473 72 } Rock;
trmontgomery 2:0876296d9473 73
rconnorlawson 0:35660d7952f7 74 typedef struct {
trmontgomery 4:cdc54191ff07 75 int key;
trmontgomery 4:cdc54191ff07 76 } Lbush;
trmontgomery 4:cdc54191ff07 77
trmontgomery 4:cdc54191ff07 78 typedef struct {
trmontgomery 4:cdc54191ff07 79 int key;
trmontgomery 4:cdc54191ff07 80 } House;
trmontgomery 4:cdc54191ff07 81
trmontgomery 4:cdc54191ff07 82
trmontgomery 4:cdc54191ff07 83 typedef struct {
rconnorlawson 0:35660d7952f7 84 int tm;
rconnorlawson 0:35660d7952f7 85 int tx, ty;
rconnorlawson 0:35660d7952f7 86 } StairsData;
rconnorlawson 0:35660d7952f7 87
rconnorlawson 0:35660d7952f7 88 // MapItem types
rconnorlawson 0:35660d7952f7 89 // Define more of these!
rconnorlawson 0:35660d7952f7 90 #define WALL 0
rconnorlawson 0:35660d7952f7 91 #define PLANT 1
trmontgomery 2:0876296d9473 92 #define NPC 2
trmontgomery 2:0876296d9473 93 #define ROCK 3
trmontgomery 2:0876296d9473 94 #define DOOR 4
trmontgomery 2:0876296d9473 95 #define GOAL 5
trmontgomery 2:0876296d9473 96 #define SPIKE 6
trmontgomery 4:cdc54191ff07 97 #define LBUSH 7
trmontgomery 4:cdc54191ff07 98 #define GEM 8
trmontgomery 4:cdc54191ff07 99 #define HOUSE 9
trmontgomery 4:cdc54191ff07 100 #define GDOOR 10
trmontgomery 4:cdc54191ff07 101 #define EXTRA 11
rconnorlawson 0:35660d7952f7 102
rconnorlawson 0:35660d7952f7 103 /**
rconnorlawson 0:35660d7952f7 104 * Initializes the internal structures for all maps. This does not populate
rconnorlawson 0:35660d7952f7 105 * the map with items, but allocates space for them, initializes the hash tables,
rconnorlawson 0:35660d7952f7 106 * and sets the width and height.
rconnorlawson 0:35660d7952f7 107 */
trmontgomery 3:289762133fd6 108 void maps_init(int h, int w, int buckets);
rconnorlawson 0:35660d7952f7 109
rconnorlawson 0:35660d7952f7 110 /**
rconnorlawson 0:35660d7952f7 111 * Returns a pointer to the active map.
rconnorlawson 0:35660d7952f7 112 */
rconnorlawson 0:35660d7952f7 113 Map* get_active_map();
rconnorlawson 0:35660d7952f7 114
rconnorlawson 0:35660d7952f7 115 /**
rconnorlawson 0:35660d7952f7 116 * Sets the active map to map m, where m is the index of the map to activate.
rconnorlawson 0:35660d7952f7 117 * Returns a pointer to the new active map.
rconnorlawson 0:35660d7952f7 118 */
rconnorlawson 0:35660d7952f7 119 Map* set_active_map(int m);
rconnorlawson 0:35660d7952f7 120
rconnorlawson 0:35660d7952f7 121 /**
rconnorlawson 0:35660d7952f7 122 * Returns the map m, regardless of whether it is the active map. This function
rconnorlawson 0:35660d7952f7 123 * does not change the active map.
rconnorlawson 0:35660d7952f7 124 */
rconnorlawson 0:35660d7952f7 125 Map* get_map(int m);
rconnorlawson 0:35660d7952f7 126
rconnorlawson 0:35660d7952f7 127 /**
rconnorlawson 0:35660d7952f7 128 * Print the active map to the serial console.
rconnorlawson 0:35660d7952f7 129 */
rconnorlawson 0:35660d7952f7 130 void print_map();
rconnorlawson 0:35660d7952f7 131
rconnorlawson 0:35660d7952f7 132 // Access
rconnorlawson 0:35660d7952f7 133 /**
rconnorlawson 0:35660d7952f7 134 * Returns the width of the active map.
rconnorlawson 0:35660d7952f7 135 */
rconnorlawson 0:35660d7952f7 136 int map_width();
rconnorlawson 0:35660d7952f7 137
rconnorlawson 0:35660d7952f7 138 /**
rconnorlawson 0:35660d7952f7 139 * Returns the heigh of the active map.
rconnorlawson 0:35660d7952f7 140 */
rconnorlawson 0:35660d7952f7 141 int map_height();
rconnorlawson 0:35660d7952f7 142
rconnorlawson 0:35660d7952f7 143 /**
rconnorlawson 0:35660d7952f7 144 * Returns the total number of cells in the active map.
rconnorlawson 0:35660d7952f7 145 */
rconnorlawson 0:35660d7952f7 146 int map_area();
rconnorlawson 0:35660d7952f7 147
rconnorlawson 0:35660d7952f7 148 /**
rconnorlawson 0:35660d7952f7 149 * Returns the MapItem immediately above the given location.
rconnorlawson 0:35660d7952f7 150 */
rconnorlawson 0:35660d7952f7 151 MapItem* get_north(int x, int y);
rconnorlawson 0:35660d7952f7 152
rconnorlawson 0:35660d7952f7 153 /**
rconnorlawson 0:35660d7952f7 154 * Returns the MapItem immediately below the given location.
rconnorlawson 0:35660d7952f7 155 */
rconnorlawson 0:35660d7952f7 156 MapItem* get_south(int x, int y);
rconnorlawson 0:35660d7952f7 157
rconnorlawson 0:35660d7952f7 158 /**
rconnorlawson 0:35660d7952f7 159 * Returns the MapItem immediately to the right of the given location.
rconnorlawson 0:35660d7952f7 160 */
rconnorlawson 0:35660d7952f7 161 MapItem* get_east(int x, int y);
rconnorlawson 0:35660d7952f7 162
rconnorlawson 0:35660d7952f7 163 /**
rconnorlawson 0:35660d7952f7 164 * Returns the MapItem immediately to the left of the given location.
rconnorlawson 0:35660d7952f7 165 */
rconnorlawson 0:35660d7952f7 166 MapItem* get_west(int x, int y);
rconnorlawson 0:35660d7952f7 167
rconnorlawson 0:35660d7952f7 168 /**
rconnorlawson 0:35660d7952f7 169 * Returns the MapItem at the given location.
rconnorlawson 0:35660d7952f7 170 */
rconnorlawson 0:35660d7952f7 171 MapItem* get_here(int x, int y);
rconnorlawson 0:35660d7952f7 172
rconnorlawson 0:35660d7952f7 173 // Directions, for using the modification functions
rconnorlawson 0:35660d7952f7 174 #define HORIZONTAL 0
rconnorlawson 0:35660d7952f7 175 #define VERTICAL 1
rconnorlawson 0:35660d7952f7 176
rconnorlawson 0:35660d7952f7 177 /**
rconnorlawson 0:35660d7952f7 178 * If there is a MapItem at (x,y), remove it from the map.
rconnorlawson 0:35660d7952f7 179 */
rconnorlawson 0:35660d7952f7 180 void map_erase(int x, int y);
rconnorlawson 0:35660d7952f7 181
trmontgomery 2:0876296d9473 182
trmontgomery 2:0876296d9473 183
trmontgomery 2:0876296d9473 184 /**
rconnorlawson 0:35660d7952f7 185 * Add WALL items in a line of length len beginning at (x,y).
rconnorlawson 0:35660d7952f7 186 * If dir == HORIZONTAL, the line is in the direction of increasing x.
rconnorlawson 0:35660d7952f7 187 * If dir == VERTICAL, the line is in the direction of increasing y.
rconnorlawson 0:35660d7952f7 188 *
rconnorlawson 0:35660d7952f7 189 * If there are already items in the map that collide with this line, they are
rconnorlawson 0:35660d7952f7 190 * erased.
rconnorlawson 0:35660d7952f7 191 */
rconnorlawson 0:35660d7952f7 192 void add_wall(int x, int y, int dir, int len);
rconnorlawson 0:35660d7952f7 193
rconnorlawson 0:35660d7952f7 194 /**
rconnorlawson 0:35660d7952f7 195 * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it
rconnorlawson 0:35660d7952f7 196 * before adding the plant.
rconnorlawson 0:35660d7952f7 197 */
rconnorlawson 0:35660d7952f7 198 void add_plant(int x, int y);
trmontgomery 2:0876296d9473 199 void add_rock(int x, int y);
trmontgomery 2:0876296d9473 200 void add_npc(int x, int y);
trmontgomery 4:cdc54191ff07 201 void add_extra(int x, int y);
trmontgomery 2:0876296d9473 202 void add_door(int x, int y);
trmontgomery 4:cdc54191ff07 203 void add_gdoor(int x, int y);
trmontgomery 2:0876296d9473 204 void add_goal(int x, int y);
trmontgomery 2:0876296d9473 205 void add_spike(int x, int y);
trmontgomery 4:cdc54191ff07 206 void add_lbush(int x, int y, int key);
trmontgomery 4:cdc54191ff07 207 void add_gem(int x, int y, int color);
trmontgomery 4:cdc54191ff07 208 void add_redhouse(int x, int y, int key);
trmontgomery 4:cdc54191ff07 209 void add_bush_rect(int a, int b, int c, int d);
trmontgomery 4:cdc54191ff07 210 void add_bluehouse(int x, int y, int key);
rconnorlawson 0:35660d7952f7 211 #endif //MAP_H