2035 project 2

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
ranroun3
Date:
Wed Dec 01 19:44:43 2021 +0000
Revision:
20:762297435411
Parent:
18:e91acccede4d
Child:
22:397601b1cdb4
added inventory, potions, items, and new buttons for using inventory

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rconnorlawson 0:35660d7952f7 1 #include "map.h"
rconnorlawson 0:35660d7952f7 2
rconnorlawson 0:35660d7952f7 3 #include "globals.h"
ranroun3 6:291aef457c4e 4 #include "hash_table.h"
rconnorlawson 0:35660d7952f7 5 #include "graphics.h"
rconnorlawson 0:35660d7952f7 6
rconnorlawson 0:35660d7952f7 7 /**
rconnorlawson 0:35660d7952f7 8 * The Map structure. This holds a HashTable for all the MapItems, along with
rconnorlawson 0:35660d7952f7 9 * values for the width and height of the Map.
lballard9 4:37d3935365f8 10 * In this file you need to define how the map will be structured. IE how will
lballard9 4:37d3935365f8 11 * you put values into the map, pull them from the map. Remember a "Map" variable
ranroun3 8:89dee5f187ba 12 * is a hashtable plus two ints (see below)
lballard9 4:37d3935365f8 13 * You will have more than one map variable, one will be the main map with it's own hashtable.
lballard9 4:37d3935365f8 14 * Then you'll have a second map with another hashtable
lballard9 4:37d3935365f8 15 * You should store objects into the hashtable with different properties (spells
lballard9 4:37d3935365f8 16 * etc)
rconnorlawson 0:35660d7952f7 17 */
rconnorlawson 0:35660d7952f7 18 struct Map {
rconnorlawson 0:35660d7952f7 19 HashTable* items;
rconnorlawson 0:35660d7952f7 20 int w, h;
rconnorlawson 0:35660d7952f7 21 };
rconnorlawson 0:35660d7952f7 22
rconnorlawson 0:35660d7952f7 23 /**
rconnorlawson 0:35660d7952f7 24 * Storage area for the maps.
rconnorlawson 0:35660d7952f7 25 * This is a global variable, but can only be access from this file because it
rconnorlawson 0:35660d7952f7 26 * is static.
rconnorlawson 0:35660d7952f7 27 */
ranroun3 6:291aef457c4e 28 static Map map[3];
rconnorlawson 0:35660d7952f7 29 static int active_map;
rconnorlawson 0:35660d7952f7 30
ranroun3 6:291aef457c4e 31
rconnorlawson 0:35660d7952f7 32 /**
rconnorlawson 0:35660d7952f7 33 * The first step in HashTable access for the map is turning the two-dimensional
rconnorlawson 0:35660d7952f7 34 * key information (x, y) into a one-dimensional unsigned integer.
rconnorlawson 0:35660d7952f7 35 * This function should uniquely map (x,y) onto the space of unsigned integers.
rconnorlawson 0:35660d7952f7 36 */
ranroun3 8:89dee5f187ba 37 static unsigned XY_KEY(int X, int Y)
ranroun3 8:89dee5f187ba 38 {
ranroun3 6:291aef457c4e 39 return (Y * map_width()) + X;
rconnorlawson 0:35660d7952f7 40 }
rconnorlawson 0:35660d7952f7 41
rconnorlawson 0:35660d7952f7 42 /**
rconnorlawson 0:35660d7952f7 43 * This is the hash function actually passed into createHashTable. It takes an
rconnorlawson 0:35660d7952f7 44 * unsigned key (the output of XY_KEY) and turns it into a hash value (some
rconnorlawson 0:35660d7952f7 45 * small non-negative integer).
rconnorlawson 0:35660d7952f7 46 */
rconnorlawson 0:35660d7952f7 47 unsigned map_hash(unsigned key)
rconnorlawson 0:35660d7952f7 48 {
ranroun3 6:291aef457c4e 49 return key % NUM_BUCKETS;
rconnorlawson 0:35660d7952f7 50 }
rconnorlawson 0:35660d7952f7 51
rconnorlawson 0:35660d7952f7 52 void maps_init()
rconnorlawson 0:35660d7952f7 53 {
ranroun3 8:89dee5f187ba 54
ranroun3 18:e91acccede4d 55 if(map[0].items!= NULL) {
ranroun3 18:e91acccede4d 56 destroyHashTable(map[0].items);
ranroun3 18:e91acccede4d 57 }
ranroun3 18:e91acccede4d 58 if(map[1].items!= NULL) {
ranroun3 18:e91acccede4d 59 destroyHashTable(map[1].items);
ranroun3 18:e91acccede4d 60 }
ranroun3 18:e91acccede4d 61 if(map[2].items!= NULL) {
ranroun3 18:e91acccede4d 62 destroyHashTable(map[2].items);
ranroun3 18:e91acccede4d 63 }
ranroun3 6:291aef457c4e 64
ranroun3 6:291aef457c4e 65 map[0].items = createHashTable(map_hash, NUM_BUCKETS);
ranroun3 6:291aef457c4e 66 map[0].w = mainMapWidth;
ranroun3 6:291aef457c4e 67 map[0].h = mainMapHeight;
ranroun3 6:291aef457c4e 68 map[1].items = createHashTable(map_hash, NUM_BUCKETS);
ranroun3 6:291aef457c4e 69 map[1].w = bossMapWidth;
ranroun3 6:291aef457c4e 70 map[1].h = bossMapHeight;
ranroun3 6:291aef457c4e 71 map[2].items = createHashTable(map_hash, NUM_BUCKETS);
ranroun3 6:291aef457c4e 72 map[2].w = map3Width;
ranroun3 6:291aef457c4e 73 map[2].h = map3Height;
ranroun3 8:89dee5f187ba 74
ranroun3 8:89dee5f187ba 75 // TODO: Implement!
rconnorlawson 0:35660d7952f7 76 // Initialize hash table
rconnorlawson 0:35660d7952f7 77 // Set width & height
rconnorlawson 0:35660d7952f7 78 }
rconnorlawson 0:35660d7952f7 79
rconnorlawson 0:35660d7952f7 80 Map* get_active_map()
rconnorlawson 0:35660d7952f7 81 {
ranroun3 8:89dee5f187ba 82
ranroun3 6:291aef457c4e 83 return &map[active_map];
rconnorlawson 0:35660d7952f7 84 }
rconnorlawson 0:35660d7952f7 85
rconnorlawson 0:35660d7952f7 86 Map* set_active_map(int m)
rconnorlawson 0:35660d7952f7 87 {
rconnorlawson 0:35660d7952f7 88 active_map = m;
ranroun3 6:291aef457c4e 89 return &map[active_map];
rconnorlawson 0:35660d7952f7 90 }
rconnorlawson 0:35660d7952f7 91
rconnorlawson 0:35660d7952f7 92 void print_map()
rconnorlawson 0:35660d7952f7 93 {
rconnorlawson 0:35660d7952f7 94 // As you add more types, you'll need to add more items to this array.
rconnorlawson 0:35660d7952f7 95 char lookup[] = {'W', 'P'};
ranroun3 8:89dee5f187ba 96 for(int y = 0; y < map_height(); y++) {
ranroun3 8:89dee5f187ba 97 for (int x = 0; x < map_width(); x++) {
rconnorlawson 0:35660d7952f7 98 MapItem* item = get_here(x,y);
rconnorlawson 0:35660d7952f7 99 if (item) pc.printf("%c", lookup[item->type]);
rconnorlawson 0:35660d7952f7 100 else pc.printf(" ");
rconnorlawson 0:35660d7952f7 101 }
rconnorlawson 0:35660d7952f7 102 pc.printf("\r\n");
rconnorlawson 0:35660d7952f7 103 }
rconnorlawson 0:35660d7952f7 104 }
rconnorlawson 0:35660d7952f7 105
rconnorlawson 0:35660d7952f7 106 int map_width()
rconnorlawson 0:35660d7952f7 107 {
ranroun3 6:291aef457c4e 108 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 109 return currMap->w;
rconnorlawson 0:35660d7952f7 110 }
rconnorlawson 0:35660d7952f7 111
rconnorlawson 0:35660d7952f7 112 int map_height()
rconnorlawson 0:35660d7952f7 113 {
ranroun3 6:291aef457c4e 114 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 115 return currMap->h;
rconnorlawson 0:35660d7952f7 116 }
rconnorlawson 0:35660d7952f7 117
rconnorlawson 0:35660d7952f7 118 int map_area()
rconnorlawson 0:35660d7952f7 119 {
ranroun3 6:291aef457c4e 120 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 121 int area = (currMap-> h) * currMap-> w;
ranroun3 6:291aef457c4e 122 return area;
rconnorlawson 0:35660d7952f7 123 }
rconnorlawson 0:35660d7952f7 124
rconnorlawson 0:35660d7952f7 125 MapItem* get_north(int x, int y)
rconnorlawson 0:35660d7952f7 126 {
ranroun3 6:291aef457c4e 127 MapItem* currItem = get_here(x, y - 1);
ranroun3 6:291aef457c4e 128 return currItem;
rconnorlawson 0:35660d7952f7 129 }
rconnorlawson 0:35660d7952f7 130
rconnorlawson 0:35660d7952f7 131 MapItem* get_south(int x, int y)
rconnorlawson 0:35660d7952f7 132 {
ranroun3 6:291aef457c4e 133 MapItem* currItem = get_here(x, y + 1);
ranroun3 6:291aef457c4e 134 return currItem;
rconnorlawson 0:35660d7952f7 135 }
rconnorlawson 0:35660d7952f7 136
rconnorlawson 0:35660d7952f7 137 MapItem* get_east(int x, int y)
rconnorlawson 0:35660d7952f7 138 {
ranroun3 6:291aef457c4e 139 MapItem* currItem = get_here(x + 1, y);
ranroun3 6:291aef457c4e 140 return currItem;
rconnorlawson 0:35660d7952f7 141 }
rconnorlawson 0:35660d7952f7 142
rconnorlawson 0:35660d7952f7 143 MapItem* get_west(int x, int y)
rconnorlawson 0:35660d7952f7 144 {
ranroun3 6:291aef457c4e 145 MapItem* currItem = get_here(x - 1, y);
ranroun3 6:291aef457c4e 146 return currItem;
rconnorlawson 0:35660d7952f7 147 }
rconnorlawson 0:35660d7952f7 148
rconnorlawson 0:35660d7952f7 149 MapItem* get_here(int x, int y)
rconnorlawson 0:35660d7952f7 150 {
ranroun3 6:291aef457c4e 151 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 152 unsigned key = XY_KEY(x, y);
ranroun3 6:291aef457c4e 153 MapItem* currItem = (MapItem*)getItem(currMap->items, key);
ranroun3 6:291aef457c4e 154 return currItem;
rconnorlawson 0:35660d7952f7 155 }
rconnorlawson 0:35660d7952f7 156
rconnorlawson 0:35660d7952f7 157
rconnorlawson 0:35660d7952f7 158 void map_erase(int x, int y)
rconnorlawson 0:35660d7952f7 159 {
ranroun3 6:291aef457c4e 160 Map* curr = get_active_map();
ranroun3 6:291aef457c4e 161 unsigned key = XY_KEY(x, y);
ranroun3 6:291aef457c4e 162 MapItem* currItem = (MapItem*) getItem(curr->items, key);
ranroun3 8:89dee5f187ba 163 if(currItem) {
ranroun3 6:291aef457c4e 164 deleteItem(curr->items, key);
ranroun3 6:291aef457c4e 165 }
ranroun3 8:89dee5f187ba 166
rconnorlawson 0:35660d7952f7 167 }
rconnorlawson 0:35660d7952f7 168
rconnorlawson 0:35660d7952f7 169 void add_wall(int x, int y, int dir, int len)
rconnorlawson 0:35660d7952f7 170 {
ranroun3 8:89dee5f187ba 171 for(int i = 0; i < len; i++) {
rconnorlawson 0:35660d7952f7 172 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
rconnorlawson 0:35660d7952f7 173 w1->type = WALL;
rconnorlawson 0:35660d7952f7 174 w1->draw = draw_wall;
rconnorlawson 0:35660d7952f7 175 w1->walkable = false;
rconnorlawson 0:35660d7952f7 176 w1->data = NULL;
rconnorlawson 0:35660d7952f7 177 unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y) : XY_KEY(x, y+i);
rconnorlawson 0:35660d7952f7 178 void* val = insertItem(get_active_map()->items, key, w1);
rconnorlawson 0:35660d7952f7 179 if (val) free(val); // If something is already there, free it
rconnorlawson 0:35660d7952f7 180 }
rconnorlawson 0:35660d7952f7 181 }
rconnorlawson 0:35660d7952f7 182
rconnorlawson 0:35660d7952f7 183 void add_plant(int x, int y)
rconnorlawson 0:35660d7952f7 184 {
rconnorlawson 0:35660d7952f7 185 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
rconnorlawson 0:35660d7952f7 186 w1->type = PLANT;
rconnorlawson 0:35660d7952f7 187 w1->draw = draw_plant;
rconnorlawson 0:35660d7952f7 188 w1->walkable = true;
rconnorlawson 0:35660d7952f7 189 w1->data = NULL;
rconnorlawson 0:35660d7952f7 190 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
rconnorlawson 0:35660d7952f7 191 if (val) free(val); // If something is already there, free it
ranroun3 6:291aef457c4e 192 }
ranroun3 6:291aef457c4e 193
ranroun3 6:291aef457c4e 194 void add_stairs(int x, int y, int newX, int newY, int newMap)
ranroun3 6:291aef457c4e 195 {
ranroun3 8:89dee5f187ba 196 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 6:291aef457c4e 197 w1->type = STAIRS;
ranroun3 6:291aef457c4e 198 w1->draw = draw_stairs;
ranroun3 6:291aef457c4e 199 w1->walkable = true;
ranroun3 6:291aef457c4e 200 StairsData *s1 = (StairsData*) malloc(sizeof(StairsData));
ranroun3 6:291aef457c4e 201 s1 -> tx = newX;
ranroun3 6:291aef457c4e 202 s1 -> ty = newY;
ranroun3 6:291aef457c4e 203 s1 -> tm = newMap;
ranroun3 6:291aef457c4e 204 s1 -> isLocked = 0;
ranroun3 6:291aef457c4e 205 w1->data = s1;
ranroun3 6:291aef457c4e 206 //stairs struct goes here
ranroun3 6:291aef457c4e 207 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 8:89dee5f187ba 208 if (val) free(val); // If something is already there, free it
ranroun3 8:89dee5f187ba 209
ranroun3 8:89dee5f187ba 210 }
ranroun3 8:89dee5f187ba 211
ranroun3 8:89dee5f187ba 212 void add_npc(int x, int y)
ranroun3 8:89dee5f187ba 213 {
ranroun3 8:89dee5f187ba 214 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 8:89dee5f187ba 215 w1->type = NPC;
ranroun3 8:89dee5f187ba 216 w1->draw = draw_npc;
ranroun3 8:89dee5f187ba 217 w1->walkable = false;
ranroun3 8:89dee5f187ba 218 newNPC *npc1 = (newNPC*) malloc(sizeof(newNPC));
ranroun3 8:89dee5f187ba 219 npc1 -> x = x;
ranroun3 8:89dee5f187ba 220 npc1 -> y = y;
ranroun3 8:89dee5f187ba 221 npc1 -> state = 0;
ranroun3 8:89dee5f187ba 222 w1->data = npc1;
ranroun3 8:89dee5f187ba 223 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 8:89dee5f187ba 224 if (val) free(val); // If something is already there, free it
ranroun3 8:89dee5f187ba 225 }
ranroun3 8:89dee5f187ba 226
ranroun3 8:89dee5f187ba 227
ranroun3 18:e91acccede4d 228 void add_boss(int x, int y, int corrSpell, int num)
ranroun3 8:89dee5f187ba 229 {
ranroun3 8:89dee5f187ba 230 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 8:89dee5f187ba 231 w1->type = BOSS;
ranroun3 8:89dee5f187ba 232 w1->draw = draw_boss;
ranroun3 8:89dee5f187ba 233 w1->walkable = false;
ranroun3 9:f3c1d9f78c44 234 bossChar *b1 = (bossChar*) malloc(sizeof(bossChar));
ranroun3 9:f3c1d9f78c44 235 b1 -> x = x;
ranroun3 9:f3c1d9f78c44 236 b1 -> y = y;
ranroun3 9:f3c1d9f78c44 237 b1 -> state = 0;
ranroun3 9:f3c1d9f78c44 238 b1 -> correctSpell = corrSpell;
ranroun3 18:e91acccede4d 239 b1 -> numBoss = num;
ranroun3 9:f3c1d9f78c44 240 w1->data = b1;
ranroun3 9:f3c1d9f78c44 241 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 9:f3c1d9f78c44 242 if (val) free(val); // If something is already there, free it
ranroun3 9:f3c1d9f78c44 243 }
ranroun3 9:f3c1d9f78c44 244
ranroun3 9:f3c1d9f78c44 245 void add_spell(int x, int y, int spellType)
ranroun3 9:f3c1d9f78c44 246 {
ranroun3 9:f3c1d9f78c44 247 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 9:f3c1d9f78c44 248 w1->type = SPELL;
ranroun3 9:f3c1d9f78c44 249
ranroun3 9:f3c1d9f78c44 250 w1->walkable = true;
ranroun3 9:f3c1d9f78c44 251 Spell *s1 = (Spell*) malloc(sizeof(Spell));
ranroun3 9:f3c1d9f78c44 252 s1 -> x = x;
ranroun3 9:f3c1d9f78c44 253 s1 -> y = y;
ranroun3 9:f3c1d9f78c44 254 s1 -> spell_type = spellType;
ranroun3 17:f20f4f3cc4ee 255 if(spellType == LAVA) {
ranroun3 9:f3c1d9f78c44 256 w1->draw = draw_fire;
ranroun3 9:f3c1d9f78c44 257 }
ranroun3 9:f3c1d9f78c44 258 if(spellType == WATER) {
ranroun3 9:f3c1d9f78c44 259 w1->draw = draw_water;
ranroun3 9:f3c1d9f78c44 260 }
ranroun3 9:f3c1d9f78c44 261 if(spellType == TACO) {
ranroun3 9:f3c1d9f78c44 262 w1->draw = draw_taco;
ranroun3 9:f3c1d9f78c44 263 }
ranroun3 18:e91acccede4d 264 if(spellType == REDSP) {
ranroun3 18:e91acccede4d 265 w1->draw = draw_red;
ranroun3 18:e91acccede4d 266 }
ranroun3 18:e91acccede4d 267 if(spellType == BLUESP) {
ranroun3 18:e91acccede4d 268 w1-> draw = draw_blue;
ranroun3 18:e91acccede4d 269 }
ranroun3 9:f3c1d9f78c44 270 w1->data = s1;
ranroun3 8:89dee5f187ba 271 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 8:89dee5f187ba 272 if (val) free(val); // If something is already there, free it
ranroun3 11:8f55aebf67a4 273 }
ranroun3 11:8f55aebf67a4 274
ranroun3 11:8f55aebf67a4 275 void add_door(int x, int y, int xLen, int yLen)
ranroun3 11:8f55aebf67a4 276 {
ranroun3 11:8f55aebf67a4 277 for(int i = 0; i < xLen; i++) {
ranroun3 11:8f55aebf67a4 278 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 279 w1->type = DOOR;
ranroun3 11:8f55aebf67a4 280 w1->draw = draw_door;
ranroun3 11:8f55aebf67a4 281 w1->walkable = false;
ranroun3 11:8f55aebf67a4 282 Door *d1 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 283 d1->startX = x;
ranroun3 11:8f55aebf67a4 284 d1->startY = y;
ranroun3 11:8f55aebf67a4 285 d1->endX = x + xLen;
ranroun3 11:8f55aebf67a4 286 d1->endY = y + yLen;
ranroun3 11:8f55aebf67a4 287 d1->isLocked = true;
ranroun3 11:8f55aebf67a4 288 w1->data = d1;
ranroun3 11:8f55aebf67a4 289 unsigned key = XY_KEY(x+i, y);
ranroun3 11:8f55aebf67a4 290 void* val = insertItem(get_active_map()->items, key, w1);
ranroun3 11:8f55aebf67a4 291 if (val) free(val); // If something is already there, free it
ranroun3 12:1735353dc298 292
ranroun3 11:8f55aebf67a4 293 MapItem* w2 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 294 w2->type = DOOR;
ranroun3 11:8f55aebf67a4 295 w2->draw = draw_door;
ranroun3 11:8f55aebf67a4 296 w2->walkable = false;
ranroun3 11:8f55aebf67a4 297 Door *d2 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 298 d2->startX = x;
ranroun3 11:8f55aebf67a4 299 d2->startY = y;
ranroun3 11:8f55aebf67a4 300 d2->endX = x + xLen;
ranroun3 11:8f55aebf67a4 301 d2->endY = y + yLen;
ranroun3 11:8f55aebf67a4 302 d2->isLocked = true;
ranroun3 11:8f55aebf67a4 303 w2->data = d2;
ranroun3 11:8f55aebf67a4 304 unsigned key2 = XY_KEY(x+i, y+yLen);
ranroun3 11:8f55aebf67a4 305 void* val2 = insertItem(get_active_map()->items, key2, w2);
ranroun3 11:8f55aebf67a4 306 if (val2) free(val2); // If something is already there, free it
ranroun3 11:8f55aebf67a4 307 }
ranroun3 12:1735353dc298 308
ranroun3 11:8f55aebf67a4 309 for(int i = 0; i <= yLen; i++) {
ranroun3 11:8f55aebf67a4 310 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 311 w1->type = DOOR;
ranroun3 11:8f55aebf67a4 312 w1->draw = draw_door;
ranroun3 11:8f55aebf67a4 313 w1->walkable = false;
ranroun3 11:8f55aebf67a4 314 Door *d1 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 315 d1->startX = x;
ranroun3 11:8f55aebf67a4 316 d1->startY = y;
ranroun3 11:8f55aebf67a4 317 d1->endX = x + xLen;
ranroun3 11:8f55aebf67a4 318 d1->endY = y + yLen;
ranroun3 11:8f55aebf67a4 319 d1->isLocked = true;
ranroun3 11:8f55aebf67a4 320 w1->data = d1;
ranroun3 11:8f55aebf67a4 321 unsigned key = XY_KEY(x, y+i);
ranroun3 11:8f55aebf67a4 322 void* val = insertItem(get_active_map()->items, key, w1);
ranroun3 11:8f55aebf67a4 323 if (val) free(val); // If something is already there, free it
ranroun3 12:1735353dc298 324
ranroun3 11:8f55aebf67a4 325 MapItem* w2 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 326 w2->type = DOOR;
ranroun3 11:8f55aebf67a4 327 w2->draw = draw_door;
ranroun3 11:8f55aebf67a4 328 w2->walkable = false;
ranroun3 11:8f55aebf67a4 329 Door *d2 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 330 d2->startX = x;
ranroun3 11:8f55aebf67a4 331 d2->startY = y;
ranroun3 11:8f55aebf67a4 332 d2->endX = x + xLen;
ranroun3 11:8f55aebf67a4 333 d2->endY = y + yLen;
ranroun3 11:8f55aebf67a4 334 d2->isLocked = true;
ranroun3 11:8f55aebf67a4 335 w2->data = d2;
ranroun3 11:8f55aebf67a4 336 unsigned key2 = XY_KEY(x+xLen, y+i);
ranroun3 11:8f55aebf67a4 337 void* val2 = insertItem(get_active_map()->items, key2, w2);
ranroun3 11:8f55aebf67a4 338 if (val2) free(val2); // If something is already there, free it
ranroun3 11:8f55aebf67a4 339 }
ranroun3 12:1735353dc298 340
ranroun3 12:1735353dc298 341
ranroun3 12:1735353dc298 342 }
ranroun3 12:1735353dc298 343
ranroun3 18:e91acccede4d 344 void add_treasure(int x, int y)
ranroun3 18:e91acccede4d 345 {
ranroun3 12:1735353dc298 346 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 12:1735353dc298 347 w1->type = TREASURE;
ranroun3 12:1735353dc298 348 w1->draw = draw_treasure;
ranroun3 12:1735353dc298 349 w1->walkable = false;
ranroun3 12:1735353dc298 350 Treasure *t1 = (Treasure*) malloc(sizeof(Treasure));
ranroun3 12:1735353dc298 351 t1 -> x = x;
ranroun3 12:1735353dc298 352 t1 -> y = y;
ranroun3 12:1735353dc298 353 t1 -> isClaimed = false;
ranroun3 12:1735353dc298 354 w1->data = t1;
ranroun3 12:1735353dc298 355 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 12:1735353dc298 356 if (val) free(val); // If something is already there, free it
ranroun3 18:e91acccede4d 357 }
ranroun3 18:e91acccede4d 358
ranroun3 18:e91acccede4d 359 void add_dead(int x, int y)
ranroun3 18:e91acccede4d 360 {
ranroun3 18:e91acccede4d 361 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 18:e91acccede4d 362 w1->type = DEAD;
ranroun3 18:e91acccede4d 363 w1->draw = draw_dead;
ranroun3 18:e91acccede4d 364 w1->walkable = true;
ranroun3 18:e91acccede4d 365 w1->data = NULL;
ranroun3 18:e91acccede4d 366 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 18:e91acccede4d 367 if (val) free(val); // If something is already there, free it
ranroun3 18:e91acccede4d 368 }
ranroun3 18:e91acccede4d 369
ranroun3 20:762297435411 370 void add_hammer(int x, int y)
ranroun3 20:762297435411 371 {
ranroun3 20:762297435411 372 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 20:762297435411 373 w1->type = HAMMER;
ranroun3 20:762297435411 374 w1->draw = draw_hammer;
ranroun3 20:762297435411 375 w1->walkable = true;
ranroun3 20:762297435411 376 w1->data = NULL;
ranroun3 20:762297435411 377 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 20:762297435411 378 if (val) free(val); // If something is already there, free it
ranroun3 20:762297435411 379 }
ranroun3 20:762297435411 380 void add_healthPotion(int x, int y)
ranroun3 20:762297435411 381 {
ranroun3 20:762297435411 382 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 20:762297435411 383 w1->type = POTION;
ranroun3 20:762297435411 384 w1->draw = draw_healthPotion;
ranroun3 20:762297435411 385 w1->walkable = true;
ranroun3 20:762297435411 386 w1->data = NULL;
ranroun3 20:762297435411 387 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 20:762297435411 388 if (val) free(val); // If something is already there, free it
ranroun3 20:762297435411 389 }
ranroun3 20:762297435411 390
ranroun3 20:762297435411 391 void add_heart(int x, int y)
ranroun3 20:762297435411 392 {
ranroun3 20:762297435411 393 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 20:762297435411 394 w1->type = HEART;
ranroun3 20:762297435411 395 w1->draw = draw_heart;
ranroun3 20:762297435411 396 w1->walkable = true;
ranroun3 20:762297435411 397 w1->data = NULL;
ranroun3 20:762297435411 398 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 20:762297435411 399 if (val) free(val); // If something is already there, free it
ranroun3 20:762297435411 400 }
ranroun3 20:762297435411 401