Cong Vu / Mbed 2 deprecated Project2_cvu31

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