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 MotionSensor
Revision 58:c8d90bb7404a, committed 2019-05-09
- Comitter:
- el17sm
- Date:
- Thu May 09 14:43:45 2019 +0000
- Parent:
- 57:1c12361b6e3d
- Child:
- 59:fd4669864b67
- Child:
- 61:901871a7c6ff
- Commit message:
- Fully Doxygenated
Changed in this revision
--- a/Entity/Bosses/Skull/Skull.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Bosses/Skull/Skull.h Thu May 09 14:43:45 2019 +0000
@@ -3,18 +3,49 @@
#include "Entity.h"
#define DASH_DELAY 120
+/**Skull Class
+@author Steven Mahasin
+@brief Creates a Skull which inherits the Entity class, this is currently the only boss in the game.
+@date May 2019
+*/
class Skull : public Entity {
private:
// Member Variables
+ /**
+ * @brief the shadow of Skull has a separate size and offset, so it has to have such member variable
+ */
SpriteSize _shadow;
+ /**
+ * @brief a status of wether the skull is dashing
+ */
bool _dash;
+ /**
+ * @brief a counter to let the skull dash periodically
+ */
int _dash_counter;
+ /**
+ * @brief an index to choose which velocity the Skull currently has when dashing
+ */
int _velocity_index;
// Member Functions
+ /**
+ * @brief increase _frame.count which increases _frame.number to animate skull
+ */
void increment_frames();
+ /**
+ * @brief updates the offset of the skull so that it floats up and down periodically above the shadow (purely graphical)
+ */
void update_offsets();
+ /**
+ * @brief moves the skull towards the player, similar to headless
+ * @param player_x @details player x-position
+ * @param player_y @details player y-position
+ */
void approaching_movement(float player_x, float player_y);
+ /**
+ * @brief moves the skull in a dashing manner
+ */
void dash_movement();
public:
@@ -22,8 +53,23 @@
Skull(float pos_x, float pos_y);
// Functions
- virtual void move(float, float, char * map, bool * doorways); // movement control and miscellaneous updates
+ /**
+ * @brief calls the function and conditions to move (both dashing and approaching)
+ * @param x_value @details player x-position
+ * @param y_value @details player y-position
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ */
+ virtual void move(float x_value, float y_value, char * map, bool * doorways); // movement control and miscellaneous updates
+ /**
+ * @brief reduce _hp by damage
+ * @param damage @details the amount of damage to be taken
+ */
virtual void take_damage(int);
+ /**
+ * @brief a function of drawing the skull onto the screen
+ * @param lcd @details the screen where the skull is drawn on
+ */
virtual void draw(N5110 &lcd);
};
--- a/Entity/Collectibles/Health/Health.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Collectibles/Health/Health.h Thu May 09 14:43:45 2019 +0000
@@ -2,16 +2,40 @@
#define HEALTH_H
#include "Entity.h"
+/**Health Class
+@author Steven Mahasin
+@brief Creates a Health which inherits the Entity class, this is a collectible entity that the player interracts with to gain health points.
+@date May 2019
+*/
class Health : public Entity
{
public:
- // Constructor
- Health(float, float);
+ /** Constructor
+ * @brief creates a heart that heals when picked up
+ * @param pos_x @details initialise _position.x
+ * @param pos_y @details initialise _position.y
+ */
+ Health(float pos_x, float pos_y);
// Functions
- virtual void move(float, float, char * map, bool * doorways);
- virtual void draw(N5110 &unused);
- virtual void take_damage(int);
+ /**
+ * @brief just because entity has a pure virtual function move, the function is of no use in health as it does not move
+ * @param unused @details not used
+ * @param unused1 @details not used
+ * @param unused2 @details not used
+ * @param unused3 @details not used
+ */
+ virtual void move(float unused, float unused1, char *unused2, bool *unused3);
+ /**
+ * @brief reduce _hp by damage
+ * @param damage @details the amount of damage to be taken
+ */
+ virtual void take_damage(int damage);
+ /**
+ * @brief a virtual function of drawing the health onto the screen
+ * @param lcd @details the screen where the health is drawn on
+ */
+ virtual void draw(N5110 &lcd);
};
const char health_sprite[7][7] = {
--- a/Entity/Entity.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Entity.h Thu May 09 14:43:45 2019 +0000
@@ -4,6 +4,11 @@
#include "math.h"
#include "N5110.h"
+/**Entity Abstract Class
+@author Steven Mahasin
+@brief Creates an Entity which holds entity datas, functions(movements, damaged actions, collision test, etc), accessors and functions to be inherited by child classes
+@date May 2019
+*/
class Entity
{
protected:
@@ -18,7 +23,7 @@
// to the right of top-left corner of hitbox
int offset_x;
// Top-left corner of sprite is offset_y
- // above of top-left corner of hitbox
+ // below of top-left corner of hitbox
int offset_y;
};
struct Position {
@@ -30,47 +35,186 @@
int number;
int max;
};
+ /**
+ * @brief A struct containing hitbox data for the entity
+ * @info width and height
+ */
Hitbox _hitbox;
+ /**
+ * @brief A struct containing sprite size data for the entity, to be used when drawing sprites on top of their hitboxes
+ * @info sprite width, sprite height, sprite offset x from hitbox, sprite offset y from hitbox
+ */
SpriteSize _sprite_size;
+ /**
+ * @brief A struct containing the position of the entity, this position is the top-left corner of the hitbox
+ */
Position _position;
+ /**
+ * @brief A struct containing the position of the entity one loop behind
+ */
Position _prev_pos;
+ /**
+ * @brief A struct containing frame count, frame number and frame max. Used to animate entities
+ */
FrameCount _frame;
+ /**
+ * @brief The health point of an entity
+ */
int _hp;
+ /**
+ * @brief The damage the entity does if it attacks another entity
+ */
int _attack;
+ /**
+ * @brief The direction the entity is facing
+ */
int _face;
+ /**
+ * @brief The speed the entity moves
+ */
float _velocity;
+ /**
+ * @brief The chance(out of 100) of dropping a heart when the entity is deleted.
+ */
int _hp_drop_chance;
public:
// Function
- virtual void move(float, float, char * map, bool * doorways) = 0; // movement control and miscellaneous updates
- virtual void take_damage(int) = 0;
+ /**
+ * @brief a virtual function movement of the entity to be inherited
+ * @param x_value @details either joystick x or player's x position
+ * @param y_value @details either joystick y or player's y position
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ */
+ virtual void move(float x_value, float y_value, char * map, bool * doorways) = 0; // movement control and miscellaneous updates
+ /**
+ * @brief a virtual function of the action when taking damage to be inherited
+ * @param damage @details the amount of damage to be taken
+ */
+ virtual void take_damage(int damage) = 0;
+ /**
+ * @brief a virtual function of drawing the entity to be inherited
+ * @param lcd @details the screen where the entity is drawn on
+ */
virtual void draw(N5110 &lcd) = 0;
+ /**
+ * @brief a function to undo entity's movement in the x direction if condition is true
+ * @param condition @details a boolean statement
+ */
void undo_move_x(bool condition);
+ /**
+ * @brief a function to undo entity's movement in the y direction if condition is true
+ * @param condition @details a boolean statement
+ */
void undo_move_y(bool condition);
+ /**
+ * @brief updates the _prev_pos into _position
+ */
void update_prev_pos();
+ /**
+ * @brief checks if the entity collides the map
+ * @param pos_x @details entity's x-position
+ * @param pos_y @details entity's y-position
+ * @param two_d_map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ * @return true if entity collide with the map
+ */
bool entity_to_map_collision_test(float pos_x, float pos_y, char * two_d_map, bool * doorways);
// Mutator
+ /**
+ * @brief mutates position of the entity to x and y
+ * @param x @details x-coordinate value
+ * @param y @details y-coordinate value
+ */
void set_position(float x, float y);
+ /**
+ * @brief adds change_x onto x-position of the entity
+ * @param change_x @details displacement x
+ */
void position_add_x(float change_x);
+ /**
+ * @brief adds change_y onto y-position of the entity
+ * @param change_y @details displacement y
+ */
void position_add_y(float change_y);
// Accessors
+ /**
+ * @brief gets the entity's chance to drop a health
+ * @return _hp_drop_chance
+ */
int get_hp_drop_chance();
+ /**
+ * @brief gets the entity's hitbox width
+ * @return _hitbox.width
+ */
int get_hitbox_width();
+ /**
+ * @brief gets the entity's hitbox height
+ * @return _hitbox.height
+ */
int get_hitbox_height();
+ /**
+ * @brief gets the entity's face
+ * @return _face
+ */
int get_face();
+ /**
+ * @brief gets the entity's sprite width
+ * @return _sprite_size.width
+ */
int get_sprite_width();
+ /**
+ * @brief gets the entity's sprite height
+ * @return _sprite_size.height
+ */
int get_sprite_height();
+ /**
+ * @brief gets the entity's sprite x-offset
+ * @return _sprite_size.offset_x
+ */
int get_offset_x();
+ /**
+ * @brief gets the entity's sprite y-offset
+ * @return _sprite_size.offset_y
+ */
int get_offset_y();
+ /**
+ * @brief gets the entity's x-position
+ * @return _position.x
+ */
int get_pos_x();
+ /**
+ * @brief gets the entity's y-position
+ * @return _position.y
+ */
int get_pos_y();
+ /**
+ * @brief gets the entity's previous x-position
+ * @return _prev_pos.x
+ */
int get_prev_pos_x();
+ /**
+ * @brief gets the entity's previous y-position
+ * @return _prev_pos.y
+ */
int get_prev_pos_y();
+ /**
+ * @brief gets the entity's attack
+ * @return _attack
+ */
int get_attack();
+ /**
+ * @brief gets the entity's hp
+ * @return _hp
+ */
int get_hp();
+ /**
+ * @brief gets the entity's velocity
+ * @return _velocity
+ */
float get_velocity();
};
--- a/Entity/Mobs/Headless/Headless.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Mobs/Headless/Headless.h Thu May 09 14:43:45 2019 +0000
@@ -2,21 +2,52 @@
#define HEADLESS_H
#include "Entity.h"
+/**Headless Class
+@author Steven Mahasin
+@brief Creates a Headless which inherits the Entity class, this is one of the mobs that spawns in the normal rooms.
+@date May 2019
+*/
class Headless : public Entity
{
public:
- // Constructor
- Headless(float, float);
+ /** Constructor
+ * @brief creates a headless at positions pos_x and pos_y
+ * @param pos_x @details initialise _position.x
+ * @param pos_y @details initialise _position.y
+ */
+ Headless(float pos_x, float pos_y);
// Functions
+ /**
+ * @brief function moves the headless towards the player
+ * @param x_value @details player x-position
+ * @param y_value @details player y-position
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ */
virtual void move(float player_x, float player_y, char * map, bool * doorways);
+ /**
+ * @brief reduce _hp by damage
+ * @param damage @details the amount of damage to be taken
+ */
+ virtual void take_damage(int damage);
+ /**
+ * @brief a virtual function of drawing the headless onto the screen
+ * @param lcd @details the screen where the headless is drawn on
+ */
virtual void draw(N5110 &lcd);
- virtual void take_damage(int damage);
private:
// Methods
+ /**
+ * @brief gets the sprite array
+ * @return char pointer array of the corresponding snake sprite frame
+ */
char * get_frame();
+ /**
+ * @brief increase _frame.count which increases _frame.number to animate snake
+ */
void increment_frame();
};
--- a/Entity/Mobs/Snake/Snake.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Mobs/Snake/Snake.h Thu May 09 14:43:45 2019 +0000
@@ -2,31 +2,89 @@
#define SNAKE_H
#include "Entity.h"
+/**Snake Class
+@author Steven Mahasin
+@brief Creates a Snake which inherits the Entity class, this is one of the mobs that spawns in the normal rooms.
+@date May 2019
+*/
class Snake : public Entity
{
public:
- // Constructor
- Snake(float, float);
+ /** Constructor
+ * @brief creates a snake at positions pos_x and pos_y
+ * @param pos_x @details initialise _position.x
+ * @param pos_y @details initialise _position.y
+ */
+ Snake(float pos_x, float pos_y);
// Functions
- virtual void move(float, float, char * map, bool * doorways);
- virtual void take_damage(int);
+ /**
+ * @brief calls the movement functions to move the snake in the desired way
+ * @param x_value @details player's x-position
+ * @param y_value @details player's y-position
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ */
+ virtual void move(float x_value, float y_value, char * map, bool * doorways);
+ /**
+ * @brief reduce hp by damage
+ * @param damage @details the amount of damage to be taken
+ */
+ virtual void take_damage(int damage);
+ /**
+ * @brief a virtual function of drawing the snake onto the screen
+ * @param lcd @details the screen where the snake is drawn on
+ */
virtual void draw(N5110 &lcd);
private:
// Member Function
+ /**
+ * @brief updates _prev_face into _face
+ */
void update_prev_face();
+ /**
+ * @brief gets the sprite array
+ * @return char pointer array of the corresponding snake sprite frame
+ */
char * get_frame();
+ /**
+ * @brief changes the face everytime the snake finish slithering, towards the player
+ * @param diff_x @details the difference between the player x-position and the snake x-position
+ * @param diff_y @details the difference between the player y-position and the snake y-position
+ */
void update_face(float diff_x, float diff_y);
+ /**
+ * @brief function moves the snake in a slither effect
+ */
void move_snake();
+ /**
+ * @brief increase _frame.count which increases _frame.number to animate snake
+ */
void increment_frame();
// Member Mutator
- void update_hitbox(int, int, int, int, int, int, int);
+ /**
+ * @brief updates the hitbox status and sprite status of the snake since different face has unique hitbox and sprite status
+ * @param _hitbox_width @details the width of the hitbox
+ * @param _hitbox_height @details the height of the hitbox
+ * @param _sprite_size_width @details the width of the sprite
+ * @param _sprite_size_height @details the height of the sprite
+ * @param _sprite_size_offset_x @details the x-offset of the sprite to the hitbox
+ * @param _sprite_size_offset_y @details the y-offset of the sprite to the hitbox
+ * @param max_frame @details the maximum number of frames for animation
+ */
+ void update_hitbox(int _hitbox_width, int _hitbox_height, int _sprite_size_width, int _sprite_size_height, int _sprite_size_offset_x, int _sprite_size_offset_y, int max_frame);
// Member Variable
+ /**
+ * @brief an index to choose which velocity the snake currently has, this is to add the slither effect
+ */
int _velocity_index;
+ /**
+ * @brief the previous face of the snake, to detect change in snake's face
+ */
int _prev_face;
};
--- a/Entity/Player/Bullets/Bullets.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Player/Bullets/Bullets.h Thu May 09 14:43:45 2019 +0000
@@ -2,17 +2,48 @@
#define BULLETS_H
#include "Entity.h"
+/**Bullets Class
+@author Steven Mahasin
+@brief Creates a Bullet which inherits the Entity class, this will be a created projectile by the player class
+@date May 2019
+*/
class Bullets : public Entity
{
public:
- // Constructor
- Bullets(float, float, int);
+ /** Constructor
+ * @brief creates a bullet at positions pos_x and pos_y travelling at face dir
+ * @param pos_x @details initialise _position.x
+ * @param pos_y @details initialise _position.y
+ * @param dir @details initialise _face
+ */
+ Bullets(float pos_x, float pos_y, int dir);
// Functions
- virtual void move(float, float, char * map, bool * doorways);
+ /**
+ * @brief function moves the bullet on it's face at a speed
+ * @param speed @details the speed of the bullet
+ * @param unused @details not used
+ * @param map @details not used
+ * @param doorways @details not used
+ */
+ virtual void move(float speed, float unused, char * map, bool * doorways);
+ /**
+ * @brief draws the bullet onto the screen
+ * @param lcd @details the screen where the bullet is drawn
+ */
virtual void draw(N5110 &lcd);
+ /**
+ * @brief reduce _hp by damage
+ * @param damage @details the amount of damage to be taken
+ */
virtual void take_damage(int damage);
+ /**
+ * @brief checks if the bullet is out of bounds (hit wall or out of screen)
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ * @returns true if bullet is out of bounds
+ */
bool out_of_bounds_check(char * map, bool * doorways);
};
--- a/Entity/Player/Player.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Player/Player.h Thu May 09 14:43:45 2019 +0000
@@ -5,47 +5,148 @@
#define INVULNERABILITY_PERIOD 50
const int bullets_max = 20;
-
+/**Player Class
+@author Steven Mahasin
+@brief Creates a Player which inherits the Entity class, contains functions that accepts all user interractions (buttons, joystick, etc)
+@date May 2019
+*/
class Player : public Entity
{
private:
// Member Variables
+ /**
+ * @brief a counter that increments to give a delay to the fire rate of player
+ */
int _fire_rate_counter;
+ /**
+ * @brief a delay between each shot
+ */
int _fire_rate_delay;
+ /**
+ * @brief the speed of the bullets created by this player
+ */
int _bullet_speed;
+ /**
+ * @brief a counter that increments, allowing player to be invulnerable to a certain period defined
+ */
int _invulnerability_counter;
// Private Functions
+ /**
+ * @brief movement of the player
+ * @param mapped_x @details joystick x
+ * @param mapped_y @details joystick y
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ */
void move_player(float mapped_x, float mapped_y, char * map, bool * doorways);
+ /**
+ * @brief movement of the bullets shot by this player
+ */
void move_bullets();
+ /**
+ * @brief to increment the _frame protected variable, for animation of player
+ * @param mapped_x @details joystick x
+ * @param mapped_y @details joystick y
+ */
void increment_frames(float mapped_x, float mapped_y);
+ /**
+ * @brief getting the needed frame of animation of player
+ * @return char pointer array to the corresponding player frame
+ */
char * get_frame();
+ /**
+ * @brief draws the player onto the screen
+ * @param lcd @details the screen the player is drawn onto
+ */
void draw_player(N5110 &lcd);
public:
- // Constructors
+ /** Constructor
+ * @brief creates a player at positions pos_x and pos_y
+ * @param pos_x @details initialise _position.x
+ * @param pos_y @details initialise _position.y
+ */
Player(float pos_x, float pos_y);
- // Deconstructors
+ /** Deconstructors */
~Player();
// Accessors
+ /**
+ * @brief getting the player's bullet speed
+ * @return _bullet_speed
+ */
int get_bullet_speed();
+ /**
+ * @brief getting the heart sprite's width
+ * @return width of the heart sprite
+ */
int get_hearts_width();
+ /**
+ * @brief getting the heart sprite's height
+ * @return height of the heart sprite
+ */
int get_hearts_height();
+ /**
+ * @brief getting the heart sprite char array
+ * @return char pointer array to the heart sprite
+ */
char * get_hearts_sprite();
// Functions
- virtual void move(float, float, char * map, bool * doorways);
+ /**
+ * @brief function calls both movement of player and movement of bullets
+ * @param x_value @details joystick x
+ * @param y_value @details joystick y
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorways @details an array that dictates which side of the wall has a doorway
+ */
+ virtual void move(float x_value, float y_value, char * map, bool * doorways);
+ /**
+ * @brief reduce _hp by damage
+ * @param damage @details the amount of damage to be taken
+ */
virtual void take_damage(int damage);
+ /**
+ * @brief a virtual function of drawing the player onto the screen
+ * @param lcd @details the screen where the player is drawn on
+ */
virtual void draw(N5110 &lcd);
+ /**
+ * @brief a virtual function of drawing the bullets the player shot onto the screen if j is the correct y-position of the bullets
+ * @param lcd @details the screen where the bullets is drawn on
+ * @param j @details which y-position hitboxes are currently being printed
+ */
void draw_bullets(N5110 &lcd, int j);
+ /**
+ * @brief attempts to delete any bullets that goes out of bounds (out of screen or onto a wall)
+ * @param map @details the 2d map array that dictates where there are walls or empty space
+ * @param doorawys @details an array that dictates which side of the wall has a doorway
+ * @return true if any bullets is successfully deleted
+ */
bool delete_out_of_bounds_bullets(char * map, bool * doorways);
+ /**
+ * @brief deletes any existing bullets
+ */
void delete_bullets();
+ /**
+ * @brief shoots bullets at the direction of the buttons
+ * @param button_A @details button down
+ * @param button_B @details button right
+ * @param button_Y @details button up
+ * @param button_X @details button left
+ */
void buttons(bool button_A, bool button_B, bool button_Y, bool button_X);
// Variables
+ /**
+ * @brief a bullets pointer array that holds all the possible bullets the player can shoot
+ */
Bullets *bullets_array[bullets_max];
+ /**
+ * @brief a boolean array that dictates which bullets in the bullets array exist
+ */
bool valid_bullets[bullets_max];
};
--- a/Entity/Walls/Walls.h Thu May 09 09:50:19 2019 +0000
+++ b/Entity/Walls/Walls.h Thu May 09 14:43:45 2019 +0000
@@ -1,16 +1,41 @@
#ifndef WALLS_H
#define WALLS_H
#include "Entity.h"
-
+/**Walls Class
+@author Steven Mahasin
+@brief Creates a Static Wall which inherits the Entity class, not used yet in this version due to bugged spawn areas
+@date May 2019
+*/
class Walls : public Entity
{
public:
- // Constructor
+ /** Constructor
+ * @brief creates a wall at positions pos_x and pos_y
+ * @param pos_x @details initialise _position.x
+ * @param pos_y @details initialise _position.y
+ * @param hitbox_width @details initialise _hitbox.width
+ * @param hitbox_height @details initialise _hitbox.height
+ */
Walls(int pos_x, int pos_y, int hitbox_width, int hitbox_height);
// Functions
+ /**
+ * @brief just because entity has a pure virtual function move, the function is of no use in walls as it does not move
+ * @param unused @details not used
+ * @param unused1 @details not used
+ * @param unused2 @details not used
+ * @param unused3 @details not used
+ */
virtual void move(float unused, float unused1, char * unused2, bool * unused3); // movement control and miscellaneous updates
- virtual void take_damage(int damage);
+ /**
+ * @brief just because entity has a pure virtual function take_damage, the function is of no use in walls as it does take_damage
+ * @param unused @details not used
+ */
+ virtual void take_damage(int unused);
+ /**
+ * @brief a virtual function of drawing the walls onto the screen
+ * @param lcd @details the screen where the wall is drawn on
+ */
virtual void draw(N5110 &lcd);
};
--- a/RoomEngine/Room/Room.h Thu May 09 09:50:19 2019 +0000
+++ b/RoomEngine/Room/Room.h Thu May 09 14:43:45 2019 +0000
@@ -12,66 +12,212 @@
#include "N5110.h"
#define MAX_ENEMIES 10
-
+/**Room Class
+@author Steven Mahasin
+@brief Create a Room which holds the enemies, collectibles and doorways
+@date May 2019
+*/
class Room // contains the type of room, number of enemies inside it, the doorways existing in the room, functions to spawn enemies
{
private:
+ /**
+ * @brief an array that dictates which side of the wall has a doorway
+ */
bool _doorways[4];
+ /**
+ * @brief states the type of room (boss, normal, walled)
+ */
int _room_type;
+ /**
+ * @brief the coordinates of enemies to be spawned
+ */
int _enemy_coord[MAX_ENEMIES][2]; // _enemy_coord[EnemyID][x/y]
+ /**
+ * @brief the status of the walls, used to construct a wall at any x, y, width and height
+ */
char _wall_stat[2][4]; // _wall_coord[WallID][x/y/width/height]
+ /**
+ * @brief the special boss doorway is held in this member variable (0-3); if no boss doorway, it is default to 4
+ */
int _before_boss_room;
+ /**
+ * @brief a counter integer to increment through the spawn points in the spawn_area array and id each point
+ */
short int _spawn_point_counter;
+ /**
+ * @brief a variable to hold the decided randomised spawn point id to spawn an enemy
+ */
short int _spawn_point_coord;
// Functions
+ /**
+ * @brief initialisation of boss room
+ */
void init_boss_room();
+ /**
+ * @brief initialisation of normal rooms
+ */
void init_normal_room();
+ /**
+ * @brief initialisation of middle walled rooms (not used in this version, in progress)
+ */
void init_middle_walled_room();
+ /**
+ * @brief initialisation of side walled rooms (not used in this version, in progress)
+ */
void init_side_walled_room();
+ /**
+ * @brief set the _enemy_coord of index id to a random valid spawn area x and y
+ * @param id @details the index of the enemy to be given a random coord
+ */
void rand_enemy_coordinate(int id);
+ /**
+ * @brief draws the doorways that are behind the player
+ * @param lcd @details the screen where the doorway is drawn
+ */
void draw_doorways(N5110 &lcd);
+ /**
+ * @brief draws overlayed doorways, these doorways are in front of the player
+ * @param lcd @details the screen where the doorway_overlay is drawn
+ */
void draw_doorways_overlay(N5110 &lcd);
+ /**
+ * @brief draws enemies onto the screen
+ * @param lcd @details the screen where the enemies are drawn
+ * @param j @details the current y-position of entities that are being drawn
+ */
void draw_enemies(N5110 &lcd, int j);
+ /**
+ * @brief draws collectibles onto the screen
+ * @param lcd @details the screen where the collectibles is drawn
+ * @param j @details the current y-position of entities that are being drawn
+ */
void draw_collectibles(N5110 &lcd, int j);
+ /**
+ * @brief draws walls entity onto the screen
+ * @param lcd @details the screen where the walls is drawn
+ * @param j @details the current y-position of entities that are being drawn
+ */
void draw_walls(N5110 &lcd, int j);
public:
- // Constructors
+ /** Constructors
+ * @brief create a room with a set number of enemies and a set room type
+ * @param no_of_enemies @details the number of enemies to be spawned in the room
+ * @param room_type @details the type of room to be initialised with
+ */
Room(int no_of_enemies, int room_type);
- // Deconstructors
+ /** Destructors */
~Room();
// Mutators
+ /**
+ * @brief sets _doorway at index "index" with the value of "doorway_value"
+ * @param index @details the index of the mutated doorway
+ * @param doorway_value @details the value of the mutated doorway
+ */
void set_doorway(int index, bool doorway_value);
+ /**
+ * @brief sets the position of boss doorway on this room
+ * @param before_boss_room @details the side in which boss doorway exists (0-3 = sides, 4 = doesn't exist)
+ */
void set_boss_doorway(int before_boss_room);
// Accessors
+ /**
+ * @brief get the 2d map array that dictates where there are walls or empty space
+ * @return the char pointer array of the 2d level map
+ */
char * get_current_map_2d();
+ /**
+ * @brief get the doorways of the room
+ * @return boolean pointer array of the _doorways member variable
+ */
bool * get_doorways();
+ /**
+ * @brief get the doorway status of the room at index "index"
+ * @return _doorway[index]
+ */
bool get_doorway(int index);
+ /**
+ * @brief get the type of room
+ * @return _room_type
+ */
char get_room_type();
+ /**
+ * @brief get the boss doorway status
+ * @return _before_boss_room
+ */
int get_boss_doorway();
// Functions
+ /**
+ * @brief loads all the entities in the room
+ */
void load();
+ /**
+ * @brief deletes all entities in the room
+ */
void unload();
+ /**
+ * @brief close all doorways if the room is a boss room
+ */
void update_doorways();
+ /**
+ * @brief draws the room including enemies
+ * @param lcd @details the screen in which the room is being drawn in
+ * @param j @details the current y-position of entities that are being drawn
+ */
void draw(N5110 &lcd, int j);
+ /**
+ * @brief draws the room
+ * @param lcd @details the screen in which the room is being drawn in
+ */
void draw_room(N5110 &lcd);
+ /**
+ * @brief draws the room_overlay
+ * @param lcd @details the screen in which the room_overlay is being drawn in
+ */
void draw_room_overlay(N5110 &lcd);
+
+ /**
+ * @brief checks if there is any valid enemies in the room
+ * @return true if there is any valid enemies in the room
+ */
bool enemies_exist();
// Variables
+ /**
+ * @brief A pointer to an array of Entities where all the possible enemies in the room are stored
+ */
Entity *enemies[MAX_ENEMIES];
+ /**
+ * @brief A boolean array to dictate which enemies exist
+ */
bool valid_enemies[MAX_ENEMIES];
+ /**
+ * @brief A pointer to an array of Entities where all the possible collectibles in the room are stored
+ */
Entity *collectibles[MAX_ENEMIES];
+ /**
+ * @brief A boolean array to dictate which collectibles exist
+ */
bool valid_collectibles[MAX_ENEMIES];
+ /**
+ * @brief A pointer to an array of Entities where all the possible walls in the room are stored
+ */
Entity *walls[2];
+ /**
+ * @brief A boolean array to dictate which walls exist
+ */
bool valid_walls[2];
+ /**
+ * @brief An array of enemy types for each enemy in the room
+ * @note currently only snake and headless
+ */
int enemies_type[MAX_ENEMIES];
};
--- a/RoomEngine/RoomEngine.cpp Thu May 09 09:50:19 2019 +0000
+++ b/RoomEngine/RoomEngine.cpp Thu May 09 14:43:45 2019 +0000
@@ -318,7 +318,7 @@
return 0;
}
-// returns true if the hitbox of "entity a" collides with any hitboxes of entities within "array" as "entity a" moves on the x direction
+// returns -1 or 1 if the hitbox of "entity a" collides with any hitboxes of entities within "array" as "entity a" moves on the x direction
float RoomEngine::entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[])
{
for (int i = 0; i < no_of_enemies; i++) { // For every enemy = Entity B
@@ -335,7 +335,7 @@
return 0;
}
-// returns true if the hitbox of "entity a" collides with any hitboxes of entities within "array" as "entity a" moves on the y direction
+// returns -1 or 1 if the hitbox of "entity a" collides with any hitboxes of entities within "array" as "entity a" moves on the y direction
float RoomEngine::entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[])
{
for (int i = 0; i < no_of_enemies; i++) { // For every enemy = Entity B
--- a/RoomEngine/RoomEngine.h Thu May 09 09:50:19 2019 +0000
+++ b/RoomEngine/RoomEngine.h Thu May 09 14:43:45 2019 +0000
@@ -11,74 +11,243 @@
#define MAX_ROOMS_MAP_X 11
#define MAX_ROOMS_MAP_Y 11
-
+/**RoomEngine Class
+@author Steven Mahasin
+@brief Handles all Inter-Class Interactions in the room
+@date May 2019
+*/
class RoomEngine
{
public:
- // Constructor
+ /** Constructor
+ * @param global_contrast @details the contrast that the game runs on, set by title screen
+ */
RoomEngine(float global_contrast);
- // Destructor
+ /** Destructor */
~RoomEngine();
// Functions
+ /**
+ * @brief loads the current player and room into the engine
+ * @param current_player @details the player we control
+ * @param current_room @details the room the player is currently in
+ */
void load(Player *current_player, Room *current_room);
+ /**
+ * @brief plays an entrance_scene of the player into the room
+ * @param lcd @details the screen that is being drawn on
+ * @param gamepad @details the gamepad whose controls are being read
+ */
void entrance_scene(N5110 &lcd, Gamepad &gamepad);
+ /**
+ * @brief increments the room coordinate based on which side the player exits the screen from
+ */
void update_current_room();
+ /**
+ * @brief returns 0-4 based on the player's position in the screen
+ * @return which side of the screen the player is currently at (4 = inside)
+ */
int check_player_room_position();
+ /**
+ * @brief reads the input from the gamepad and converts it into member variables
+ * @param gamepad @details the gamepad whose controls are being read
+ */
void read_input(Gamepad &gamepad);
+ /**
+ * @brief updates the interaction between entities in room (enemies hp, damage, etc)
+ * @param number_of_enemies_killed @details for the final score, gets incremented everytime an enemy is killed
+ */
void update(int &number_of_enemies_killed);
+ /**
+ * @brief to draw all the map, entities, doorway onto the screen
+ * @param lcd @details the screen that the roomengine draws on
+ */
void render(N5110 &lcd, Gamepad &gamepad);
+ /**
+ * @brief Plays an exit scene of the player leaving the room
+ * @param lcd @details the screen that the exit scene is drawn on
+ * @param gamepad @details the gamepad whose controls are being read
+ */
void exit_scene(N5110 &lcd, Gamepad &gamepad);
// Accessor
+ /**
+ * @brief reads the member variable _room_x
+ * @return the current room's x-coordinate
+ */
int get_room_x();
+ /**
+ * @brief reads the member variable _room_y
+ * @return the current room's y-coordinate
+ */
int get_room_y();
private:
// Member variables
+ /**
+ * @brief A boolean to indicate if button L is pressed
+ */
bool _L;
+ /**
+ * @brief A boolean to indicate if button R is pressed
+ */
bool _R;
+ /**
+ * @brief A boolean to indicate if button A is pressed
+ */
bool _A;
+ /**
+ * @brief A boolean to indicate if button B is pressed
+ */
bool _B;
+ /**
+ * @brief A boolean to indicate if button X is pressed
+ */
bool _X;
+ /**
+ * @brief A boolean to indicate if button Y is pressed
+ */
bool _Y;
+ /**
+ * @brief A vector2D that stores the x and y of the mapped_coordinates of the joystick
+ */
Vector2D mapped_coord;
-
+ /**
+ * @brief The x-coordinate value for the current room's position
+ */
int _room_x;
+ /**
+ * @brief The y-coordinate value for the current room's position
+ */
int _room_y;
-
+ /**
+ * @brief The value of set contrast from title screen, which dictates the contrast of lcd
+ */
float _global_contrast;
-
+ /**
+ * @brief A pointer to a Room, used to access the current room class and it's functions
+ */
Room *room;
+ /**
+ * @brief A pointer to a Player, used to access the current player class and it's functions
+ */
Player *player;
// Mutator
+ /**
+ * @brief mutates all the user input manually
+ * @param L @details value to be written onto _L
+ * @param R @details value to be written onto _R
+ * @param A @details value to be written onto _A
+ * @param B @details value to be written onto _B
+ * @param X @details value to be written onto _X
+ * @param Y @details value to be written onto _Y
+ * @param mapped_x @details value to be written onto _mapped_coord.x
+ * @param mapped_y @details value to be written onto _mapped_coord.y
+ */
void set_input(bool L, bool R, bool A, bool B, bool X, bool Y, float mapped_x, float mapped_y);
+ /**
+ * @brief mutates _mapped_coord manually
+ * @param mapped_x @details value to be written onto _mapped_coord.x
+ * @param mapped_y @details value to be written onto _mapped_coord.y
+ */
void set_mapped_coord(float x, float y);
// Methods
+ /**
+ * @brief checks if the two entities a and b collide
+ * @param a @details entity a to be checked if colliding with entity b
+ * @param b @details entity b to be checked if colliding with entity a
+ * @return true if the two entities collide
+ */
bool entity_collision(Entity &a, Entity &b);
+ /**
+ * @brief checks if the entity a collides with any entities in the entity array "array[]" if entity a moves in the x direction
+ * @param a @details entity a to be checked if colliding with any entity in the array[]
+ * @param array[] @details an array of entities to be check if colliding with a
+ * @param no_of_enemies @details constant length of enemies in the array[]
+ * @param current_entity @details the index of the enemy to be ignored if entity a is within array[]
+ * @param valid_enemies[] @details the array that defines which entities in array[] exists
+ * @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
+ */
float entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]);
+ /**
+ * @brief checks if the entity a collides with any entities in the entity array "array[]" if entity a moves in the y direction
+ * @param a @details entity a to be checked if colliding with any entity in the array[]
+ * @param array[] @details an array of entities to be check if colliding with a
+ * @param no_of_enemies @details constant length of enemies in the array[]
+ * @param current_entity @details the index of the enemy to be ignored if entity a is within array[]
+ * @param valid_enemies[] @details the array that defines which entities in array[] exists
+ * @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
+ */
float entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]);
+ /**
+ * @brief inflict any damage happening to any entities in the room
+ */
void check_damage();
+ /**
+ * @brief inflict any damage happening to the player in the room
+ */
void check_damage_player();
+ /**
+ * @brief inflict any damage happening to any enemies in the room
+ */
void check_damage_enemies();
+ /**
+ * @brief delete any enemies that has it's health depleted
+ * @param number_of_enemies_killed @details increments whenever an enemy is successfully deleted
+ */
void check_enemies_death(int &number_of_enemies_killed);
+ /**
+ * @brief undo movement of entity if the entity collides with the wall (not used in this version)
+ */
void check_walls_collision();
+ /**
+ * @brief updates the positions of all entities
+ */
void move();
+ /**
+ * @brief updates the positions of player based on the joystick and wall constraint
+ */
void move_player();
+ /**
+ * @brief updates the positions of enemies based on their coded movement patterns, repulsion effect and wall constraint
+ */
void move_enemies();
+ /**
+ * @brief updates the position of the player whenever the player has just exit the screen
+ * @param side @details the side the player exits the room from
+ */
void update_player_position(int side);
+ /**
+ * @brief holds the loop and detection for when a player pauses
+ * @param lcd @details the screen where the paused screen is going to be displayed on
+ * @param gamepad @details the gamepad whose controls are being read
+ */
void pause_detection(N5110 &lcd, Gamepad &gamepad);
+ /**
+ * @brief draws the pause screen onto lcd
+ * @param lcd @details the screen where the paused screen is going to be displayed on
+ * @param paused_screen @details the char array of the frozen screen when paused
+ * @param pause_timer @details the loop count to check if the pause sprite should appear or not for blink effect
+ */
void draw_pause_screen(N5110 &lcd, char * paused_screen, int &pause_timer);
+ /**
+ * @brief draws the map, the entities and map overlays in the order of descending j
+ * @param lcd @details the screen where all entities are being drawn on
+ */
void draw(N5110 &lcd);
+ /**
+ * @brief draws number of hp as hearts on the top left of the screen whenever the user holds button L
+ * @param lcd @details the screen where the hearts are being drawn on
+ */
void draw_health(N5110 &lcd);
};
--- a/Title/Title.h Thu May 09 09:50:19 2019 +0000
+++ b/Title/Title.h Thu May 09 14:43:45 2019 +0000
@@ -13,30 +13,85 @@
{
private:
// Member Variables
+ /**
+ * @brief a counter that increments per loop, used to detect delays
+ */
int _title_count;
+ /**
+ * @brief a delay period for the joystick to update another right or left input
+ */
int _cursor_timer;
+ /**
+ * @brief an integer that stores which option the cursor is on
+ * @note 0 = Start, 1 = Options, 2 = Credits, 3 = Tutorial
+ */
int _title_option;
// Methods
+ /**
+ * @brief This function is used to draw the title screen along with the animations
+ * @param lcd @details the screen the title screen is drawn on
+ */
void draw_title_screen(N5110 &lcd);
+ /**
+ * @brief This function is used to read the gamepad buttons and joystick, interracting with the member variable _title_option
+ * @param gamepad @details the gamepad the input is being read from
+ */
void title_options_joystick(Gamepad &gamepad);
+ /**
+ * @brief This function is called when the user chooses the title option "Option"
+ * @param lcd @details the screen the Options screen is drawn on
+ * @param gamepad @details the gamepad used to read the potentiometer
+ * @param player @details the player that is being used as a demo for the options screen
+ * @param global_contrast @details the global contrast that is being varried to be set for the whole game
+ */
void title_option_option(N5110 &lcd, Gamepad &gamepad, Player &player, float &global_contrast);
+ /**
+ * @brief This function is called when the user chooses the title option "Credit"
+ * @param lcd @details the screen the credits is being displayed on
+ * @param gamepad @details the gamepad is used to read when the user decides to exit the credit page (button A)
+ */
void title_option_credit(N5110 &lcd, Gamepad &gamepad);
+ /**
+ * @brief This function is called when the user chooses the title option "Tutorial"
+ * @param lcd @details the screen tutotrial is being displayed on
+ * @param gamepad @details the gamepad is used to read when the user decides to go to the next tutorial page (button A)
+ */
void title_option_tutorial(N5110 &lcd, Gamepad &gamepad);
+ /**
+ * @brief This function is displays tutorial page 0
+ * @param lcd @details the screen the credits is being displayed on
+ */
void print_tutorial_page_0(N5110 &lcd);
+ /**
+ * @brief This function is displays tutorial page 1
+ * @param lcd @details the screen the credits is being displayed on
+ */
void print_tutorial_page_1(N5110 &lcd);
+ /**
+ * @brief This function is displays tutorial page 2
+ * @param lcd @details the screen the credits is being displayed on
+ */
void print_tutorial_page_2(N5110 &lcd);
public:
- // Constructor
+ /** Constructor */
Title();
// Accessor
+ /** @brief to get the seed for rand()
+ * @returns _title_count
+ */
int get_seed();
// Functions
+ /** @brief This function runs the whole Title screen, it contains the title loop and calls for the rest of the methods
+ * @param lcd @details the screen the Title screen is being displayed on
+ * @param gamepad @details the input the Title screen processes
+ * @param global_contrast @details the variable that is varied by the Title screen to chance screen contrast
+ */
void main(N5110 &lcd, Gamepad &gamepad, float &global_contrast);
};