hgftf

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
ajorgih3
Date:
Sat Apr 17 14:09:46 2021 +0000
Revision:
10:0b2f37cef9b9
Parent:
9:d09b96b6c39c
huhu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DCchico 2:4947d6a82971 1 // Copyright 2020 Georgia Tech. All rights reserved.
DCchico 2:4947d6a82971 2 // The materials provided by the instructor in this course are for
DCchico 2:4947d6a82971 3 // the use of the students currently enrolled in the course.
DCchico 2:4947d6a82971 4 // Copyrighted course materials may not be further disseminated.
DCchico 2:4947d6a82971 5 // This file must not be made publicly available anywhere.
DCchico 2:4947d6a82971 6
DCchico 1:10330bce85cb 7 #ifndef MAP_H
DCchico 1:10330bce85cb 8 #define MAP_H
DCchico 1:10330bce85cb 9
DCchico 1:10330bce85cb 10 #include "hash_table.h"
DCchico 1:10330bce85cb 11
DCchico 1:10330bce85cb 12 /**
DCchico 1:10330bce85cb 13 * A structure to represent the map. The implementation is private.
DCchico 1:10330bce85cb 14 */
DCchico 1:10330bce85cb 15 struct Map;
DCchico 1:10330bce85cb 16
DCchico 1:10330bce85cb 17 // A function pointer type for drawing MapItems.
DCchico 1:10330bce85cb 18 // All tiles are 11x11 blocks.
DCchico 1:10330bce85cb 19 // u,v is the top left corner pixel of the block
DCchico 1:10330bce85cb 20 typedef void (*DrawFunc)(int u, int v);
DCchico 1:10330bce85cb 21
DCchico 1:10330bce85cb 22 /**
DCchico 1:10330bce85cb 23 * The data for elements in the map. Each item in the map HashTable is a
DCchico 1:10330bce85cb 24 * MapItem.
DCchico 1:10330bce85cb 25 */
DCchico 1:10330bce85cb 26 typedef struct {
DCchico 1:10330bce85cb 27 /**
DCchico 1:10330bce85cb 28 * Indicates the "type" of the MapItem: WALL, DOOR, PLANT, etc. This is
DCchico 1:10330bce85cb 29 * useful for determining how to interact with the object when updating the
DCchico 1:10330bce85cb 30 * game state.
DCchico 1:10330bce85cb 31 */
DCchico 1:10330bce85cb 32 int type;
DCchico 1:10330bce85cb 33
DCchico 1:10330bce85cb 34 /**
DCchico 1:10330bce85cb 35 * A function pointer to the drawing function for this item. Used by draw_game.
DCchico 1:10330bce85cb 36 */
DCchico 1:10330bce85cb 37 DrawFunc draw;
DCchico 1:10330bce85cb 38
DCchico 1:10330bce85cb 39 /**
DCchico 1:10330bce85cb 40 * If zero, this item should block character motion.
DCchico 1:10330bce85cb 41 */
DCchico 1:10330bce85cb 42 int walkable;
DCchico 1:10330bce85cb 43
DCchico 1:10330bce85cb 44 /**
DCchico 1:10330bce85cb 45 * Arbitrary extra data for the MapItem. Could be useful for keeping up with
DCchico 1:10330bce85cb 46 * special information, like where a set of stairs should take the player.
DCchico 1:10330bce85cb 47 *
DCchico 1:10330bce85cb 48 * Iterpretation of this can depend on the type of the MapItem. For example,
DCchico 1:10330bce85cb 49 * a WALL probably doesn't need to use this (it can be NULL), where an NPC
DCchico 1:10330bce85cb 50 * might use it to store game state (have I given the player the key yet?).
DCchico 1:10330bce85cb 51 */
DCchico 1:10330bce85cb 52 void* data;
DCchico 1:10330bce85cb 53 } MapItem;
DCchico 1:10330bce85cb 54
DCchico 1:10330bce85cb 55 typedef struct {
DCchico 1:10330bce85cb 56 int tm;
DCchico 1:10330bce85cb 57 int tx, ty;
DCchico 1:10330bce85cb 58 } StairsData;
DCchico 1:10330bce85cb 59
DCchico 1:10330bce85cb 60 // MapItem types
DCchico 1:10330bce85cb 61 // Define more of these!
DCchico 1:10330bce85cb 62 #define WALL 0
DCchico 1:10330bce85cb 63 #define DOOR 1
DCchico 1:10330bce85cb 64 #define PLANT 2
DCchico 1:10330bce85cb 65 #define WATER 3
DCchico 1:10330bce85cb 66 #define KEY 4
DCchico 1:10330bce85cb 67 #define GOODIE 5
DCchico 1:10330bce85cb 68 #define SNAKE_BODY 6
DCchico 1:10330bce85cb 69 #define CLEAR 7
DCchico 1:10330bce85cb 70 #define STAIRS 8
DCchico 1:10330bce85cb 71 #define SONAR 9
DCchico 1:10330bce85cb 72 #define PUZZLE 10
DCchico 1:10330bce85cb 73 #define NPC 11
ajorgih3 3:bb6f73642f01 74 #define SHIELD 12
ajorgih3 3:bb6f73642f01 75 #define LIFE 13
ajorgih3 3:bb6f73642f01 76 #define SNOWFLAKE 14
ajorgih3 3:bb6f73642f01 77 #define NOTHING 15
ajorgih3 3:bb6f73642f01 78 #define SWORD 16
ajorgih3 4:697e1120f821 79 #define ARROWUP 17
ajorgih3 4:697e1120f821 80 #define ARROWDOWN 18
ajorgih3 4:697e1120f821 81 #define ARROWRIGHT 19
ajorgih3 4:697e1120f821 82 #define ARROWLEFT 20
ajorgih3 5:5953ca12205d 83 #define LIGHTSPEED 21
ajorgih3 5:5953ca12205d 84 #define BLUEWALL 22
ajorgih3 6:fbaee888e5ea 85 #define REVERSE 23
ajorgih3 7:7ab2f4b09196 86 #define BLUEPOTION 24
ajorgih3 7:7ab2f4b09196 87 #define REDPOTION 25
ajorgih3 9:d09b96b6c39c 88 #define PORTAL 26
ajorgih3 10:0b2f37cef9b9 89 #define SNAKE_TAIL 27
ajorgih3 10:0b2f37cef9b9 90 #define SNAKE_HEAD 28
DCchico 1:10330bce85cb 91
DCchico 1:10330bce85cb 92
DCchico 1:10330bce85cb 93 /**
DCchico 1:10330bce85cb 94 * Initializes the internal structures for all maps. This does not populate
DCchico 1:10330bce85cb 95 * the map with items, but allocates space for them, initializes the hash tables,
DCchico 1:10330bce85cb 96 * and sets the width and height.
DCchico 1:10330bce85cb 97 */
DCchico 1:10330bce85cb 98 void maps_init();
DCchico 1:10330bce85cb 99
DCchico 1:10330bce85cb 100 /**
DCchico 1:10330bce85cb 101 * Returns a pointer to the active map.
DCchico 1:10330bce85cb 102 */
DCchico 1:10330bce85cb 103 Map* get_active_map();
DCchico 1:10330bce85cb 104
DCchico 1:10330bce85cb 105 /**
DCchico 1:10330bce85cb 106 * Sets the active map to map m, where m is the index of the map to activate.
DCchico 1:10330bce85cb 107 * Returns a pointer to the new active map.
DCchico 1:10330bce85cb 108 */
DCchico 1:10330bce85cb 109 Map* set_active_map(int m);
DCchico 1:10330bce85cb 110
DCchico 1:10330bce85cb 111 /**
DCchico 1:10330bce85cb 112 * Returns the map m, regardless of whether it is the active map. This function
DCchico 1:10330bce85cb 113 * does not change the active map.
DCchico 1:10330bce85cb 114 */
DCchico 1:10330bce85cb 115 Map* get_map(int m);
DCchico 1:10330bce85cb 116
DCchico 1:10330bce85cb 117 /**
DCchico 1:10330bce85cb 118 * Print the active map to the serial console.
DCchico 1:10330bce85cb 119 */
DCchico 1:10330bce85cb 120 void print_map();
DCchico 1:10330bce85cb 121
DCchico 1:10330bce85cb 122 // Access
DCchico 1:10330bce85cb 123 /**
DCchico 1:10330bce85cb 124 * Returns the width of the active map.
DCchico 1:10330bce85cb 125 */
DCchico 1:10330bce85cb 126 int map_width();
DCchico 1:10330bce85cb 127
DCchico 1:10330bce85cb 128 /**
DCchico 1:10330bce85cb 129 * Returns the heigh of the active map.
DCchico 1:10330bce85cb 130 */
DCchico 1:10330bce85cb 131 int map_height();
DCchico 1:10330bce85cb 132
DCchico 1:10330bce85cb 133 /**
DCchico 1:10330bce85cb 134 * Returns the total number of cells in the active map.
DCchico 1:10330bce85cb 135 */
DCchico 1:10330bce85cb 136 int map_area();
DCchico 1:10330bce85cb 137
DCchico 1:10330bce85cb 138 MapItem* get_current(int x, int y);
DCchico 1:10330bce85cb 139
DCchico 1:10330bce85cb 140 /**
DCchico 1:10330bce85cb 141 * Returns the MapItem immediately above the given location.
DCchico 1:10330bce85cb 142 */
DCchico 1:10330bce85cb 143 MapItem* get_north(int x, int y);
DCchico 1:10330bce85cb 144
DCchico 1:10330bce85cb 145 /**
DCchico 1:10330bce85cb 146 * Returns the MapItem immediately below the given location.
DCchico 1:10330bce85cb 147 */
DCchico 1:10330bce85cb 148 MapItem* get_south(int x, int y);
DCchico 1:10330bce85cb 149
DCchico 1:10330bce85cb 150 /**
DCchico 1:10330bce85cb 151 * Returns the MapItem immediately to the right of the given location.
DCchico 1:10330bce85cb 152 */
DCchico 1:10330bce85cb 153 MapItem* get_east(int x, int y);
DCchico 1:10330bce85cb 154
DCchico 1:10330bce85cb 155 /**
DCchico 1:10330bce85cb 156 * Returns the MapItem immediately to the left of the given location.
DCchico 1:10330bce85cb 157 */
DCchico 1:10330bce85cb 158 MapItem* get_west(int x, int y);
DCchico 1:10330bce85cb 159
DCchico 1:10330bce85cb 160 /**
DCchico 1:10330bce85cb 161 * Returns the MapItem at the given location.
DCchico 1:10330bce85cb 162 */
DCchico 1:10330bce85cb 163 MapItem* get_here(int x, int y);
DCchico 1:10330bce85cb 164
DCchico 1:10330bce85cb 165 // Directions, for using the modification functions
DCchico 1:10330bce85cb 166 #define HORIZONTAL 0
DCchico 1:10330bce85cb 167 #define VERTICAL 1
DCchico 1:10330bce85cb 168
DCchico 1:10330bce85cb 169 /**
DCchico 1:10330bce85cb 170 * If there is a MapItem at (x,y), remove it from the map.
DCchico 1:10330bce85cb 171 */
DCchico 1:10330bce85cb 172 void map_erase(int x, int y);
DCchico 1:10330bce85cb 173
DCchico 1:10330bce85cb 174 /**
DCchico 1:10330bce85cb 175 * Add WALL items in a line of length len beginning at (x,y).
DCchico 1:10330bce85cb 176 * If dir == HORIZONTAL, the line is in the direction of increasing x.
DCchico 1:10330bce85cb 177 * If dir == VERTICAL, the line is in the direction of increasing y.
DCchico 1:10330bce85cb 178 *
DCchico 1:10330bce85cb 179 * If there are already items in the map that collide with this line, they are
DCchico 1:10330bce85cb 180 * erased.
DCchico 1:10330bce85cb 181 */
DCchico 1:10330bce85cb 182 void add_wall(int x, int y, int dir, int len);
ajorgih3 5:5953ca12205d 183 void add_blue_wall(int x, int y, int dir, int len);
DCchico 1:10330bce85cb 184 /**
DCchico 1:10330bce85cb 185 * Add a PLANT item at (x,y). If there is already a MapItem at (x,y), erase it
DCchico 1:10330bce85cb 186 * before adding the plant.
DCchico 1:10330bce85cb 187 */
DCchico 1:10330bce85cb 188 void add_plant(int x, int y);
DCchico 1:10330bce85cb 189 void add_goodie(int x, int y);
DCchico 1:10330bce85cb 190 void remove_goodie(int x, int y);
DCchico 1:10330bce85cb 191 void add_snake_body(int x, int y);
DCchico 1:10330bce85cb 192 void add_snake_head(int x, int y);
DCchico 1:10330bce85cb 193 void add_snake_tail(int x, int y);
ajorgih3 3:bb6f73642f01 194 void add_shield(int x, int y);
ajorgih3 3:bb6f73642f01 195 void add_life(int x, int y);
ajorgih3 3:bb6f73642f01 196 void add_snowflake(int x, int y);
ajorgih3 3:bb6f73642f01 197 void add_sword(int x, int y);
ajorgih3 4:697e1120f821 198 void add_nothing(int x, int y);
ajorgih3 4:697e1120f821 199 void add_arrow_down(int x, int y);
ajorgih3 4:697e1120f821 200 void add_arrow_up(int x, int y);
ajorgih3 4:697e1120f821 201 void add_arrow_right(int x, int y);
ajorgih3 4:697e1120f821 202 void add_arrow_left(int x, int y);
ajorgih3 5:5953ca12205d 203 void add_lightspeed(int x, int y);
ajorgih3 6:fbaee888e5ea 204 void add_reverse(int x, int y);
ajorgih3 7:7ab2f4b09196 205 void add_blue_potion(int x, int y);
ajorgih3 7:7ab2f4b09196 206 void add_red_potion(int x, int y);
ajorgih3 9:d09b96b6c39c 207 void add_portal(int x, int y);
DCchico 1:10330bce85cb 208
DCchico 1:10330bce85cb 209 #endif //MAP_H