project for 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
map.h@1:10330bce85cb, 2020-10-23 (annotated)
- Committer:
- DCchico
- Date:
- Fri Oct 23 16:18:39 2020 -0400
- Revision:
- 1:10330bce85cb
- Child:
- 2:4947d6a82971
shell-code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DCchico | 1:10330bce85cb | 1 | #ifndef MAP_H |
DCchico | 1:10330bce85cb | 2 | #define MAP_H |
DCchico | 1:10330bce85cb | 3 | |
DCchico | 1:10330bce85cb | 4 | #include "hash_table.h" |
DCchico | 1:10330bce85cb | 5 | |
DCchico | 1:10330bce85cb | 6 | /** |
DCchico | 1:10330bce85cb | 7 | * A structure to represent the map. The implementation is private. |
DCchico | 1:10330bce85cb | 8 | */ |
DCchico | 1:10330bce85cb | 9 | struct Map; |
DCchico | 1:10330bce85cb | 10 | |
DCchico | 1:10330bce85cb | 11 | // A function pointer type for drawing MapItems. |
DCchico | 1:10330bce85cb | 12 | // All tiles are 11x11 blocks. |
DCchico | 1:10330bce85cb | 13 | // u,v is the top left corner pixel of the block |
DCchico | 1:10330bce85cb | 14 | typedef void (*DrawFunc)(int u, int v); |
DCchico | 1:10330bce85cb | 15 | |
DCchico | 1:10330bce85cb | 16 | /** |
DCchico | 1:10330bce85cb | 17 | * The data for elements in the map. Each item in the map HashTable is a |
DCchico | 1:10330bce85cb | 18 | * MapItem. |
DCchico | 1:10330bce85cb | 19 | */ |
DCchico | 1:10330bce85cb | 20 | typedef struct { |
DCchico | 1:10330bce85cb | 21 | /** |
DCchico | 1:10330bce85cb | 22 | * Indicates the "type" of the MapItem: WALL, DOOR, PLANT, etc. This is |
DCchico | 1:10330bce85cb | 23 | * useful for determining how to interact with the object when updating the |
DCchico | 1:10330bce85cb | 24 | * game state. |
DCchico | 1:10330bce85cb | 25 | */ |
DCchico | 1:10330bce85cb | 26 | int type; |
DCchico | 1:10330bce85cb | 27 | |
DCchico | 1:10330bce85cb | 28 | /** |
DCchico | 1:10330bce85cb | 29 | * A function pointer to the drawing function for this item. Used by draw_game. |
DCchico | 1:10330bce85cb | 30 | */ |
DCchico | 1:10330bce85cb | 31 | DrawFunc draw; |
DCchico | 1:10330bce85cb | 32 | |
DCchico | 1:10330bce85cb | 33 | /** |
DCchico | 1:10330bce85cb | 34 | * If zero, this item should block character motion. |
DCchico | 1:10330bce85cb | 35 | */ |
DCchico | 1:10330bce85cb | 36 | int walkable; |
DCchico | 1:10330bce85cb | 37 | |
DCchico | 1:10330bce85cb | 38 | /** |
DCchico | 1:10330bce85cb | 39 | * Arbitrary extra data for the MapItem. Could be useful for keeping up with |
DCchico | 1:10330bce85cb | 40 | * special information, like where a set of stairs should take the player. |
DCchico | 1:10330bce85cb | 41 | * |
DCchico | 1:10330bce85cb | 42 | * Iterpretation of this can depend on the type of the MapItem. For example, |
DCchico | 1:10330bce85cb | 43 | * a WALL probably doesn't need to use this (it can be NULL), where an NPC |
DCchico | 1:10330bce85cb | 44 | * might use it to store game state (have I given the player the key yet?). |
DCchico | 1:10330bce85cb | 45 | */ |
DCchico | 1:10330bce85cb | 46 | void* data; |
DCchico | 1:10330bce85cb | 47 | } MapItem; |
DCchico | 1:10330bce85cb | 48 | |
DCchico | 1:10330bce85cb | 49 | typedef struct { |
DCchico | 1:10330bce85cb | 50 | int tm; |
DCchico | 1:10330bce85cb | 51 | int tx, ty; |
DCchico | 1:10330bce85cb | 52 | } StairsData; |
DCchico | 1:10330bce85cb | 53 | |
DCchico | 1:10330bce85cb | 54 | // MapItem types |
DCchico | 1:10330bce85cb | 55 | // Define more of these! |
DCchico | 1:10330bce85cb | 56 | #define WALL 0 |
DCchico | 1:10330bce85cb | 57 | #define DOOR 1 |
DCchico | 1:10330bce85cb | 58 | #define PLANT 2 |
DCchico | 1:10330bce85cb | 59 | #define WATER 3 |
DCchico | 1:10330bce85cb | 60 | #define KEY 4 |
DCchico | 1:10330bce85cb | 61 | #define GOODIE 5 |
DCchico | 1:10330bce85cb | 62 | #define SNAKE_BODY 6 |
DCchico | 1:10330bce85cb | 63 | #define CLEAR 7 |
DCchico | 1:10330bce85cb | 64 | #define STAIRS 8 |
DCchico | 1:10330bce85cb | 65 | #define SONAR 9 |
DCchico | 1:10330bce85cb | 66 | #define PUZZLE 10 |
DCchico | 1:10330bce85cb | 67 | #define NPC 11 |
DCchico | 1:10330bce85cb | 68 | |
DCchico | 1:10330bce85cb | 69 | |
DCchico | 1:10330bce85cb | 70 | /** |
DCchico | 1:10330bce85cb | 71 | * Initializes the internal structures for all maps. This does not populate |
DCchico | 1:10330bce85cb | 72 | * the map with items, but allocates space for them, initializes the hash tables, |
DCchico | 1:10330bce85cb | 73 | * and sets the width and height. |
DCchico | 1:10330bce85cb | 74 | */ |
DCchico | 1:10330bce85cb | 75 | void maps_init(); |
DCchico | 1:10330bce85cb | 76 | |
DCchico | 1:10330bce85cb | 77 | /** |
DCchico | 1:10330bce85cb | 78 | * Returns a pointer to the active map. |
DCchico | 1:10330bce85cb | 79 | */ |
DCchico | 1:10330bce85cb | 80 | Map* get_active_map(); |
DCchico | 1:10330bce85cb | 81 | |
DCchico | 1:10330bce85cb | 82 | /** |
DCchico | 1:10330bce85cb | 83 | * Sets the active map to map m, where m is the index of the map to activate. |
DCchico | 1:10330bce85cb | 84 | * Returns a pointer to the new active map. |
DCchico | 1:10330bce85cb | 85 | */ |
DCchico | 1:10330bce85cb | 86 | Map* set_active_map(int m); |
DCchico | 1:10330bce85cb | 87 | |
DCchico | 1:10330bce85cb | 88 | /** |
DCchico | 1:10330bce85cb | 89 | * Returns the map m, regardless of whether it is the active map. This function |
DCchico | 1:10330bce85cb | 90 | * does not change the active map. |
DCchico | 1:10330bce85cb | 91 | */ |
DCchico | 1:10330bce85cb | 92 | Map* get_map(int m); |
DCchico | 1:10330bce85cb | 93 | |
DCchico | 1:10330bce85cb | 94 | /** |
DCchico | 1:10330bce85cb | 95 | * Print the active map to the serial console. |
DCchico | 1:10330bce85cb | 96 | */ |
DCchico | 1:10330bce85cb | 97 | void print_map(); |
DCchico | 1:10330bce85cb | 98 | |
DCchico | 1:10330bce85cb | 99 | // Access |
DCchico | 1:10330bce85cb | 100 | /** |
DCchico | 1:10330bce85cb | 101 | * Returns the width of the active map. |
DCchico | 1:10330bce85cb | 102 | */ |
DCchico | 1:10330bce85cb | 103 | int map_width(); |
DCchico | 1:10330bce85cb | 104 | |
DCchico | 1:10330bce85cb | 105 | /** |
DCchico | 1:10330bce85cb | 106 | * Returns the heigh of the active map. |
DCchico | 1:10330bce85cb | 107 | */ |
DCchico | 1:10330bce85cb | 108 | int map_height(); |
DCchico | 1:10330bce85cb | 109 | |
DCchico | 1:10330bce85cb | 110 | /** |
DCchico | 1:10330bce85cb | 111 | * Returns the total number of cells in the active map. |
DCchico | 1:10330bce85cb | 112 | */ |
DCchico | 1:10330bce85cb | 113 | int map_area(); |
DCchico | 1:10330bce85cb | 114 | |
DCchico | 1:10330bce85cb | 115 | MapItem* get_current(int x, int y); |
DCchico | 1:10330bce85cb | 116 | |
DCchico | 1:10330bce85cb | 117 | /** |
DCchico | 1:10330bce85cb | 118 | * Returns the MapItem immediately above the given location. |
DCchico | 1:10330bce85cb | 119 | */ |
DCchico | 1:10330bce85cb | 120 | MapItem* get_north(int x, int y); |
DCchico | 1:10330bce85cb | 121 | |
DCchico | 1:10330bce85cb | 122 | /** |
DCchico | 1:10330bce85cb | 123 | * Returns the MapItem immediately below the given location. |
DCchico | 1:10330bce85cb | 124 | */ |
DCchico | 1:10330bce85cb | 125 | MapItem* get_south(int x, int y); |
DCchico | 1:10330bce85cb | 126 | |
DCchico | 1:10330bce85cb | 127 | /** |
DCchico | 1:10330bce85cb | 128 | * Returns the MapItem immediately to the right of the given location. |
DCchico | 1:10330bce85cb | 129 | */ |
DCchico | 1:10330bce85cb | 130 | MapItem* get_east(int x, int y); |
DCchico | 1:10330bce85cb | 131 | |
DCchico | 1:10330bce85cb | 132 | /** |
DCchico | 1:10330bce85cb | 133 | * Returns the MapItem immediately to the left of the given location. |
DCchico | 1:10330bce85cb | 134 | */ |
DCchico | 1:10330bce85cb | 135 | MapItem* get_west(int x, int y); |
DCchico | 1:10330bce85cb | 136 | |
DCchico | 1:10330bce85cb | 137 | /** |
DCchico | 1:10330bce85cb | 138 | * Returns the MapItem at the given location. |
DCchico | 1:10330bce85cb | 139 | */ |
DCchico | 1:10330bce85cb | 140 | MapItem* get_here(int x, int y); |
DCchico | 1:10330bce85cb | 141 | |
DCchico | 1:10330bce85cb | 142 | // Directions, for using the modification functions |
DCchico | 1:10330bce85cb | 143 | #define HORIZONTAL 0 |
DCchico | 1:10330bce85cb | 144 | #define VERTICAL 1 |
DCchico | 1:10330bce85cb | 145 | |
DCchico | 1:10330bce85cb | 146 | /** |
DCchico | 1:10330bce85cb | 147 | * If there is a MapItem at (x,y), remove it from the map. |
DCchico | 1:10330bce85cb | 148 | */ |
DCchico | 1:10330bce85cb | 149 | void map_erase(int x, int y); |
DCchico | 1:10330bce85cb | 150 | |
DCchico | 1:10330bce85cb | 151 | /** |
DCchico | 1:10330bce85cb | 152 | * Add WALL items in a line of length len beginning at (x,y). |
DCchico | 1:10330bce85cb | 153 | * If dir == HORIZONTAL, the line is in the direction of increasing x. |
DCchico | 1:10330bce85cb | 154 | * If dir == VERTICAL, the line is in the direction of increasing y. |
DCchico | 1:10330bce85cb | 155 | * |
DCchico | 1:10330bce85cb | 156 | * If there are already items in the map that collide with this line, they are |
DCchico | 1:10330bce85cb | 157 | * erased. |
DCchico | 1:10330bce85cb | 158 | */ |
DCchico | 1:10330bce85cb | 159 | void add_wall(int x, int y, int dir, int len); |
DCchico | 1:10330bce85cb | 160 | |
DCchico | 1:10330bce85cb | 161 | /** |
DCchico | 1:10330bce85cb | 162 | * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it |
DCchico | 1:10330bce85cb | 163 | * before adding the plant. |
DCchico | 1:10330bce85cb | 164 | */ |
DCchico | 1:10330bce85cb | 165 | void add_plant(int x, int y); |
DCchico | 1:10330bce85cb | 166 | |
DCchico | 1:10330bce85cb | 167 | |
DCchico | 1:10330bce85cb | 168 | void add_goodie(int x, int y); |
DCchico | 1:10330bce85cb | 169 | |
DCchico | 1:10330bce85cb | 170 | void remove_goodie(int x, int y); |
DCchico | 1:10330bce85cb | 171 | |
DCchico | 1:10330bce85cb | 172 | void add_snake_body(int x, int y); |
DCchico | 1:10330bce85cb | 173 | void add_snake_head(int x, int y); |
DCchico | 1:10330bce85cb | 174 | void add_snake_tail(int x, int y); |
DCchico | 1:10330bce85cb | 175 | |
DCchico | 1:10330bce85cb | 176 | |
DCchico | 1:10330bce85cb | 177 | #endif //MAP_H |