A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
RoomEngine/RoomEngine.h@58:c8d90bb7404a, 2019-05-09 (annotated)
- Committer:
- el17sm
- Date:
- Thu May 09 14:43:45 2019 +0000
- Revision:
- 58:c8d90bb7404a
- Parent:
- 57:1c12361b6e3d
- Child:
- 59:fd4669864b67
Fully Doxygenated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17sm | 26:abbc19edc5c1 | 1 | #ifndef ROOMENGINE_H |
el17sm | 26:abbc19edc5c1 | 2 | #define ROOMENGINE_H |
el17sm | 28:98848e6a77a2 | 3 | #include "N5110.h" |
el17sm | 29:6b8411bb040a | 4 | #include "Gamepad.h" |
el17sm | 29:6b8411bb040a | 5 | |
el17sm | 26:abbc19edc5c1 | 6 | #include "Player.h" |
el17sm | 29:6b8411bb040a | 7 | #include "Health.h" |
el17sm | 26:abbc19edc5c1 | 8 | #include "Room.h" |
el17sm | 29:6b8411bb040a | 9 | |
el17sm | 26:abbc19edc5c1 | 10 | #include "sprites.h" |
el17sm | 46:f09711580d4a | 11 | #define MAX_ROOMS_MAP_X 11 |
el17sm | 46:f09711580d4a | 12 | #define MAX_ROOMS_MAP_Y 11 |
el17sm | 29:6b8411bb040a | 13 | |
el17sm | 58:c8d90bb7404a | 14 | /**RoomEngine Class |
el17sm | 58:c8d90bb7404a | 15 | @author Steven Mahasin |
el17sm | 58:c8d90bb7404a | 16 | @brief Handles all Inter-Class Interactions in the room |
el17sm | 58:c8d90bb7404a | 17 | @date May 2019 |
el17sm | 58:c8d90bb7404a | 18 | */ |
el17sm | 27:a1b41626f57c | 19 | class RoomEngine |
el17sm | 26:abbc19edc5c1 | 20 | { |
el17sm | 26:abbc19edc5c1 | 21 | public: |
el17sm | 58:c8d90bb7404a | 22 | /** Constructor |
el17sm | 58:c8d90bb7404a | 23 | * @param global_contrast @details the contrast that the game runs on, set by title screen |
el17sm | 58:c8d90bb7404a | 24 | */ |
el17sm | 41:0697508a28ba | 25 | RoomEngine(float global_contrast); |
el17sm | 58:c8d90bb7404a | 26 | /** Destructor */ |
el17sm | 27:a1b41626f57c | 27 | ~RoomEngine(); |
el17sm | 32:fe6359ef9916 | 28 | |
el17sm | 32:fe6359ef9916 | 29 | // Functions |
el17sm | 58:c8d90bb7404a | 30 | /** |
el17sm | 58:c8d90bb7404a | 31 | * @brief loads the current player and room into the engine |
el17sm | 58:c8d90bb7404a | 32 | * @param current_player @details the player we control |
el17sm | 58:c8d90bb7404a | 33 | * @param current_room @details the room the player is currently in |
el17sm | 58:c8d90bb7404a | 34 | */ |
el17sm | 31:ab24d028ddfd | 35 | void load(Player *current_player, Room *current_room); |
el17sm | 58:c8d90bb7404a | 36 | /** |
el17sm | 58:c8d90bb7404a | 37 | * @brief plays an entrance_scene of the player into the room |
el17sm | 58:c8d90bb7404a | 38 | * @param lcd @details the screen that is being drawn on |
el17sm | 58:c8d90bb7404a | 39 | * @param gamepad @details the gamepad whose controls are being read |
el17sm | 58:c8d90bb7404a | 40 | */ |
el17sm | 28:98848e6a77a2 | 41 | void entrance_scene(N5110 &lcd, Gamepad &gamepad); |
el17sm | 58:c8d90bb7404a | 42 | /** |
el17sm | 58:c8d90bb7404a | 43 | * @brief increments the room coordinate based on which side the player exits the screen from |
el17sm | 58:c8d90bb7404a | 44 | */ |
el17sm | 29:6b8411bb040a | 45 | void update_current_room(); |
el17sm | 29:6b8411bb040a | 46 | |
el17sm | 58:c8d90bb7404a | 47 | /** |
el17sm | 58:c8d90bb7404a | 48 | * @brief returns 0-4 based on the player's position in the screen |
el17sm | 58:c8d90bb7404a | 49 | * @return which side of the screen the player is currently at (4 = inside) |
el17sm | 58:c8d90bb7404a | 50 | */ |
el17sm | 50:2c5cb92a5361 | 51 | int check_player_room_position(); |
el17sm | 50:2c5cb92a5361 | 52 | |
el17sm | 58:c8d90bb7404a | 53 | /** |
el17sm | 58:c8d90bb7404a | 54 | * @brief reads the input from the gamepad and converts it into member variables |
el17sm | 58:c8d90bb7404a | 55 | * @param gamepad @details the gamepad whose controls are being read |
el17sm | 58:c8d90bb7404a | 56 | */ |
el17sm | 26:abbc19edc5c1 | 57 | void read_input(Gamepad &gamepad); |
el17sm | 58:c8d90bb7404a | 58 | /** |
el17sm | 58:c8d90bb7404a | 59 | * @brief updates the interaction between entities in room (enemies hp, damage, etc) |
el17sm | 58:c8d90bb7404a | 60 | * @param number_of_enemies_killed @details for the final score, gets incremented everytime an enemy is killed |
el17sm | 58:c8d90bb7404a | 61 | */ |
el17sm | 47:6e31b195ce3c | 62 | void update(int &number_of_enemies_killed); |
el17sm | 58:c8d90bb7404a | 63 | /** |
el17sm | 58:c8d90bb7404a | 64 | * @brief to draw all the map, entities, doorway onto the screen |
el17sm | 58:c8d90bb7404a | 65 | * @param lcd @details the screen that the roomengine draws on |
el17sm | 58:c8d90bb7404a | 66 | */ |
el17sm | 27:a1b41626f57c | 67 | void render(N5110 &lcd, Gamepad &gamepad); |
el17sm | 32:fe6359ef9916 | 68 | |
el17sm | 58:c8d90bb7404a | 69 | /** |
el17sm | 58:c8d90bb7404a | 70 | * @brief Plays an exit scene of the player leaving the room |
el17sm | 58:c8d90bb7404a | 71 | * @param lcd @details the screen that the exit scene is drawn on |
el17sm | 58:c8d90bb7404a | 72 | * @param gamepad @details the gamepad whose controls are being read |
el17sm | 58:c8d90bb7404a | 73 | */ |
el17sm | 50:2c5cb92a5361 | 74 | void exit_scene(N5110 &lcd, Gamepad &gamepad); |
el17sm | 26:abbc19edc5c1 | 75 | |
el17sm | 29:6b8411bb040a | 76 | // Accessor |
el17sm | 58:c8d90bb7404a | 77 | /** |
el17sm | 58:c8d90bb7404a | 78 | * @brief reads the member variable _room_x |
el17sm | 58:c8d90bb7404a | 79 | * @return the current room's x-coordinate |
el17sm | 58:c8d90bb7404a | 80 | */ |
el17sm | 29:6b8411bb040a | 81 | int get_room_x(); |
el17sm | 58:c8d90bb7404a | 82 | /** |
el17sm | 58:c8d90bb7404a | 83 | * @brief reads the member variable _room_y |
el17sm | 58:c8d90bb7404a | 84 | * @return the current room's y-coordinate |
el17sm | 58:c8d90bb7404a | 85 | */ |
el17sm | 29:6b8411bb040a | 86 | int get_room_y(); |
el17sm | 29:6b8411bb040a | 87 | |
el17sm | 26:abbc19edc5c1 | 88 | private: |
el17sm | 57:1c12361b6e3d | 89 | // Member variables |
el17sm | 58:c8d90bb7404a | 90 | /** |
el17sm | 58:c8d90bb7404a | 91 | * @brief A boolean to indicate if button L is pressed |
el17sm | 58:c8d90bb7404a | 92 | */ |
el17sm | 26:abbc19edc5c1 | 93 | bool _L; |
el17sm | 58:c8d90bb7404a | 94 | /** |
el17sm | 58:c8d90bb7404a | 95 | * @brief A boolean to indicate if button R is pressed |
el17sm | 58:c8d90bb7404a | 96 | */ |
el17sm | 26:abbc19edc5c1 | 97 | bool _R; |
el17sm | 58:c8d90bb7404a | 98 | /** |
el17sm | 58:c8d90bb7404a | 99 | * @brief A boolean to indicate if button A is pressed |
el17sm | 58:c8d90bb7404a | 100 | */ |
el17sm | 26:abbc19edc5c1 | 101 | bool _A; |
el17sm | 58:c8d90bb7404a | 102 | /** |
el17sm | 58:c8d90bb7404a | 103 | * @brief A boolean to indicate if button B is pressed |
el17sm | 58:c8d90bb7404a | 104 | */ |
el17sm | 26:abbc19edc5c1 | 105 | bool _B; |
el17sm | 58:c8d90bb7404a | 106 | /** |
el17sm | 58:c8d90bb7404a | 107 | * @brief A boolean to indicate if button X is pressed |
el17sm | 58:c8d90bb7404a | 108 | */ |
el17sm | 26:abbc19edc5c1 | 109 | bool _X; |
el17sm | 58:c8d90bb7404a | 110 | /** |
el17sm | 58:c8d90bb7404a | 111 | * @brief A boolean to indicate if button Y is pressed |
el17sm | 58:c8d90bb7404a | 112 | */ |
el17sm | 26:abbc19edc5c1 | 113 | bool _Y; |
el17sm | 58:c8d90bb7404a | 114 | /** |
el17sm | 58:c8d90bb7404a | 115 | * @brief A vector2D that stores the x and y of the mapped_coordinates of the joystick |
el17sm | 58:c8d90bb7404a | 116 | */ |
el17sm | 26:abbc19edc5c1 | 117 | Vector2D mapped_coord; |
el17sm | 58:c8d90bb7404a | 118 | /** |
el17sm | 58:c8d90bb7404a | 119 | * @brief The x-coordinate value for the current room's position |
el17sm | 58:c8d90bb7404a | 120 | */ |
el17sm | 29:6b8411bb040a | 121 | int _room_x; |
el17sm | 58:c8d90bb7404a | 122 | /** |
el17sm | 58:c8d90bb7404a | 123 | * @brief The y-coordinate value for the current room's position |
el17sm | 58:c8d90bb7404a | 124 | */ |
el17sm | 29:6b8411bb040a | 125 | int _room_y; |
el17sm | 58:c8d90bb7404a | 126 | /** |
el17sm | 58:c8d90bb7404a | 127 | * @brief The value of set contrast from title screen, which dictates the contrast of lcd |
el17sm | 58:c8d90bb7404a | 128 | */ |
el17sm | 30:ec915d24d3e9 | 129 | float _global_contrast; |
el17sm | 58:c8d90bb7404a | 130 | /** |
el17sm | 58:c8d90bb7404a | 131 | * @brief A pointer to a Room, used to access the current room class and it's functions |
el17sm | 58:c8d90bb7404a | 132 | */ |
el17sm | 27:a1b41626f57c | 133 | Room *room; |
el17sm | 58:c8d90bb7404a | 134 | /** |
el17sm | 58:c8d90bb7404a | 135 | * @brief A pointer to a Player, used to access the current player class and it's functions |
el17sm | 58:c8d90bb7404a | 136 | */ |
el17sm | 27:a1b41626f57c | 137 | Player *player; |
el17sm | 26:abbc19edc5c1 | 138 | |
el17sm | 28:98848e6a77a2 | 139 | // Mutator |
el17sm | 58:c8d90bb7404a | 140 | /** |
el17sm | 58:c8d90bb7404a | 141 | * @brief mutates all the user input manually |
el17sm | 58:c8d90bb7404a | 142 | * @param L @details value to be written onto _L |
el17sm | 58:c8d90bb7404a | 143 | * @param R @details value to be written onto _R |
el17sm | 58:c8d90bb7404a | 144 | * @param A @details value to be written onto _A |
el17sm | 58:c8d90bb7404a | 145 | * @param B @details value to be written onto _B |
el17sm | 58:c8d90bb7404a | 146 | * @param X @details value to be written onto _X |
el17sm | 58:c8d90bb7404a | 147 | * @param Y @details value to be written onto _Y |
el17sm | 58:c8d90bb7404a | 148 | * @param mapped_x @details value to be written onto _mapped_coord.x |
el17sm | 58:c8d90bb7404a | 149 | * @param mapped_y @details value to be written onto _mapped_coord.y |
el17sm | 58:c8d90bb7404a | 150 | */ |
el17sm | 28:98848e6a77a2 | 151 | void set_input(bool L, bool R, bool A, bool B, bool X, bool Y, float mapped_x, float mapped_y); |
el17sm | 58:c8d90bb7404a | 152 | /** |
el17sm | 58:c8d90bb7404a | 153 | * @brief mutates _mapped_coord manually |
el17sm | 58:c8d90bb7404a | 154 | * @param mapped_x @details value to be written onto _mapped_coord.x |
el17sm | 58:c8d90bb7404a | 155 | * @param mapped_y @details value to be written onto _mapped_coord.y |
el17sm | 58:c8d90bb7404a | 156 | */ |
el17sm | 28:98848e6a77a2 | 157 | void set_mapped_coord(float x, float y); |
el17sm | 28:98848e6a77a2 | 158 | |
el17sm | 49:3f83ed62d123 | 159 | // Methods |
el17sm | 58:c8d90bb7404a | 160 | /** |
el17sm | 58:c8d90bb7404a | 161 | * @brief checks if the two entities a and b collide |
el17sm | 58:c8d90bb7404a | 162 | * @param a @details entity a to be checked if colliding with entity b |
el17sm | 58:c8d90bb7404a | 163 | * @param b @details entity b to be checked if colliding with entity a |
el17sm | 58:c8d90bb7404a | 164 | * @return true if the two entities collide |
el17sm | 58:c8d90bb7404a | 165 | */ |
el17sm | 28:98848e6a77a2 | 166 | bool entity_collision(Entity &a, Entity &b); |
el17sm | 58:c8d90bb7404a | 167 | /** |
el17sm | 58:c8d90bb7404a | 168 | * @brief checks if the entity a collides with any entities in the entity array "array[]" if entity a moves in the x direction |
el17sm | 58:c8d90bb7404a | 169 | * @param a @details entity a to be checked if colliding with any entity in the array[] |
el17sm | 58:c8d90bb7404a | 170 | * @param array[] @details an array of entities to be check if colliding with a |
el17sm | 58:c8d90bb7404a | 171 | * @param no_of_enemies @details constant length of enemies in the array[] |
el17sm | 58:c8d90bb7404a | 172 | * @param current_entity @details the index of the enemy to be ignored if entity a is within array[] |
el17sm | 58:c8d90bb7404a | 173 | * @param valid_enemies[] @details the array that defines which entities in array[] exists |
el17sm | 58:c8d90bb7404a | 174 | * @return -1 or 1 if the entity a collides with any entities in the entity array "array[]" when entity a moves in the x direction depending if a's x pos is bigger than the colliding entity's x pos or not |
el17sm | 58:c8d90bb7404a | 175 | */ |
el17sm | 28:98848e6a77a2 | 176 | float entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]); |
el17sm | 58:c8d90bb7404a | 177 | /** |
el17sm | 58:c8d90bb7404a | 178 | * @brief checks if the entity a collides with any entities in the entity array "array[]" if entity a moves in the y direction |
el17sm | 58:c8d90bb7404a | 179 | * @param a @details entity a to be checked if colliding with any entity in the array[] |
el17sm | 58:c8d90bb7404a | 180 | * @param array[] @details an array of entities to be check if colliding with a |
el17sm | 58:c8d90bb7404a | 181 | * @param no_of_enemies @details constant length of enemies in the array[] |
el17sm | 58:c8d90bb7404a | 182 | * @param current_entity @details the index of the enemy to be ignored if entity a is within array[] |
el17sm | 58:c8d90bb7404a | 183 | * @param valid_enemies[] @details the array that defines which entities in array[] exists |
el17sm | 58:c8d90bb7404a | 184 | * @return -1 or 1 if the entity a collides with any entities in the entity array "array[]" when entity a moves in the y direction depending if a's x pos is bigger than the colliding entity's x pos or not |
el17sm | 58:c8d90bb7404a | 185 | */ |
el17sm | 28:98848e6a77a2 | 186 | float entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]); |
el17sm | 28:98848e6a77a2 | 187 | |
el17sm | 58:c8d90bb7404a | 188 | /** |
el17sm | 58:c8d90bb7404a | 189 | * @brief inflict any damage happening to any entities in the room |
el17sm | 58:c8d90bb7404a | 190 | */ |
el17sm | 26:abbc19edc5c1 | 191 | void check_damage(); |
el17sm | 58:c8d90bb7404a | 192 | /** |
el17sm | 58:c8d90bb7404a | 193 | * @brief inflict any damage happening to the player in the room |
el17sm | 58:c8d90bb7404a | 194 | */ |
el17sm | 26:abbc19edc5c1 | 195 | void check_damage_player(); |
el17sm | 58:c8d90bb7404a | 196 | /** |
el17sm | 58:c8d90bb7404a | 197 | * @brief inflict any damage happening to any enemies in the room |
el17sm | 58:c8d90bb7404a | 198 | */ |
el17sm | 26:abbc19edc5c1 | 199 | void check_damage_enemies(); |
el17sm | 58:c8d90bb7404a | 200 | /** |
el17sm | 58:c8d90bb7404a | 201 | * @brief delete any enemies that has it's health depleted |
el17sm | 58:c8d90bb7404a | 202 | * @param number_of_enemies_killed @details increments whenever an enemy is successfully deleted |
el17sm | 58:c8d90bb7404a | 203 | */ |
el17sm | 47:6e31b195ce3c | 204 | void check_enemies_death(int &number_of_enemies_killed); |
el17sm | 58:c8d90bb7404a | 205 | /** |
el17sm | 58:c8d90bb7404a | 206 | * @brief undo movement of entity if the entity collides with the wall (not used in this version) |
el17sm | 58:c8d90bb7404a | 207 | */ |
el17sm | 41:0697508a28ba | 208 | void check_walls_collision(); |
el17sm | 41:0697508a28ba | 209 | |
el17sm | 58:c8d90bb7404a | 210 | /** |
el17sm | 58:c8d90bb7404a | 211 | * @brief updates the positions of all entities |
el17sm | 58:c8d90bb7404a | 212 | */ |
el17sm | 26:abbc19edc5c1 | 213 | void move(); |
el17sm | 58:c8d90bb7404a | 214 | /** |
el17sm | 58:c8d90bb7404a | 215 | * @brief updates the positions of player based on the joystick and wall constraint |
el17sm | 58:c8d90bb7404a | 216 | */ |
el17sm | 26:abbc19edc5c1 | 217 | void move_player(); |
el17sm | 58:c8d90bb7404a | 218 | /** |
el17sm | 58:c8d90bb7404a | 219 | * @brief updates the positions of enemies based on their coded movement patterns, repulsion effect and wall constraint |
el17sm | 58:c8d90bb7404a | 220 | */ |
el17sm | 26:abbc19edc5c1 | 221 | void move_enemies(); |
el17sm | 58:c8d90bb7404a | 222 | /** |
el17sm | 58:c8d90bb7404a | 223 | * @brief updates the position of the player whenever the player has just exit the screen |
el17sm | 58:c8d90bb7404a | 224 | * @param side @details the side the player exits the room from |
el17sm | 58:c8d90bb7404a | 225 | */ |
el17sm | 28:98848e6a77a2 | 226 | void update_player_position(int side); |
el17sm | 28:98848e6a77a2 | 227 | |
el17sm | 58:c8d90bb7404a | 228 | /** |
el17sm | 58:c8d90bb7404a | 229 | * @brief holds the loop and detection for when a player pauses |
el17sm | 58:c8d90bb7404a | 230 | * @param lcd @details the screen where the paused screen is going to be displayed on |
el17sm | 58:c8d90bb7404a | 231 | * @param gamepad @details the gamepad whose controls are being read |
el17sm | 58:c8d90bb7404a | 232 | */ |
el17sm | 27:a1b41626f57c | 233 | void pause_detection(N5110 &lcd, Gamepad &gamepad); |
el17sm | 58:c8d90bb7404a | 234 | /** |
el17sm | 58:c8d90bb7404a | 235 | * @brief draws the pause screen onto lcd |
el17sm | 58:c8d90bb7404a | 236 | * @param lcd @details the screen where the paused screen is going to be displayed on |
el17sm | 58:c8d90bb7404a | 237 | * @param paused_screen @details the char array of the frozen screen when paused |
el17sm | 58:c8d90bb7404a | 238 | * @param pause_timer @details the loop count to check if the pause sprite should appear or not for blink effect |
el17sm | 58:c8d90bb7404a | 239 | */ |
el17sm | 49:3f83ed62d123 | 240 | void draw_pause_screen(N5110 &lcd, char * paused_screen, int &pause_timer); |
el17sm | 26:abbc19edc5c1 | 241 | |
el17sm | 58:c8d90bb7404a | 242 | /** |
el17sm | 58:c8d90bb7404a | 243 | * @brief draws the map, the entities and map overlays in the order of descending j |
el17sm | 58:c8d90bb7404a | 244 | * @param lcd @details the screen where all entities are being drawn on |
el17sm | 58:c8d90bb7404a | 245 | */ |
el17sm | 27:a1b41626f57c | 246 | void draw(N5110 &lcd); |
el17sm | 58:c8d90bb7404a | 247 | /** |
el17sm | 58:c8d90bb7404a | 248 | * @brief draws number of hp as hearts on the top left of the screen whenever the user holds button L |
el17sm | 58:c8d90bb7404a | 249 | * @param lcd @details the screen where the hearts are being drawn on |
el17sm | 58:c8d90bb7404a | 250 | */ |
el17sm | 26:abbc19edc5c1 | 251 | void draw_health(N5110 &lcd); |
el17sm | 26:abbc19edc5c1 | 252 | |
el17sm | 26:abbc19edc5c1 | 253 | }; |
el17sm | 26:abbc19edc5c1 | 254 | #endif |