Carter Montgomery / Mbed 2 deprecated 2035_Final_Project

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers map.h Source File

map.h

00001 #ifndef MAP_H
00002 #define MAP_H
00003 
00004 #include "hash_table.h"
00005 
00006 /**
00007  * A structure to represent the map. The implementation is private.
00008  */
00009 
00010 typedef struct {
00011     HashTable* items;
00012     int w, h;
00013 } Map;
00014 
00015 // A function pointer type for drawing MapItems.
00016 // All tiles are 11x11 blocks.
00017 // u,v is the top left corner pixel of the block
00018 typedef void (*DrawFunc)(int u, int v);
00019 
00020 /**
00021  * The data for elements in the map. Each item in the map HashTable is a
00022  * MapItem.
00023  */
00024 typedef struct {
00025     /**
00026      * Indicates the "type" of the MapItem: WALL, DOOR, PLANT, etc. This is
00027      * useful for determining how to interact with the object when updating the
00028      * game state.
00029      */
00030     int type;
00031     
00032     /**
00033      * A function pointer to the drawing function for this item. Used by draw_game.
00034      */
00035     DrawFunc draw;
00036     
00037     /**
00038      * If zero, this item should block character motion.
00039      */
00040     int walkable;
00041     
00042     /**
00043      * Arbitrary extra data for the MapItem. Could be useful for keeping up with
00044      * special information, like where a set of stairs should take the player.
00045      * 
00046      * Iterpretation of this can depend on the type of the MapItem. For example,
00047      * a WALL probably doesn't need to use this (it can be NULL), where an NPC
00048      * might use it to store game state (have I given the player the key yet?).
00049      */
00050     void* data;
00051 } MapItem;
00052 
00053 typedef struct{
00054     int x,y;    // Current locations
00055     int px, py; // Previous locations
00056     int quest_requested; //check to see if player has asked for quest
00057     int has_key;
00058     int quest_complete;
00059 } NonPlayer;
00060 
00061 typedef struct{
00062     int x,y;    // Current locations
00063     int px, py; // Previous locations
00064     int e;
00065 } Extra;
00066 
00067 typedef struct {
00068     int x,y;    // Current locations
00069     int px, py; // Previous locations
00070     int is_pushed;
00071     int wall_touch;
00072 } Rock;
00073 
00074 typedef struct {
00075     int key;
00076 } Lbush;
00077 
00078 typedef struct {
00079     int key;
00080 } House;
00081 
00082 
00083 typedef struct {
00084     int tm;
00085     int tx, ty;
00086 } StairsData;
00087 
00088 // MapItem types
00089 // Define more of these!
00090 #define WALL    0
00091 #define PLANT   1
00092 #define NPC     2
00093 #define ROCK    3
00094 #define DOOR    4
00095 #define GOAL    5
00096 #define SPIKE   6
00097 #define LBUSH   7
00098 #define GEM     8
00099 #define HOUSE   9
00100 #define GDOOR   10
00101 #define EXTRA   11
00102 
00103 /**
00104  * Initializes the internal structures for all maps. This does not populate
00105  * the map with items, but allocates space for them, initializes the hash tables, 
00106  * and sets the width and height.
00107  */
00108 void maps_init(int h, int w, int buckets);
00109 
00110 /**
00111  * Returns a pointer to the active map.
00112  */
00113 Map* get_active_map();
00114 
00115 /**
00116  * Sets the active map to map m, where m is the index of the map to activate.
00117  * Returns a pointer to the new active map.
00118  */
00119 Map* set_active_map(int m);
00120 
00121 /**
00122  * Returns the map m, regardless of whether it is the active map. This function
00123  * does not change the active map.
00124  */
00125 Map* get_map(int m);
00126 
00127 /**
00128  * Print the active map to the serial console.
00129  */
00130 void print_map();
00131 
00132 // Access
00133 /**
00134  * Returns the width of the active map.
00135  */
00136 int map_width();
00137 
00138 /**
00139  * Returns the heigh of the active map.
00140  */
00141 int map_height();
00142 
00143 /**
00144  * Returns the total number of cells in the active map.
00145  */
00146 int map_area();
00147 
00148 /**
00149  * Returns the MapItem immediately above the given location.
00150  */
00151 MapItem* get_north(int x, int y);
00152 
00153 /**
00154  * Returns the MapItem immediately below the given location.
00155  */
00156 MapItem* get_south(int x, int y);
00157 
00158 /**
00159  * Returns the MapItem immediately to the right of the given location.
00160  */
00161 MapItem* get_east(int x, int y);
00162 
00163 /**
00164  * Returns the MapItem immediately to the left of  the given location.
00165  */
00166 MapItem* get_west(int x, int y);
00167 
00168 /**
00169  * Returns the MapItem at the given location.
00170  */
00171 MapItem* get_here(int x, int y);
00172 
00173 // Directions, for using the modification functions
00174 #define HORIZONTAL  0
00175 #define VERTICAL    1
00176 
00177 /**
00178  * If there is a MapItem at (x,y), remove it from the map.
00179  */
00180 void map_erase(int x, int y);
00181 
00182 
00183 
00184 /**
00185  * Add WALL items in a line of length len beginning at (x,y).
00186  * If dir == HORIZONTAL, the line is in the direction of increasing x.
00187  * If dir == VERTICAL, the line is in the direction of increasing y.
00188  *
00189  * If there are already items in the map that collide with this line, they are
00190  * erased.
00191  */
00192 void add_wall(int x, int y, int dir, int len);
00193 
00194 /**
00195  * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it
00196  * before adding the plant.
00197  */
00198 void add_plant(int x, int y);
00199 void add_rock(int x, int y);
00200 void add_npc(int x, int y);
00201 void add_extra(int x, int y);
00202 void add_door(int x, int y);
00203 void add_gdoor(int x, int y);
00204 void add_goal(int x, int y);
00205 void add_spike(int x, int y);
00206 void add_lbush(int x, int y, int key);
00207 void add_gem(int x, int y, int color);
00208 void add_redhouse(int x, int y, int key);
00209 void add_bush_rect(int a, int b, int c, int d);
00210 void add_bluehouse(int x, int y, int key);
00211 #endif //MAP_H