2035 project 2

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
ranroun3
Date:
Wed Dec 01 23:39:02 2021 +0000
Revision:
23:06cbe894690d
Parent:
22:397601b1cdb4
FINAL p2-2;

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 }
ranroun3 22:397601b1cdb4 85 int get_active_map_int(){
ranroun3 22:397601b1cdb4 86
ranroun3 22:397601b1cdb4 87 return active_map;
ranroun3 22:397601b1cdb4 88 }
rconnorlawson 0:35660d7952f7 89
rconnorlawson 0:35660d7952f7 90 Map* set_active_map(int m)
rconnorlawson 0:35660d7952f7 91 {
rconnorlawson 0:35660d7952f7 92 active_map = m;
ranroun3 6:291aef457c4e 93 return &map[active_map];
rconnorlawson 0:35660d7952f7 94 }
rconnorlawson 0:35660d7952f7 95
rconnorlawson 0:35660d7952f7 96 void print_map()
rconnorlawson 0:35660d7952f7 97 {
rconnorlawson 0:35660d7952f7 98 // As you add more types, you'll need to add more items to this array.
rconnorlawson 0:35660d7952f7 99 char lookup[] = {'W', 'P'};
ranroun3 8:89dee5f187ba 100 for(int y = 0; y < map_height(); y++) {
ranroun3 8:89dee5f187ba 101 for (int x = 0; x < map_width(); x++) {
rconnorlawson 0:35660d7952f7 102 MapItem* item = get_here(x,y);
rconnorlawson 0:35660d7952f7 103 if (item) pc.printf("%c", lookup[item->type]);
rconnorlawson 0:35660d7952f7 104 else pc.printf(" ");
rconnorlawson 0:35660d7952f7 105 }
rconnorlawson 0:35660d7952f7 106 pc.printf("\r\n");
rconnorlawson 0:35660d7952f7 107 }
rconnorlawson 0:35660d7952f7 108 }
rconnorlawson 0:35660d7952f7 109
rconnorlawson 0:35660d7952f7 110 int map_width()
rconnorlawson 0:35660d7952f7 111 {
ranroun3 6:291aef457c4e 112 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 113 return currMap->w;
rconnorlawson 0:35660d7952f7 114 }
rconnorlawson 0:35660d7952f7 115
rconnorlawson 0:35660d7952f7 116 int map_height()
rconnorlawson 0:35660d7952f7 117 {
ranroun3 6:291aef457c4e 118 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 119 return currMap->h;
rconnorlawson 0:35660d7952f7 120 }
rconnorlawson 0:35660d7952f7 121
rconnorlawson 0:35660d7952f7 122 int map_area()
rconnorlawson 0:35660d7952f7 123 {
ranroun3 6:291aef457c4e 124 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 125 int area = (currMap-> h) * currMap-> w;
ranroun3 6:291aef457c4e 126 return area;
rconnorlawson 0:35660d7952f7 127 }
rconnorlawson 0:35660d7952f7 128
rconnorlawson 0:35660d7952f7 129 MapItem* get_north(int x, int y)
rconnorlawson 0:35660d7952f7 130 {
ranroun3 6:291aef457c4e 131 MapItem* currItem = get_here(x, y - 1);
ranroun3 6:291aef457c4e 132 return currItem;
rconnorlawson 0:35660d7952f7 133 }
rconnorlawson 0:35660d7952f7 134
rconnorlawson 0:35660d7952f7 135 MapItem* get_south(int x, int y)
rconnorlawson 0:35660d7952f7 136 {
ranroun3 6:291aef457c4e 137 MapItem* currItem = get_here(x, y + 1);
ranroun3 6:291aef457c4e 138 return currItem;
rconnorlawson 0:35660d7952f7 139 }
rconnorlawson 0:35660d7952f7 140
rconnorlawson 0:35660d7952f7 141 MapItem* get_east(int x, int y)
rconnorlawson 0:35660d7952f7 142 {
ranroun3 6:291aef457c4e 143 MapItem* currItem = get_here(x + 1, y);
ranroun3 6:291aef457c4e 144 return currItem;
rconnorlawson 0:35660d7952f7 145 }
rconnorlawson 0:35660d7952f7 146
rconnorlawson 0:35660d7952f7 147 MapItem* get_west(int x, int y)
rconnorlawson 0:35660d7952f7 148 {
ranroun3 6:291aef457c4e 149 MapItem* currItem = get_here(x - 1, y);
ranroun3 6:291aef457c4e 150 return currItem;
rconnorlawson 0:35660d7952f7 151 }
rconnorlawson 0:35660d7952f7 152
rconnorlawson 0:35660d7952f7 153 MapItem* get_here(int x, int y)
rconnorlawson 0:35660d7952f7 154 {
ranroun3 6:291aef457c4e 155 Map* currMap = get_active_map();
ranroun3 6:291aef457c4e 156 unsigned key = XY_KEY(x, y);
ranroun3 6:291aef457c4e 157 MapItem* currItem = (MapItem*)getItem(currMap->items, key);
ranroun3 6:291aef457c4e 158 return currItem;
rconnorlawson 0:35660d7952f7 159 }
rconnorlawson 0:35660d7952f7 160
rconnorlawson 0:35660d7952f7 161
rconnorlawson 0:35660d7952f7 162 void map_erase(int x, int y)
rconnorlawson 0:35660d7952f7 163 {
ranroun3 6:291aef457c4e 164 Map* curr = get_active_map();
ranroun3 6:291aef457c4e 165 unsigned key = XY_KEY(x, y);
ranroun3 6:291aef457c4e 166 MapItem* currItem = (MapItem*) getItem(curr->items, key);
ranroun3 8:89dee5f187ba 167 if(currItem) {
ranroun3 6:291aef457c4e 168 deleteItem(curr->items, key);
ranroun3 6:291aef457c4e 169 }
ranroun3 8:89dee5f187ba 170
rconnorlawson 0:35660d7952f7 171 }
rconnorlawson 0:35660d7952f7 172
rconnorlawson 0:35660d7952f7 173 void add_wall(int x, int y, int dir, int len)
rconnorlawson 0:35660d7952f7 174 {
ranroun3 8:89dee5f187ba 175 for(int i = 0; i < len; i++) {
rconnorlawson 0:35660d7952f7 176 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
rconnorlawson 0:35660d7952f7 177 w1->type = WALL;
rconnorlawson 0:35660d7952f7 178 w1->draw = draw_wall;
rconnorlawson 0:35660d7952f7 179 w1->walkable = false;
rconnorlawson 0:35660d7952f7 180 w1->data = NULL;
rconnorlawson 0:35660d7952f7 181 unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y) : XY_KEY(x, y+i);
rconnorlawson 0:35660d7952f7 182 void* val = insertItem(get_active_map()->items, key, w1);
rconnorlawson 0:35660d7952f7 183 if (val) free(val); // If something is already there, free it
rconnorlawson 0:35660d7952f7 184 }
rconnorlawson 0:35660d7952f7 185 }
rconnorlawson 0:35660d7952f7 186
rconnorlawson 0:35660d7952f7 187 void add_plant(int x, int y)
rconnorlawson 0:35660d7952f7 188 {
rconnorlawson 0:35660d7952f7 189 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
rconnorlawson 0:35660d7952f7 190 w1->type = PLANT;
rconnorlawson 0:35660d7952f7 191 w1->draw = draw_plant;
rconnorlawson 0:35660d7952f7 192 w1->walkable = true;
rconnorlawson 0:35660d7952f7 193 w1->data = NULL;
rconnorlawson 0:35660d7952f7 194 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
rconnorlawson 0:35660d7952f7 195 if (val) free(val); // If something is already there, free it
ranroun3 6:291aef457c4e 196 }
ranroun3 6:291aef457c4e 197
ranroun3 6:291aef457c4e 198 void add_stairs(int x, int y, int newX, int newY, int newMap)
ranroun3 6:291aef457c4e 199 {
ranroun3 8:89dee5f187ba 200 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 6:291aef457c4e 201 w1->type = STAIRS;
ranroun3 6:291aef457c4e 202 w1->draw = draw_stairs;
ranroun3 6:291aef457c4e 203 w1->walkable = true;
ranroun3 6:291aef457c4e 204 StairsData *s1 = (StairsData*) malloc(sizeof(StairsData));
ranroun3 6:291aef457c4e 205 s1 -> tx = newX;
ranroun3 6:291aef457c4e 206 s1 -> ty = newY;
ranroun3 6:291aef457c4e 207 s1 -> tm = newMap;
ranroun3 6:291aef457c4e 208 s1 -> isLocked = 0;
ranroun3 6:291aef457c4e 209 w1->data = s1;
ranroun3 6:291aef457c4e 210 //stairs struct goes here
ranroun3 6:291aef457c4e 211 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 8:89dee5f187ba 212 if (val) free(val); // If something is already there, free it
ranroun3 8:89dee5f187ba 213
ranroun3 8:89dee5f187ba 214 }
ranroun3 8:89dee5f187ba 215
ranroun3 8:89dee5f187ba 216 void add_npc(int x, int y)
ranroun3 8:89dee5f187ba 217 {
ranroun3 8:89dee5f187ba 218 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 8:89dee5f187ba 219 w1->type = NPC;
ranroun3 8:89dee5f187ba 220 w1->draw = draw_npc;
ranroun3 8:89dee5f187ba 221 w1->walkable = false;
ranroun3 8:89dee5f187ba 222 newNPC *npc1 = (newNPC*) malloc(sizeof(newNPC));
ranroun3 8:89dee5f187ba 223 npc1 -> x = x;
ranroun3 8:89dee5f187ba 224 npc1 -> y = y;
ranroun3 8:89dee5f187ba 225 npc1 -> state = 0;
ranroun3 8:89dee5f187ba 226 w1->data = npc1;
ranroun3 8:89dee5f187ba 227 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 8:89dee5f187ba 228 if (val) free(val); // If something is already there, free it
ranroun3 8:89dee5f187ba 229 }
ranroun3 8:89dee5f187ba 230
ranroun3 8:89dee5f187ba 231
ranroun3 18:e91acccede4d 232 void add_boss(int x, int y, int corrSpell, int num)
ranroun3 8:89dee5f187ba 233 {
ranroun3 8:89dee5f187ba 234 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 8:89dee5f187ba 235 w1->type = BOSS;
ranroun3 8:89dee5f187ba 236 w1->draw = draw_boss;
ranroun3 8:89dee5f187ba 237 w1->walkable = false;
ranroun3 9:f3c1d9f78c44 238 bossChar *b1 = (bossChar*) malloc(sizeof(bossChar));
ranroun3 9:f3c1d9f78c44 239 b1 -> x = x;
ranroun3 9:f3c1d9f78c44 240 b1 -> y = y;
ranroun3 9:f3c1d9f78c44 241 b1 -> state = 0;
ranroun3 9:f3c1d9f78c44 242 b1 -> correctSpell = corrSpell;
ranroun3 18:e91acccede4d 243 b1 -> numBoss = num;
ranroun3 9:f3c1d9f78c44 244 w1->data = b1;
ranroun3 9:f3c1d9f78c44 245 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 9:f3c1d9f78c44 246 if (val) free(val); // If something is already there, free it
ranroun3 9:f3c1d9f78c44 247 }
ranroun3 9:f3c1d9f78c44 248
ranroun3 9:f3c1d9f78c44 249 void add_spell(int x, int y, int spellType)
ranroun3 9:f3c1d9f78c44 250 {
ranroun3 9:f3c1d9f78c44 251 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 9:f3c1d9f78c44 252 w1->type = SPELL;
ranroun3 9:f3c1d9f78c44 253
ranroun3 9:f3c1d9f78c44 254 w1->walkable = true;
ranroun3 9:f3c1d9f78c44 255 Spell *s1 = (Spell*) malloc(sizeof(Spell));
ranroun3 9:f3c1d9f78c44 256 s1 -> x = x;
ranroun3 9:f3c1d9f78c44 257 s1 -> y = y;
ranroun3 9:f3c1d9f78c44 258 s1 -> spell_type = spellType;
ranroun3 17:f20f4f3cc4ee 259 if(spellType == LAVA) {
ranroun3 9:f3c1d9f78c44 260 w1->draw = draw_fire;
ranroun3 9:f3c1d9f78c44 261 }
ranroun3 9:f3c1d9f78c44 262 if(spellType == WATER) {
ranroun3 9:f3c1d9f78c44 263 w1->draw = draw_water;
ranroun3 9:f3c1d9f78c44 264 }
ranroun3 9:f3c1d9f78c44 265 if(spellType == TACO) {
ranroun3 9:f3c1d9f78c44 266 w1->draw = draw_taco;
ranroun3 9:f3c1d9f78c44 267 }
ranroun3 18:e91acccede4d 268 if(spellType == REDSP) {
ranroun3 18:e91acccede4d 269 w1->draw = draw_red;
ranroun3 18:e91acccede4d 270 }
ranroun3 18:e91acccede4d 271 if(spellType == BLUESP) {
ranroun3 18:e91acccede4d 272 w1-> draw = draw_blue;
ranroun3 18:e91acccede4d 273 }
ranroun3 9:f3c1d9f78c44 274 w1->data = s1;
ranroun3 8:89dee5f187ba 275 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 8:89dee5f187ba 276 if (val) free(val); // If something is already there, free it
ranroun3 11:8f55aebf67a4 277 }
ranroun3 11:8f55aebf67a4 278
ranroun3 11:8f55aebf67a4 279 void add_door(int x, int y, int xLen, int yLen)
ranroun3 11:8f55aebf67a4 280 {
ranroun3 11:8f55aebf67a4 281 for(int i = 0; i < xLen; i++) {
ranroun3 11:8f55aebf67a4 282 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 283 w1->type = DOOR;
ranroun3 11:8f55aebf67a4 284 w1->draw = draw_door;
ranroun3 11:8f55aebf67a4 285 w1->walkable = false;
ranroun3 11:8f55aebf67a4 286 Door *d1 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 287 d1->startX = x;
ranroun3 11:8f55aebf67a4 288 d1->startY = y;
ranroun3 11:8f55aebf67a4 289 d1->endX = x + xLen;
ranroun3 11:8f55aebf67a4 290 d1->endY = y + yLen;
ranroun3 11:8f55aebf67a4 291 d1->isLocked = true;
ranroun3 11:8f55aebf67a4 292 w1->data = d1;
ranroun3 11:8f55aebf67a4 293 unsigned key = XY_KEY(x+i, y);
ranroun3 11:8f55aebf67a4 294 void* val = insertItem(get_active_map()->items, key, w1);
ranroun3 11:8f55aebf67a4 295 if (val) free(val); // If something is already there, free it
ranroun3 12:1735353dc298 296
ranroun3 11:8f55aebf67a4 297 MapItem* w2 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 298 w2->type = DOOR;
ranroun3 11:8f55aebf67a4 299 w2->draw = draw_door;
ranroun3 11:8f55aebf67a4 300 w2->walkable = false;
ranroun3 11:8f55aebf67a4 301 Door *d2 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 302 d2->startX = x;
ranroun3 11:8f55aebf67a4 303 d2->startY = y;
ranroun3 11:8f55aebf67a4 304 d2->endX = x + xLen;
ranroun3 11:8f55aebf67a4 305 d2->endY = y + yLen;
ranroun3 11:8f55aebf67a4 306 d2->isLocked = true;
ranroun3 11:8f55aebf67a4 307 w2->data = d2;
ranroun3 11:8f55aebf67a4 308 unsigned key2 = XY_KEY(x+i, y+yLen);
ranroun3 11:8f55aebf67a4 309 void* val2 = insertItem(get_active_map()->items, key2, w2);
ranroun3 11:8f55aebf67a4 310 if (val2) free(val2); // If something is already there, free it
ranroun3 11:8f55aebf67a4 311 }
ranroun3 12:1735353dc298 312
ranroun3 11:8f55aebf67a4 313 for(int i = 0; i <= yLen; i++) {
ranroun3 11:8f55aebf67a4 314 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 315 w1->type = DOOR;
ranroun3 11:8f55aebf67a4 316 w1->draw = draw_door;
ranroun3 11:8f55aebf67a4 317 w1->walkable = false;
ranroun3 11:8f55aebf67a4 318 Door *d1 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 319 d1->startX = x;
ranroun3 11:8f55aebf67a4 320 d1->startY = y;
ranroun3 11:8f55aebf67a4 321 d1->endX = x + xLen;
ranroun3 11:8f55aebf67a4 322 d1->endY = y + yLen;
ranroun3 11:8f55aebf67a4 323 d1->isLocked = true;
ranroun3 11:8f55aebf67a4 324 w1->data = d1;
ranroun3 11:8f55aebf67a4 325 unsigned key = XY_KEY(x, y+i);
ranroun3 11:8f55aebf67a4 326 void* val = insertItem(get_active_map()->items, key, w1);
ranroun3 11:8f55aebf67a4 327 if (val) free(val); // If something is already there, free it
ranroun3 12:1735353dc298 328
ranroun3 11:8f55aebf67a4 329 MapItem* w2 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 11:8f55aebf67a4 330 w2->type = DOOR;
ranroun3 11:8f55aebf67a4 331 w2->draw = draw_door;
ranroun3 11:8f55aebf67a4 332 w2->walkable = false;
ranroun3 11:8f55aebf67a4 333 Door *d2 = (Door*) malloc(sizeof(Door));
ranroun3 11:8f55aebf67a4 334 d2->startX = x;
ranroun3 11:8f55aebf67a4 335 d2->startY = y;
ranroun3 11:8f55aebf67a4 336 d2->endX = x + xLen;
ranroun3 11:8f55aebf67a4 337 d2->endY = y + yLen;
ranroun3 11:8f55aebf67a4 338 d2->isLocked = true;
ranroun3 11:8f55aebf67a4 339 w2->data = d2;
ranroun3 11:8f55aebf67a4 340 unsigned key2 = XY_KEY(x+xLen, y+i);
ranroun3 11:8f55aebf67a4 341 void* val2 = insertItem(get_active_map()->items, key2, w2);
ranroun3 11:8f55aebf67a4 342 if (val2) free(val2); // If something is already there, free it
ranroun3 11:8f55aebf67a4 343 }
ranroun3 12:1735353dc298 344
ranroun3 12:1735353dc298 345
ranroun3 12:1735353dc298 346 }
ranroun3 12:1735353dc298 347
ranroun3 18:e91acccede4d 348 void add_treasure(int x, int y)
ranroun3 18:e91acccede4d 349 {
ranroun3 12:1735353dc298 350 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 12:1735353dc298 351 w1->type = TREASURE;
ranroun3 12:1735353dc298 352 w1->draw = draw_treasure;
ranroun3 12:1735353dc298 353 w1->walkable = false;
ranroun3 12:1735353dc298 354 Treasure *t1 = (Treasure*) malloc(sizeof(Treasure));
ranroun3 12:1735353dc298 355 t1 -> x = x;
ranroun3 12:1735353dc298 356 t1 -> y = y;
ranroun3 12:1735353dc298 357 t1 -> isClaimed = false;
ranroun3 12:1735353dc298 358 w1->data = t1;
ranroun3 12:1735353dc298 359 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 12:1735353dc298 360 if (val) free(val); // If something is already there, free it
ranroun3 18:e91acccede4d 361 }
ranroun3 18:e91acccede4d 362
ranroun3 18:e91acccede4d 363 void add_dead(int x, int y)
ranroun3 18:e91acccede4d 364 {
ranroun3 18:e91acccede4d 365 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 18:e91acccede4d 366 w1->type = DEAD;
ranroun3 18:e91acccede4d 367 w1->draw = draw_dead;
ranroun3 18:e91acccede4d 368 w1->walkable = true;
ranroun3 18:e91acccede4d 369 w1->data = NULL;
ranroun3 18:e91acccede4d 370 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 18:e91acccede4d 371 if (val) free(val); // If something is already there, free it
ranroun3 18:e91acccede4d 372 }
ranroun3 18:e91acccede4d 373
ranroun3 20:762297435411 374 void add_hammer(int x, int y)
ranroun3 20:762297435411 375 {
ranroun3 20:762297435411 376 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 20:762297435411 377 w1->type = HAMMER;
ranroun3 20:762297435411 378 w1->draw = draw_hammer;
ranroun3 20:762297435411 379 w1->walkable = true;
ranroun3 20:762297435411 380 w1->data = NULL;
ranroun3 20:762297435411 381 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 20:762297435411 382 if (val) free(val); // If something is already there, free it
ranroun3 20:762297435411 383 }
ranroun3 20:762297435411 384 void add_healthPotion(int x, int y)
ranroun3 20:762297435411 385 {
ranroun3 20:762297435411 386 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 20:762297435411 387 w1->type = POTION;
ranroun3 20:762297435411 388 w1->draw = draw_healthPotion;
ranroun3 20:762297435411 389 w1->walkable = true;
ranroun3 20:762297435411 390 w1->data = NULL;
ranroun3 20:762297435411 391 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 20:762297435411 392 if (val) free(val); // If something is already there, free it
ranroun3 20:762297435411 393 }
ranroun3 20:762297435411 394
ranroun3 20:762297435411 395 void add_heart(int x, int y)
ranroun3 20:762297435411 396 {
ranroun3 20:762297435411 397 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 20:762297435411 398 w1->type = HEART;
ranroun3 20:762297435411 399 w1->draw = draw_heart;
ranroun3 20:762297435411 400 w1->walkable = true;
ranroun3 20:762297435411 401 w1->data = NULL;
ranroun3 20:762297435411 402 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 20:762297435411 403 if (val) free(val); // If something is already there, free it
ranroun3 20:762297435411 404 }
ranroun3 20:762297435411 405
ranroun3 22:397601b1cdb4 406 void add_key(int x, int y)
ranroun3 22:397601b1cdb4 407 {
ranroun3 22:397601b1cdb4 408 MapItem* w1 = (MapItem*) malloc(sizeof(MapItem));
ranroun3 22:397601b1cdb4 409 w1->type = KEY;
ranroun3 22:397601b1cdb4 410 w1->draw = draw_key;
ranroun3 22:397601b1cdb4 411 w1->walkable = true;
ranroun3 22:397601b1cdb4 412 w1->data = NULL;
ranroun3 22:397601b1cdb4 413 void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1);
ranroun3 22:397601b1cdb4 414 if (val) free(val); // If something is already there, free it
ranroun3 22:397601b1cdb4 415 }