Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
map.cpp@11:6cd02a8539d1, 2021-12-02 (annotated)
- Committer:
- nasiromar
- Date:
- Thu Dec 02 06:24:22 2021 +0000
- Revision:
- 11:6cd02a8539d1
- Parent:
- 10:e18685911e84
- Child:
- 12:116a4cc85b16
almost;
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 | 11:6cd02a8539d1 | 6 | #define NumBuckets 10 |
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 | 6:c9695079521d | 70 | map[1].w = WIDTH-25; |
nasiromar | 6:c9695079521d | 71 | map[1].h = HEIGHT-25; |
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 | 11:6cd02a8539d1 | 262 | void add_eye(int x, int y) |
nasiromar | 11:6cd02a8539d1 | 263 | { |
nasiromar | 11:6cd02a8539d1 | 264 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 11:6cd02a8539d1 | 265 | w1->type = ENEMY; |
nasiromar | 11:6cd02a8539d1 | 266 | w1->draw = draw_eye; |
nasiromar | 11:6cd02a8539d1 | 267 | w1->walkable = true; |
nasiromar | 11:6cd02a8539d1 | 268 | w1->data = NULL; |
nasiromar | 11:6cd02a8539d1 | 269 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 11:6cd02a8539d1 | 270 | if (val) free(val); |
nasiromar | 11:6cd02a8539d1 | 271 | } |
nasiromar | 11:6cd02a8539d1 | 272 | |
nasiromar | 11:6cd02a8539d1 | 273 | void add_goblin(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_goblin; |
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 | 11:6cd02a8539d1 | 284 | |
nasiromar | 6:c9695079521d | 285 | void add_portal(int x, int y) |
nasiromar | 6:c9695079521d | 286 | { |
nasiromar | 6:c9695079521d | 287 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 6:c9695079521d | 288 | w1->type = PORTAL; |
nasiromar | 6:c9695079521d | 289 | w1->draw = draw_portal; |
nasiromar | 6:c9695079521d | 290 | w1->walkable = true; |
nasiromar | 6:c9695079521d | 291 | w1->data = NULL; |
nasiromar | 6:c9695079521d | 292 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 6:c9695079521d | 293 | if (val) free(val); |
nasiromar | 6:c9695079521d | 294 | } |
nasiromar | 6:c9695079521d | 295 | |
nasiromar | 7:862062ffca62 | 296 | void add_kindom(int x, int y) |
nasiromar | 7:862062ffca62 | 297 | { |
nasiromar | 7:862062ffca62 | 298 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 299 | w1->type = KINDOM; |
nasiromar | 7:862062ffca62 | 300 | w1->draw = draw_kindom; |
nasiromar | 7:862062ffca62 | 301 | w1->walkable = false; |
nasiromar | 7:862062ffca62 | 302 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 303 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 304 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 305 | } |
nasiromar | 7:862062ffca62 | 306 | |
nasiromar | 7:862062ffca62 | 307 | |
nasiromar | 7:862062ffca62 | 308 | void add_portal2(int x, int y) |
nasiromar | 7:862062ffca62 | 309 | { |
nasiromar | 7:862062ffca62 | 310 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 311 | w1->type = PORTAl; |
nasiromar | 7:862062ffca62 | 312 | w1->draw = draw_portal2; |
nasiromar | 7:862062ffca62 | 313 | w1->walkable = true; |
nasiromar | 7:862062ffca62 | 314 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 315 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 316 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 317 | } |
nasiromar | 7:862062ffca62 | 318 | |
nasiromar | 7:862062ffca62 | 319 | |
nasiromar | 6:c9695079521d | 320 | void add_chest(int x, int y) |
nasiromar | 6:c9695079521d | 321 | { |
nasiromar | 6:c9695079521d | 322 | MapItem*chest = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 6:c9695079521d | 323 | chest->type = CHEST; |
nasiromar | 6:c9695079521d | 324 | chest->draw = draw_chest; |
nasiromar | 6:c9695079521d | 325 | chest->walkable = false; |
nasiromar | 6:c9695079521d | 326 | chest->data = NULL; |
nasiromar | 6:c9695079521d | 327 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),chest); |
nasiromar | 6:c9695079521d | 328 | if (val) free(val); |
nasiromar | 6:c9695079521d | 329 | } |
nasiromar | 6:c9695079521d | 330 | |
nasiromar | 7:862062ffca62 | 331 | void add_door(int x, int y) |
nasiromar | 7:862062ffca62 | 332 | { |
nasiromar | 7:862062ffca62 | 333 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 334 | w1->type = DOOR; |
nasiromar | 7:862062ffca62 | 335 | w1->draw = draw_door; |
nasiromar | 7:862062ffca62 | 336 | w1->walkable = false; |
nasiromar | 7:862062ffca62 | 337 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 338 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 339 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 340 | } |
nasiromar | 7:862062ffca62 | 341 | |
nasiromar | 7:862062ffca62 | 342 | void add_dragon(int x, int y) |
nasiromar | 7:862062ffca62 | 343 | { |
nasiromar | 7:862062ffca62 | 344 | MapItem*w1 = (MapItem*) malloc(sizeof(MapItem)); |
nasiromar | 7:862062ffca62 | 345 | w1->type = DRAGON; |
nasiromar | 7:862062ffca62 | 346 | w1->draw = draw_dragon; |
nasiromar | 7:862062ffca62 | 347 | w1->walkable = false; |
nasiromar | 7:862062ffca62 | 348 | w1->data = NULL; |
nasiromar | 7:862062ffca62 | 349 | void* val = insertItem(get_active_map()->items,XY_KEY(x,y),w1); |
nasiromar | 7:862062ffca62 | 350 | if (val) free(val); |
nasiromar | 7:862062ffca62 | 351 | } |
nasiromar | 6:c9695079521d | 352 | |
nasiromar | 6:c9695079521d | 353 | |
nasiromar | 6:c9695079521d | 354 | |
nasiromar | 6:c9695079521d | 355 | |
rconnorlawson | 0:35660d7952f7 | 356 | void add_plant(int x, int y) |
rconnorlawson | 0:35660d7952f7 | 357 | { |
rconnorlawson | 0:35660d7952f7 | 358 | MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); |
rconnorlawson | 0:35660d7952f7 | 359 | w1->type = PLANT; |
rconnorlawson | 0:35660d7952f7 | 360 | w1->draw = draw_plant; |
rconnorlawson | 0:35660d7952f7 | 361 | w1->walkable = true; |
nasiromar | 9:cbb9cfb1f6c5 | 362 | w1->data = FRUIT; |
rconnorlawson | 0:35660d7952f7 | 363 | void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); |
rconnorlawson | 0:35660d7952f7 | 364 | if (val) free(val); // If something is already there, free it |
rconnorlawson | 0:35660d7952f7 | 365 | } |