Randall Kliman / Mbed 2 deprecated NEOPUNK

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