Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
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 00038 /** 00039 * Arbitrary extra data for the MapItem. Could be useful for keeping up with 00040 * special information, like where a set of stairs should take the player. 00041 * 00042 * Iterpretation of this can depend on the type of the MapItem. For example, 00043 * a WALL probably doesn't need to use this (it can be NULL), where an NPC 00044 * might use it to store game state (have I given the player the key yet?). 00045 */ 00046 int data; 00047 } MapItem; 00048 00049 typedef struct { 00050 int tm; 00051 int tx, ty; 00052 } StairsData; 00053 00054 // MapItem types 00055 // Define more of these! 00056 #define WALL 0 00057 #define PLANT 1 00058 #define NPC 2 00059 #define CHEST 3 00060 #define CHESTT 16 00061 #define CASTL 4 00062 #define PORTAL 5 00063 #define DOOR 6 00064 #define DRAGON 7 00065 #define PORTAl 8 00066 #define KINDOM 9 00067 #define FRUIT 10 00068 #define VILL 11 00069 #define NPCT 12 00070 #define ENEMY1 13 00071 #define ENEMY2 14 00072 #define ENEMY 15 00073 #define KEY 17 00074 00075 00076 00077 00078 /** 00079 * Initializes the internal structures for all maps. This does not populate 00080 * the map with items, but allocates space for them, initializes the hash tables, 00081 * and sets the width and height. 00082 */ 00083 void maps_init(); 00084 00085 /** 00086 * Returns a pointer to the active map. 00087 */ 00088 Map* get_active_map(); 00089 00090 int get_current_map(); 00091 00092 /** 00093 * Sets the active map to map m, where m is the index of the map to activate. 00094 * Returns a pointer to the new active map. 00095 */ 00096 Map* set_active_map(int m); 00097 00098 /** 00099 * Returns the map m, regardless of whether it is the active map. This function 00100 * does not change the active map. 00101 */ 00102 int get_map(int m); 00103 00104 /** 00105 * Print the active map to the serial console. 00106 */ 00107 void print_map(); 00108 00109 // Access 00110 /** 00111 * Returns the width of the active map. 00112 */ 00113 int map_width(); 00114 00115 /** 00116 * Returns the heigh of the active map. 00117 */ 00118 int map_height(); 00119 00120 /** 00121 * Returns the total number of cells in the active map. 00122 */ 00123 int map_area(); 00124 00125 /** 00126 * Returns the MapItem immediately above the given location. 00127 */ 00128 MapItem* get_north(int x, int y); 00129 00130 /** 00131 * Returns the MapItem immediately below the given location. 00132 */ 00133 MapItem* get_south(int x, int y); 00134 00135 /** 00136 * Returns the MapItem immediately to the right of the given location. 00137 */ 00138 MapItem* get_east(int x, int y); 00139 00140 /** 00141 * Returns the MapItem immediately to the left of the given location. 00142 */ 00143 MapItem* get_west(int x, int y); 00144 00145 /** 00146 * Returns the MapItem at the given location. 00147 */ 00148 MapItem* get_here(int x, int y); 00149 00150 // Directions, for using the modification functions 00151 #define HORIZONTAL 0 00152 #define VERTICAL 1 00153 00154 /** 00155 * If there is a MapItem at (x,y), remove it from the map. 00156 */ 00157 void map_erase(int x, int y); 00158 00159 void map_delete(int x, int y); 00160 00161 /** 00162 * Add WALL items in a line of length len beginning at (x,y). 00163 * If dir == HORIZONTAL, the line is in the direction of increasing x. 00164 * If dir == VERTICAL, the line is in the direction of increasing y. 00165 * 00166 * If there are already items in the map that collide with this line, they are 00167 * erased. 00168 */ 00169 void add_wall(int x, int y, int dir, int len); 00170 00171 //, int dir, int len 00172 00173 void add_castle(int x, int y, int dir, int len); 00174 00175 void add_kindom(int x, int y); 00176 00177 void add_fire(int x, int y); 00178 00179 void add_key(int x, int y); 00180 00181 void add_chest(int x, int y); 00182 00183 void add_chest2(int x, int y); 00184 00185 void add_npc(int x, int y); 00186 00187 void add_npc2(int x, int y); 00188 00189 void add_store(int x, int y); 00190 00191 void add_merch(int x, int y); 00192 00193 void add_eye(int x, int y); 00194 00195 void add_goblin(int x, int y, int type); 00196 00197 void add_portal(int x, int y); 00198 00199 void add_portal2(int x, int y); 00200 00201 void add_door(int x, int y); 00202 00203 void add_dragon(int x, int y); 00204 00205 00206 /** 00207 * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it 00208 * before adding the plant. 00209 */ 00210 void add_plant(int x, int y); 00211 00212 #endif //MAP_H
Generated on Wed Jul 27 2022 10:35:26 by
