Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
map.cpp@18:760dd68e939e, 2021-12-03 (annotated)
- Committer:
- nasiromar
- Date:
- Fri Dec 03 19:12:50 2021 +0000
- Revision:
- 18:760dd68e939e
- Parent:
- 16:06a88c0110ff
New Update;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:35660d7952f7 | 1 | #include "map.h" |
rconnorlawson | 0:35660d7952f7 | 2 | |
rconnorlawson | 0:35660d7952f7 | 3 | #include "globals.h" |
rconnorlawson | 0:35660d7952f7 | 4 | #include "graphics.h" |
rconnorlawson | 0:35660d7952f7 | 5 | |
nasiromar | 12:116a4cc85b16 | 6 | #define NumBuckets 5 |
nasiromar | 11:6cd02a8539d1 | 7 | #define NumMaps 3 |
nasiromar | 6:c9695079521d | 8 | #define HEIGHT 50 |
nasiromar | 6:c9695079521d | 9 | #define WIDTH 50 |
nasiromar | 6:c9695079521d | 10 | |
rconnorlawson | 0:35660d7952f7 | 11 | /** |
rconnorlawson | 0:35660d7952f7 | 12 | * The Map structure. This holds a HashTable for all the MapItems, along with |
rconnorlawson | 0:35660d7952f7 | 13 | * values for the width and height of the Map. |
lballard9 | 4:37d3935365f8 | 14 | * In this file you need to define how the map will be structured. IE how will |
lballard9 | 4:37d3935365f8 | 15 | * you put values into the map, pull them from the map. Remember a "Map" variable |
nasiromar | 6:c9695079521d | 16 | * is a hashtable plus two ints (see below) |
lballard9 | 4:37d3935365f8 | 17 | * You will have more than one map variable, one will be the main map with it's own hashtable. |
lballard9 | 4:37d3935365f8 | 18 | * Then you'll have a second map with another hashtable |
lballard9 | 4:37d3935365f8 | 19 | * You should store objects into the hashtable with different properties (spells |
lballard9 | 4:37d3935365f8 | 20 | * etc) |
rconnorlawson | 0:35660d7952f7 | 21 | */ |
rconnorlawson | 0:35660d7952f7 | 22 | struct Map { |
rconnorlawson | 0:35660d7952f7 | 23 | HashTable* items; |
rconnorlawson | 0:35660d7952f7 | 24 | int w, h; |
rconnorlawson | 0:35660d7952f7 | 25 | }; |
rconnorlawson | 0:35660d7952f7 | 26 | |
rconnorlawson | 0:35660d7952f7 | 27 | /** |
rconnorlawson | 0:35660d7952f7 | 28 | * Storage area for the maps. |
rconnorlawson | 0:35660d7952f7 | 29 | * This is a global variable, but can only be access from this file because it |
rconnorlawson | 0:35660d7952f7 | 30 | * is static. |
rconnorlawson | 0:35660d7952f7 | 31 | */ |
nasiromar | 6:c9695079521d | 32 | static Map map[NumMaps]; |
rconnorlawson | 0:35660d7952f7 | 33 | static int active_map; |
rconnorlawson | 0:35660d7952f7 | 34 | |
rconnorlawson | 0:35660d7952f7 | 35 | /** |
rconnorlawson | 0:35660d7952f7 | 36 | * The first step in HashTable access for the map is turning the two-dimensional |
rconnorlawson | 0:35660d7952f7 | 37 | * key information (x, y) into a one-dimensional unsigned integer. |
rconnorlawson | 0:35660d7952f7 | 38 | * This function should uniquely map (x,y) onto the space of unsigned integers. |
rconnorlawson | 0:35660d7952f7 | 39 | */ |
nasiromar | 6:c9695079521d | 40 | static unsigned XY_KEY(int X, int Y) |
nasiromar | 6:c9695079521d | 41 | { |
rconnorlawson | 0:35660d7952f7 | 42 | // TODO: Fix me! |
nasiromar | 6:c9695079521d | 43 | unsigned int key = WIDTH*X+Y; |
nasiromar | 6:c9695079521d | 44 | return key; |
rconnorlawson | 0:35660d7952f7 | 45 | } |
rconnorlawson | 0:35660d7952f7 | 46 | |
rconnorlawson | 0:35660d7952f7 | 47 | /** |
rconnorlawson | 0:35660d7952f7 | 48 | * This is the hash function actually passed into createHashTable. It takes an |
rconnorlawson | 0:35660d7952f7 | 49 | * unsigned key (the output of XY_KEY) and turns it into a hash value (some |
rconnorlawson | 0:35660d7952f7 | 50 | * small non-negative integer). |
rconnorlawson | 0:35660d7952f7 | 51 | */ |
rconnorlawson | 0:35660d7952f7 | 52 | unsigned map_hash(unsigned key) |
rconnorlawson | 0:35660d7952f7 | 53 | { |
rconnorlawson | 0:35660d7952f7 | 54 | // TODO: Fix me! |
nasiromar | 6:c9695079521d | 55 | int hash_value = key%NumBuckets; |
nasiromar | 6:c9695079521d | 56 | return hash_value; |
rconnorlawson | 0:35660d7952f7 | 57 | } |
rconnorlawson | 0:35660d7952f7 | 58 | |
rconnorlawson | 0:35660d7952f7 | 59 | void maps_init() |
rconnorlawson | 0:35660d7952f7 | 60 | { |
nasiromar | 6:c9695079521d | 61 | // TODO: Implement! |
rconnorlawson | 0:35660d7952f7 | 62 | // Initialize hash table |
rconnorlawson | 0:35660d7952f7 | 63 | // Set width & height |
nasiromar | 6:c9695079521d | 64 | |
nasiromar | 6:c9695079521d | 65 | map[0].items = createHashTable(map_hash,NumBuckets); |
nasiromar | 6:c9695079521d | 66 | map[0].w = WIDTH; |
nasiromar | 6:c9695079521d | 67 | map[0].h = HEIGHT; |
nasiromar | 6:c9695079521d | 68 | |
nasiromar | 6:c9695079521d | 69 | map[1].items = createHashTable(map_hash,NumBuckets); |
nasiromar | 12:116a4cc85b16 | 70 | map[1].w = WIDTH-30; |
nasiromar | 12:116a4cc85b16 | 71 | map[1].h = HEIGHT-30; |
nasiromar | 6:c9695079521d | 72 | |
nasiromar | 6:c9695079521d | 73 | |
rconnorlawson | 0:35660d7952f7 | 74 | } |
rconnorlawson | 0:35660d7952f7 | 75 | |
rconnorlawson | 0:35660d7952f7 | 76 | Map* get_active_map() |
rconnorlawson | 0:35660d7952f7 | 77 | { |
rconnorlawson | 0:35660d7952f7 | 78 | // There's only one map |
nasiromar | 6:c9695079521d | 79 | return &map[active_map]; |
rconnorlawson | 0:35660d7952f7 | 80 | } |
rconnorlawson | 0:35660d7952f7 | 81 | |
nasiromar | 11:6cd02a8539d1 | 82 | int get_map(int m){ |
nasiromar | 10:e18685911e84 | 83 | |
nasiromar | 11:6cd02a8539d1 | 84 | return m; |
nasiromar | 10:e18685911e84 | 85 | |
nasiromar | 10:e18685911e84 | 86 | } |
nasiromar | 10:e18685911e84 | 87 | |
rconnorlawson | 0:35660d7952f7 | 88 | Map* set_active_map(int m) |
rconnorlawson | 0:35660d7952f7 | 89 | { |
rconnorlawson | 0:35660d7952f7 | 90 | active_map = m; |
nasiromar | 6:c9695079521d | 91 | return &map[active_map]; |
rconnorlawson | 0:35660d7952f7 | 92 | } |
rconnorlawson | 0:35660d7952f7 | 93 | |
rconnorlawson | 0:35660d7952f7 | 94 | void print_map() |
rconnorlawson | 0:35660d7952f7 | 95 | { |
rconnorlawson | 0:35660d7952f7 | 96 | // As you add more types, you'll need to add more items to this array. |
rconnorlawson | 0:35660d7952f7 | 97 | char lookup[] = {'W', 'P'}; |
nasiromar | 6:c9695079521d | 98 | for(int y = 0; y < map_height(); y++) { |
nasiromar | 6:c9695079521d | 99 | for (int x = 0; x < map_width(); x++) { |
rconnorlawson | 0:35660d7952f7 | 100 | MapItem* item = get_here(x,y); |
rconnorlawson | 0:35660d7952f7 | 101 | if (item) pc.printf("%c", lookup[item->type]); |
rconnorlawson | 0:35660d7952f7 | 102 | else pc.printf(" "); |
rconnorlawson | 0:35660d7952f7 | 103 | } |
rconnorlawson | 0:35660d7952f7 | 104 | pc.printf("\r\n"); |
rconnorlawson | 0:35660d7952f7 | 105 | } |
rconnorlawson | 0:35660d7952f7 | 106 | } |
rconnorlawson | 0:35660d7952f7 | 107 | |
rconnorlawson | 0:35660d7952f7 | 108 | int map_width() |
rconnorlawson | 0:35660d7952f7 | 109 | { |
nasiromar | 6:c9695079521d | 110 | return get_active_map()->w; |
rconnorlawson | 0:35660d7952f7 | 111 | } |
rconnorlawson | 0:35660d7952f7 | 112 | |
rconnorlawson | 0:35660d7952f7 | 113 | int map_height() |
rconnorlawson | 0:35660d7952f7 | 114 | { |
nasiromar | 6:c9695079521d | 115 | return get_active_map()->h; |
rconnorlawson | 0:35660d7952f7 | 116 | } |
rconnorlawson | 0:35660d7952f7 | 117 | |
rconnorlawson | 0:35660d7952f7 | 118 | int map_area() |
rconnorlawson | 0:35660d7952f7 | 119 | { |
nasiromar | 6:c9695079521d | 120 | int area = map_height() * map_width(); |
nasiromar | 6:c9695079521d | 121 | return area; |
rconnorlawson | 0:35660d7952f7 | 122 | } |
rconnorlawson | 0:35660d7952f7 | 123 | |
rconnorlawson | 0:35660d7952f7 | 124 | MapItem* get_north(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 125 | { |
nasiromar | 6:c9695079521d | 126 | unsigned int key = XY_KEY(x,y-1); |
nasiromar | 6:c9695079521d | 127 | MapItem* up = (MapItem*)getItem(get_active_map()->items,key); |
nasiromar | 6:c9695079521d | 128 | return up; |
nasiromar | 6:c9695079521d | 129 | |
rconnorlawson | 0:35660d7952f7 | 130 | } |
rconnorlawson | 0:35660d7952f7 | 131 | |
rconnorlawson | 0:35660d7952f7 | 132 | MapItem* get_south(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 133 | { |
nasiromar | 6:c9695079521d | 134 | unsigned int key = XY_KEY(x,y+1); |
nasiromar | 6:c9695079521d | 135 | MapItem* down = (MapItem*)getItem(get_active_map()->items,key); |
nasiromar | 6:c9695079521d | 136 | return down; |
nasiromar | 6:c9695079521d | 137 | |
rconnorlawson | 0:35660d7952f7 | 138 | } |
rconnorlawson | 0:35660d7952f7 | 139 | |
rconnorlawson | 0:35660d7952f7 | 140 | MapItem* get_east(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 141 | { |
nasiromar | 6:c9695079521d | 142 | unsigned int key = XY_KEY(x+1,y); |
nasiromar | 6:c9695079521d | 143 | MapItem* right = (MapItem*)getItem(get_active_map()->items,key); |
nasiromar | 6:c9695079521d | 144 | return right; |
nasiromar | 6:c9695079521d | 145 | |
rconnorlawson | 0:35660d7952f7 | 146 | } |
rconnorlawson | 0:35660d7952f7 | 147 | |
rconnorlawson | 0:35660d7952f7 | 148 | MapItem* get_west(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 149 | { |
nasiromar | 6:c9695079521d | 150 | unsigned int key = XY_KEY(x-1,y); |
nasiromar | 6:c9695079521d | 151 | MapItem* left = (MapItem*)getItem(get_active_map()->items,key); |
nasiromar | 6:c9695079521d | 152 | return left; |
nasiromar | 6:c9695079521d | 153 | |
rconnorlawson | 0:35660d7952f7 | 154 | } |
rconnorlawson | 0:35660d7952f7 | 155 | |
rconnorlawson | 0:35660d7952f7 | 156 | MapItem* get_here(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 157 | { |
nasiromar | 6:c9695079521d | 158 | unsigned int key = XY_KEY(x,y); |
nasiromar | 6:c9695079521d | 159 | MapItem* curr = (MapItem*)getItem(get_active_map()->items,key); |
nasiromar | 6:c9695079521d | 160 | return curr; |
rconnorlawson | 0:35660d7952f7 | 161 | } |
rconnorlawson | 0:35660d7952f7 | 162 | |
rconnorlawson | 0:35660d7952f7 | 163 | |
rconnorlawson | 0:35660d7952f7 | 164 | void map_erase(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 165 | { |
nasiromar | 6:c9695079521d | 166 | unsigned int key = XY_KEY(x,y); |
nasiromar | 6:c9695079521d | 167 | |
nasiromar | 10:e18685911e84 | 168 | removeItem(get_active_map()->items,key); |
rconnorlawson | 0:35660d7952f7 | 169 | } |
rconnorlawson | 0:35660d7952f7 | 170 | |
nasiromar | 11:6cd02a8539d1 | 171 | void map_delete(int x, int y) |
nasiromar | 11:6cd02a8539d1 | 172 | { |
nasiromar | 11:6cd02a8539d1 | 173 | unsigned int key = XY_KEY(x,y); |
nasiromar | 11:6cd02a8539d1 | 174 | |
nasiromar | 11:6cd02a8539d1 | 175 | deleteItem(get_active_map()->items,key); |
nasiromar | 11:6cd02a8539d1 | 176 | } |
nasiromar | 11:6cd02a8539d1 | 177 | |
rconnorlawson | 0:35660d7952f7 | 178 | void add_wall(int x, int y, int dir, int len) |
rconnorlawson | 0:35660d7952f7 | 179 | { |
nasiromar | 6:c9695079521d | 180 | for(int i = 0; i < len; i++) { |
rconnorlawson | 0:35660d7952f7 | 181 | MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); |
rconnorlawson | 0:35660d7952f7 | 182 | w1->type = WALL; |
rconnorlawson | 0:35660d7952f7 | 183 | w1->draw = draw_wall; |
rconnorlawson | 0:35660d7952f7 | 184 | w1->walkable = false; |
rconnorlawson | 0:35660d7952f7 | 185 | w1->data = NULL; |
rconnorlawson | 0:35660d7952f7 | 186 | unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y) : XY_KEY(x, y+i); |
rconnorlawson | 0:35660d7952f7 | 187 | void* val = insertItem(get_active_map()->items, key, w1); |
rconnorlawson | 0:35660d7952f7 | 188 | if (val) free(val); // If something is already there, free it |
rconnorlawson | 0:35660d7952f7 | 189 | } |
rconnorlawson | 0:35660d7952f7 | 190 | } |
rconnorlawson | 0:35660d7952f7 | 191 | |
nasiromar | 7:862062ffca62 | 192 | void add_castle(int x, int y, int dir, int len) |
nasiromar | 6:c9695079521d | 193 | { |
nasiromar | 7:862062ffca62 | 194 | for(int i = 0; i < len; i++) { |
nasiromar | 6:c9695079521d | 195 | MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 6:c9695079521d | 196 | w1->type = CASTL; |
nasiromar | 6:c9695079521d | 197 | w1->draw = draw_castle; |
nasiromar | 6:c9695079521d | 198 | w1->walkable = false; |
nasiromar | 6:c9695079521d | 199 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 200 | unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y) : XY_KEY(x, y+i); |
nasiromar | 7:862062ffca62 | 201 | void* val = insertItem(get_active_map()->items, key, w1); |
nasiromar | 6:c9695079521d | 202 | if (val) free(val); // If something is already there, free it |
nasiromar | 7:862062ffca62 | 203 | } |
nasiromar | 6:c9695079521d | 204 | } |
nasiromar | 6:c9695079521d | 205 | |
nasiromar | 11:6cd02a8539d1 | 206 | void add_fire(int x, int y) |
nasiromar | 11:6cd02a8539d1 | 207 | { |
nasiromar | 11:6cd02a8539d1 | 208 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 11:6cd02a8539d1 | 209 | w1->type = CASTL; |
nasiromar | 11:6cd02a8539d1 | 210 | w1->draw = draw_fire; |
nasiromar | 11:6cd02a8539d1 | 211 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 212 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 213 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 214 | if (val) free(val); |
nasiromar | 11:6cd02a8539d1 | 215 | } |
nasiromar | 9:cbb9cfb1f6c5 | 216 | |
nasiromar | 6:c9695079521d | 217 | |
nasiromar | 6:c9695079521d | 218 | void add_npc(int x, int y) |
nasiromar | 6:c9695079521d | 219 | { |
nasiromar | 11:6cd02a8539d1 | 220 | MapItem*npc = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 6:c9695079521d | 221 | npc->type = NPC; |
nasiromar | 6:c9695079521d | 222 | npc->draw = draw_npc; |
nasiromar | 6:c9695079521d | 223 | npc->walkable = false; |
nasiromar | 6:c9695079521d | 224 | npc->data = NULL; |
nasiromar | 6:c9695079521d | 225 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),npc); |
nasiromar | 6:c9695079521d | 226 | if (val) free(val); |
nasiromar | 6:c9695079521d | 227 | } |
nasiromar | 6:c9695079521d | 228 | |
nasiromar | 11:6cd02a8539d1 | 229 | void add_npc2(int x, int y) |
nasiromar | 11:6cd02a8539d1 | 230 | { |
nasiromar | 11:6cd02a8539d1 | 231 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 11:6cd02a8539d1 | 232 | w1->type = NPCT; |
nasiromar | 11:6cd02a8539d1 | 233 | w1->draw = draw_npc2; |
nasiromar | 11:6cd02a8539d1 | 234 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 235 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 236 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 237 | if (val) free(val); |
nasiromar | 11:6cd02a8539d1 | 238 | } |
nasiromar | 11:6cd02a8539d1 | 239 | |
nasiromar | 11:6cd02a8539d1 | 240 | void add_store(int x, int y) |
nasiromar | 11:6cd02a8539d1 | 241 | { |
nasiromar | 11:6cd02a8539d1 | 242 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 11:6cd02a8539d1 | 243 | w1->type = CASTL; |
nasiromar | 11:6cd02a8539d1 | 244 | w1->draw = draw_store; |
nasiromar | 11:6cd02a8539d1 | 245 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 246 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 247 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 248 | if (val) free(val); |
nasiromar | 11:6cd02a8539d1 | 249 | } |
nasiromar | 11:6cd02a8539d1 | 250 | |
nasiromar | 11:6cd02a8539d1 | 251 | void add_merch(int x, int y) |
nasiromar | 9:cbb9cfb1f6c5 | 252 | { |
nasiromar | 11:6cd02a8539d1 | 253 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 11:6cd02a8539d1 | 254 | w1->type = VILL; |
nasiromar | 11:6cd02a8539d1 | 255 | w1->draw = draw_merch; |
nasiromar | 11:6cd02a8539d1 | 256 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 257 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 258 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 259 | if (val) free(val); |
nasiromar | 10:e18685911e84 | 260 | } |
nasiromar | 9:cbb9cfb1f6c5 | 261 | |
nasiromar | 16:06a88c0110ff | 262 | void add_key(int x, int y) |
nasiromar | 16:06a88c0110ff | 263 | { |
nasiromar | 16:06a88c0110ff | 264 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 16:06a88c0110ff | 265 | w1->type = KEY; |
nasiromar | 16:06a88c0110ff | 266 | w1->draw = draw_key; |
nasiromar | 16:06a88c0110ff | 267 | w1->walkable = true; |
nasiromar | 16:06a88c0110ff | 268 | w1->data = NULL; |
nasiromar | 16:06a88c0110ff | 269 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 16:06a88c0110ff | 270 | if (val) free(val); |
nasiromar | 16:06a88c0110ff | 271 | } |
nasiromar | 16:06a88c0110ff | 272 | |
nasiromar | 11:6cd02a8539d1 | 273 | void add_eye(int x, int y) |
nasiromar | 11:6cd02a8539d1 | 274 | { |
nasiromar | 11:6cd02a8539d1 | 275 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 11:6cd02a8539d1 | 276 | w1->type = ENEMY; |
nasiromar | 11:6cd02a8539d1 | 277 | w1->draw = draw_eye; |
nasiromar | 11:6cd02a8539d1 | 278 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 279 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 280 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 281 | if (val) free(val); |
nasiromar | 11:6cd02a8539d1 | 282 | } |
nasiromar | 11:6cd02a8539d1 | 283 | |
nasiromar | 13:798a4dd14c7e | 284 | void add_goblin(int x, int y, int type) |
nasiromar | 11:6cd02a8539d1 | 285 | { |
nasiromar | 11:6cd02a8539d1 | 286 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 13:798a4dd14c7e | 287 | w1->type = type; |
nasiromar | 11:6cd02a8539d1 | 288 | w1->draw = draw_goblin; |
nasiromar | 11:6cd02a8539d1 | 289 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 290 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 291 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 292 | if (val) free(val); |
nasiromar | 11:6cd02a8539d1 | 293 | } |
nasiromar | 11:6cd02a8539d1 | 294 | |
nasiromar | 11:6cd02a8539d1 | 295 | |
nasiromar | 6:c9695079521d | 296 | void add_portal(int x, int y) |
nasiromar | 6:c9695079521d | 297 | { |
nasiromar | 6:c9695079521d | 298 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 6:c9695079521d | 299 | w1->type = PORTAL; |
nasiromar | 6:c9695079521d | 300 | w1->draw = draw_portal; |
nasiromar | 6:c9695079521d | 301 | w1->walkable = true; |
nasiromar | 6:c9695079521d | 302 | w1->data = NULL; |
nasiromar | 6:c9695079521d | 303 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 6:c9695079521d | 304 | if (val) free(val); |
nasiromar | 6:c9695079521d | 305 | } |
nasiromar | 6:c9695079521d | 306 | |
nasiromar | 7:862062ffca62 | 307 | void add_kindom(int x, int y) |
nasiromar | 7:862062ffca62 | 308 | { |
nasiromar | 7:862062ffca62 | 309 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 310 | w1->type = KINDOM; |
nasiromar | 7:862062ffca62 | 311 | w1->draw = draw_kindom; |
nasiromar | 7:862062ffca62 | 312 | w1->walkable = false; |
nasiromar | 7:862062ffca62 | 313 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 314 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 315 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 316 | } |
nasiromar | 7:862062ffca62 | 317 | |
nasiromar | 7:862062ffca62 | 318 | |
nasiromar | 7:862062ffca62 | 319 | void add_portal2(int x, int y) |
nasiromar | 7:862062ffca62 | 320 | { |
nasiromar | 7:862062ffca62 | 321 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 322 | w1->type = PORTAl; |
nasiromar | 7:862062ffca62 | 323 | w1->draw = draw_portal2; |
nasiromar | 7:862062ffca62 | 324 | w1->walkable = true; |
nasiromar | 7:862062ffca62 | 325 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 326 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 327 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 328 | } |
nasiromar | 7:862062ffca62 | 329 | |
nasiromar | 7:862062ffca62 | 330 | |
nasiromar | 6:c9695079521d | 331 | void add_chest(int x, int y) |
nasiromar | 6:c9695079521d | 332 | { |
nasiromar | 6:c9695079521d | 333 | MapItem*chest = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 6:c9695079521d | 334 | chest->type = CHEST; |
nasiromar | 6:c9695079521d | 335 | chest->draw = draw_chest; |
nasiromar | 6:c9695079521d | 336 | chest->walkable = false; |
nasiromar | 6:c9695079521d | 337 | chest->data = NULL; |
nasiromar | 6:c9695079521d | 338 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),chest); |
nasiromar | 6:c9695079521d | 339 | if (val) free(val); |
nasiromar | 6:c9695079521d | 340 | } |
nasiromar | 6:c9695079521d | 341 | |
nasiromar | 14:7225da81314a | 342 | void add_chest2(int x, int y) |
nasiromar | 14:7225da81314a | 343 | { |
nasiromar | 14:7225da81314a | 344 | MapItem*chest = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 14:7225da81314a | 345 | chest->type = CHESTT; |
nasiromar | 14:7225da81314a | 346 | chest->draw = draw_chest; |
nasiromar | 14:7225da81314a | 347 | chest->walkable = false; |
nasiromar | 14:7225da81314a | 348 | chest->data = NULL; |
nasiromar | 14:7225da81314a | 349 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),chest); |
nasiromar | 14:7225da81314a | 350 | if (val) free(val); |
nasiromar | 14:7225da81314a | 351 | } |
nasiromar | 14:7225da81314a | 352 | |
nasiromar | 7:862062ffca62 | 353 | void add_door(int x, int y) |
nasiromar | 7:862062ffca62 | 354 | { |
nasiromar | 7:862062ffca62 | 355 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 356 | w1->type = DOOR; |
nasiromar | 7:862062ffca62 | 357 | w1->draw = draw_door; |
nasiromar | 7:862062ffca62 | 358 | w1->walkable = false; |
nasiromar | 7:862062ffca62 | 359 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 360 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 361 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 362 | } |
nasiromar | 7:862062ffca62 | 363 | |
nasiromar | 7:862062ffca62 | 364 | void add_dragon(int x, int y) |
nasiromar | 7:862062ffca62 | 365 | { |
nasiromar | 7:862062ffca62 | 366 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 367 | w1->type = DRAGON; |
nasiromar | 7:862062ffca62 | 368 | w1->draw = draw_dragon; |
nasiromar | 7:862062ffca62 | 369 | w1->walkable = false; |
nasiromar | 7:862062ffca62 | 370 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 371 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 372 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 373 | } |
nasiromar | 6:c9695079521d | 374 | |
nasiromar | 6:c9695079521d | 375 | |
nasiromar | 6:c9695079521d | 376 | |
nasiromar | 6:c9695079521d | 377 | |
rconnorlawson | 0:35660d7952f7 | 378 | void add_plant(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 379 | { |
rconnorlawson | 0:35660d7952f7 | 380 | MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); |
rconnorlawson | 0:35660d7952f7 | 381 | w1->type = PLANT; |
rconnorlawson | 0:35660d7952f7 | 382 | w1->draw = draw_plant; |
rconnorlawson | 0:35660d7952f7 | 383 | w1->walkable = true; |
nasiromar | 9:cbb9cfb1f6c5 | 384 | w1->data = FRUIT; |
rconnorlawson | 0:35660d7952f7 | 385 | void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); |
rconnorlawson | 0:35660d7952f7 | 386 | if (val) free(val); // If something is already there, free it |
rconnorlawson | 0:35660d7952f7 | 387 | } |