![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Adventure game written for ECE2035 at the Georgia Institute of Technology
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Diff: map.cpp
- Revision:
- 4:cdc54191ff07
- Parent:
- 3:289762133fd6
--- a/map.cpp Wed Apr 18 20:18:51 2018 +0000 +++ b/map.cpp Tue May 22 19:13:03 2018 +0000 @@ -14,7 +14,7 @@ * This is a global variable, but can only be access from this file because it * is static. */ -static Map maps[2]; +static Map maps[3]; static int active_map; /** @@ -136,17 +136,6 @@ deleteItem(map->items, index); } -void omni(){ - Map* map = get_active_map(); - int h = map -> h; - int w = map -> w; - for (int i = 0; i < h; i++){ - for(int j = 0; j < w; j++){ - MapItem* object = (MapItem*)getItem(map->items, XY_KEY(i,j)); - if(object) object -> walkable = true; - } - } -} void add_wall(int x, int y, int dir, int len) { @@ -163,6 +152,74 @@ } } +/*void add_road(int x, int y, int dir, int len) +{ + for(int i = 0; i < len; i++) + { + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = ROAD; + w1->draw = draw_wall; + w1->walkable = true; + w1->data = NULL; + unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y) : XY_KEY(x, y+i); + void* val = insertItem(get_active_map()->items, key, w1); + if (val) free(val); // If something is already there, free it + } +}*/ + +void add_lbush(int x, int y, int key){ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = LBUSH; + w1->draw = draw_lbush; + w1->walkable = true; + MapItem* w2 = (MapItem*) malloc(sizeof(MapItem)); + w2->type = LBUSH; + w2->draw = draw_lbush; + w2->walkable = true; + MapItem* w3 = (MapItem*) malloc(sizeof(MapItem)); + w3->type = LBUSH; + w3->draw = draw_lbush; + w3->walkable = true; + MapItem* w4 = (MapItem*) malloc(sizeof(MapItem)); + w4->type = LBUSH; + w4->draw = draw_lbush; + w4->walkable = true; + + Lbush* b1 = (Lbush*)malloc(sizeof(Lbush)); + b1 -> key = key; + + w1 -> data = b1; + w2 -> data = b1; + w3 -> data = b1; + w4 -> data = b1; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + if (val) free(val); // If something is already there, free it + void* val1 = insertItem(get_active_map()->items, XY_KEY(x+1, y), w2); + if (val1) free(val); // If something is already there, free it + void* val2 = insertItem(get_active_map()->items, XY_KEY(x, y+1), w3); + if (val2) free(val); // If something is already there, free it + void* val3 = insertItem(get_active_map()->items, XY_KEY(x+1, y+1), w4); + if (val3) free(val); // If something is already there, free it +} + +void add_bush_rect(int a, int b, int c, int d){ + + for(int i = a; i < c; i++){ + for(int j = b; j < d; j++){ + MapItem* b = (MapItem*) malloc(sizeof(MapItem)); + b->type = LBUSH; + b->draw = draw_lbush; + b->walkable = true; + + Lbush* bush = (Lbush*)malloc(sizeof(Lbush)); + bush -> key = XY_KEY(i,j); + b -> data = bush; + void* val = insertItem(get_active_map()->items, XY_KEY(i, j), b); + if (val) free(val); // If something is already there, free it + } + } +} + void add_plant(int x, int y) { MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); @@ -205,6 +262,21 @@ if (val) free(val); // If something is already there, free it } +void add_extra(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = EXTRA; + w1->draw = draw_npc; + w1->walkable = false; + Extra* npc = (Extra*) malloc(sizeof(Extra)); + npc -> x = x; + npc -> y = y; + npc -> e = false; + w1->data = npc; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + if (val) free(val); // If something is already there, free it +} + void add_door(int x, int y) { MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); @@ -217,6 +289,18 @@ if (val) free(val); // If something is already there, free it } +void add_gdoor(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = GDOOR; + w1->draw = draw_door; + w1->walkable = false; + int o = false; + w1->data = &o; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + if (val) free(val); // If something is already there, free it +} + void add_goal(int x, int y) { MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); @@ -234,9 +318,115 @@ MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); w1->type = SPIKE; w1->draw = draw_spike; - w1->walkable = false; + w1->walkable = true; int o = false; w1->data = &o; void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); if (val) free(val); // If something is already there, free it -} \ No newline at end of file +} + +void add_gem(int x, int y, int color) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = GEM; + int* c = &color; + if (color == 1){ + w1->draw = draw_gem1; + + } else if (color == 2){ + w1->draw = draw_gem2; + } else{ + w1->draw = draw_gem3; + } + w1->walkable = true; + w1->data = c; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + if (val) free(val); // If something is already there, free it +} + +void add_redhouse(int x, int y, int key){ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = HOUSE; + w1->draw = draw_rhouse1; + w1->walkable = false; + MapItem* w2 = (MapItem*) malloc(sizeof(MapItem)); + w2->type = HOUSE; + w2->draw = draw_rhouse2; + w2->walkable = false; + MapItem* w3 = (MapItem*) malloc(sizeof(MapItem)); + w3->type = HOUSE; + w3->draw = draw_rhouse2; + w3->walkable = false; + MapItem* w4 = (MapItem*) malloc(sizeof(MapItem)); + w4->type = HOUSE; + w4->draw = draw_rhouse1; + w4->walkable = false; + MapItem* w5 = (MapItem*) malloc(sizeof(MapItem)); + w5->type = HOUSE; + w5->draw = draw_rhouse2; + w5->walkable = false; + + House* r = (House*)malloc(sizeof(House)); + r -> key = key; + + w1 -> data = r; + w2 -> data = r; + w3 -> data = r; + w4 -> data = r; + w5 -> data = r; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + if (val) free(val); // If something is already there, free it + void* val1 = insertItem(get_active_map()->items, XY_KEY(x+1, y), w2); + if (val1) free(val); // If something is already there, free it + void* val2 = insertItem(get_active_map()->items, XY_KEY(x+1, y+1), w3); + if (val2) free(val); // If something is already there, free it + void* val3 = insertItem(get_active_map()->items, XY_KEY(x, y+2), w4); + if (val3) free(val); // If something is already there, free it + void* val4 = insertItem(get_active_map()->items, XY_KEY(x+1, y+2), w5); + if (val4) free(val); // If something is already there, free it + add_door(x, y+1); +} + + +void add_bluehouse(int x, int y, int key){ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = HOUSE; + w1->draw = draw_bhouse1; + w1->walkable = false; + MapItem* w2 = (MapItem*) malloc(sizeof(MapItem)); + w2->type = HOUSE; + w2->draw = draw_bhouse2; + w2->walkable = false; + MapItem* w3 = (MapItem*) malloc(sizeof(MapItem)); + w3->type = HOUSE; + w3->draw = draw_bhouse2; + w3->walkable = false; + MapItem* w4 = (MapItem*) malloc(sizeof(MapItem)); + w4->type = HOUSE; + w4->draw = draw_bhouse1; + w4->walkable = false; + MapItem* w5 = (MapItem*) malloc(sizeof(MapItem)); + w5->type = HOUSE; + w5->draw = draw_bhouse2; + w5->walkable = false; + + House* r = (House*)malloc(sizeof(House)); + r -> key = key; + + w1 -> data = r; + w2 -> data = r; + w3 -> data = r; + w4 -> data = r; + w5 -> data = r; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + if (val) free(val); // If something is already there, free it + void* val1 = insertItem(get_active_map()->items, XY_KEY(x+1, y), w2); + if (val1) free(val); // If something is already there, free it + void* val2 = insertItem(get_active_map()->items, XY_KEY(x+1, y+1), w3); + if (val2) free(val); // If something is already there, free it + void* val3 = insertItem(get_active_map()->items, XY_KEY(x, y+2), w4); + if (val3) free(val); // If something is already there, free it + void* val4 = insertItem(get_active_map()->items, XY_KEY(x+1, y+2), w5); + if (val4) free(val); // If something is already there, free it + add_door(x, y+1); +}