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 void* 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 SIGN 2 00059 #define DOORLOCKED 3 00060 #define DOORUNLOCKED 4 00061 #define FLOWFRIEND 5 00062 #define FLOWWINK 6 00063 #define FLOWCREEPY 7 00064 #define TOBY 8 00065 #define TOBYBONE 9 00066 #define REDBUTTON 10 00067 #define BLUEBUTTON 11 00068 #define GREENBUTTON 12 00069 #define RIVERMAN 13 00070 #define CHEST 14 00071 #define LEAF 15 00072 #define WOOD 16 00073 /** 00074 * Initializes the internal structures for all maps. This does not populate 00075 * the map with items, but allocates space for them, initializes the hash tables, 00076 * and sets the width and height. 00077 */ 00078 void maps_init(); 00079 00080 /** 00081 * Returns a pointer to the active map. 00082 */ 00083 Map* get_active_map(); 00084 00085 /** 00086 * Sets the active map to map m, where m is the index of the map to activate. 00087 * Returns a pointer to the new active map. 00088 */ 00089 Map* set_active_map(int m); 00090 00091 /** 00092 * Returns the map m, regardless of whether it is the active map. This function 00093 * does not change the active map. 00094 */ 00095 Map* get_map(int m); 00096 00097 /** 00098 * Print the active map to the serial console. 00099 */ 00100 void print_map(); 00101 00102 // Access 00103 /** 00104 * Returns the width of the active map. 00105 */ 00106 int map_width(); 00107 00108 /** 00109 * Returns the heigh of the active map. 00110 */ 00111 int map_height(); 00112 00113 /** 00114 * Returns the total number of cells in the active map. 00115 */ 00116 int map_area(); 00117 00118 /** 00119 * Returns the MapItem immediately above the given location. 00120 */ 00121 MapItem* get_north(int x, int y); 00122 00123 /** 00124 * Returns the MapItem immediately below the given location. 00125 */ 00126 MapItem* get_south(int x, int y); 00127 00128 /** 00129 * Returns the MapItem immediately to the right of the given location. 00130 */ 00131 MapItem* get_east(int x, int y); 00132 00133 /** 00134 * Returns the MapItem immediately to the left of the given location. 00135 */ 00136 MapItem* get_west(int x, int y); 00137 00138 /** 00139 * Returns the MapItem at the given location. 00140 */ 00141 MapItem* get_here(int x, int y); 00142 00143 // Directions, for using the modification functions 00144 #define HORIZONTAL 0 00145 #define VERTICAL 1 00146 00147 /** 00148 * If there is a MapItem at (x,y), remove it from the map. 00149 */ 00150 void map_erase(int x, int y); 00151 00152 /** 00153 * Add WALL items in a line of length len beginning at (x,y). 00154 * If dir == HORIZONTAL, the line is in the direction of increasing x. 00155 * If dir == VERTICAL, the line is in the direction of increasing y. 00156 * 00157 * If there are already items in the map that collide with this line, they are 00158 * erased. 00159 */ 00160 void add_wall(int x, int y, int dir, int len); 00161 00162 /** 00163 * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it 00164 * before adding the plant. 00165 */ 00166 void add_plant(int x, int y); 00167 void add_sign(int x, int y); 00168 void add_door_locked(int x, int y); 00169 void add_door_unlocked(int x, int y); 00170 void add_flowey_friendly(int x, int y); 00171 void add_flowey_wink(int x, int y); 00172 void add_flowey_creepy(int x, int y); 00173 void add_toby(int x, int y); 00174 void add_toby_bone(int x, int y); 00175 void add_red_button(int x, int y); 00176 void add_blue_button(int x, int y); 00177 void add_green_button(int x, int y); 00178 void add_river_man(int x, int y); 00179 void add_chest(int x, int v); 00180 void add_leaf(int x, int y); 00181 void add_wood(int x, int y); 00182 #endif //MAP_H
Generated on Thu Jul 14 2022 01:43:17 by
1.7.2