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