Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Embed: (wiki syntax)

« Back to documentation index

Player Class Reference

Player Class. More...

#include <Player.h>

Inherits Entity.

Public Member Functions

 Player (float pos_x, float pos_y)
 Constructor.
 ~Player ()
 Deconstructors.
int get_bullet_speed ()
 getting the player's bullet speed
int get_hearts_width ()
 getting the heart sprite's width
int get_hearts_height ()
 getting the heart sprite's height
char * get_hearts_sprite ()
 getting the heart sprite char array
virtual void move (float x_value, float y_value, char *map, bool *doorways)
 function calls both movement of player and movement of bullets
virtual void take_damage (int damage)
 reduce _hp by damage
virtual void draw (N5110 &lcd)
 a virtual function of drawing the player onto the screen
void draw_bullets (N5110 &lcd, int j)
 a virtual function of drawing the bullets the player shot onto the screen if j is the correct y-position of the bullets
bool delete_out_of_bounds_bullets (char *map, bool *doorways)
 attempts to delete any bullets that goes out of bounds (out of screen or onto a wall)
void delete_bullets ()
 deletes any existing bullets
void buttons (bool button_A, bool button_B, bool button_Y, bool button_X)
 shoots bullets at the direction of the buttons
void undo_move_x (bool condition)
 a function to undo entity's movement in the x direction if condition is true
void undo_move_y (bool condition)
 a function to undo entity's movement in the y direction if condition is true
void update_prev_pos ()
 updates the _prev_pos into _position
bool entity_to_map_collision_test (float pos_x, float pos_y, char *two_d_map, bool *doorways)
 checks if the entity collides the map
void set_position (float x, float y)
 mutates position of the entity to x and y
void position_add_x (float change_x)
 adds change_x onto x-position of the entity
void position_add_y (float change_y)
 adds change_y onto y-position of the entity
int get_hp_drop_chance ()
 gets the entity's chance to drop a health
int get_hitbox_width ()
 gets the entity's hitbox width
int get_hitbox_height ()
 gets the entity's hitbox height
int get_face ()
 gets the entity's face
int get_sprite_width ()
 gets the entity's sprite width
int get_sprite_height ()
 gets the entity's sprite height
int get_offset_x ()
 gets the entity's sprite x-offset
int get_offset_y ()
 gets the entity's sprite y-offset
int get_pos_x ()
 gets the entity's x-position
int get_pos_y ()
 gets the entity's y-position
int get_prev_pos_x ()
 gets the entity's previous x-position
int get_prev_pos_y ()
 gets the entity's previous y-position
int get_attack ()
 gets the entity's attack
int get_hp ()
 gets the entity's hp
float get_velocity ()
 gets the entity's velocity

Data Fields

Bulletsbullets_array [bullets_max]
 a bullets pointer array that holds all the possible bullets the player can shoot
bool valid_bullets [bullets_max]
 a boolean array that dictates which bullets in the bullets array exist

Protected Attributes

Hitbox _hitbox
 A struct containing hitbox data for the entity width and height.
SpriteSize _sprite_size
 A struct containing sprite size data for the entity, to be used when drawing sprites on top of their hitboxes sprite width, sprite height, sprite offset x from hitbox, sprite offset y from hitbox.
Position _position
 A struct containing the position of the entity, this position is the top-left corner of the hitbox.
Position _prev_pos
 A struct containing the position of the entity one loop behind.
FrameCount _frame
 A struct containing frame count, frame number and frame max.
int _hp
 The health point of an entity.
int _attack
 The damage the entity does if it attacks another entity.
int _face
 The direction the entity is facing.
float _velocity
 The speed the entity moves.
int _hp_drop_chance
 The chance(out of 100) of dropping a heart when the entity is deleted.

Detailed Description

Player Class.

Author:
Steven Mahasin Creates a Player which inherits the Entity class, contains functions that accepts all user interractions (buttons, joystick, etc)
Date:
May 2019

Definition at line 13 of file Player.h.


Constructor & Destructor Documentation

Player ( float  pos_x,
float  pos_y 
)

Constructor.

creates a player at positions pos_x and pos_y

Parameters:
pos_xinitialise _position.x
pos_yinitialise _position.y

Definition at line 5 of file Player.cpp.

~Player (  )

Deconstructors.

Definition at line 39 of file Player.cpp.


Member Function Documentation

void buttons ( bool  button_A,
bool  button_B,
bool  button_Y,
bool  button_X 
)

shoots bullets at the direction of the buttons

Parameters:
button_Abutton down
button_Bbutton right
button_Ybutton up
button_Xbutton left

Definition at line 181 of file Player.cpp.

void delete_bullets (  )

deletes any existing bullets

Definition at line 163 of file Player.cpp.

bool delete_out_of_bounds_bullets ( char *  map,
bool *  doorways 
)

attempts to delete any bullets that goes out of bounds (out of screen or onto a wall)

Parameters:
mapthe 2d map array that dictates where there are walls or empty space
doorawysan array that dictates which side of the wall has a doorway
Returns:
true if any bullets is successfully deleted

Definition at line 127 of file Player.cpp.

void draw ( N5110 lcd ) [virtual]

a virtual function of drawing the player onto the screen

Parameters:
lcdthe screen where the player is drawn on

Implements Entity.

Definition at line 140 of file Player.cpp.

void draw_bullets ( N5110 lcd,
int  j 
)

a virtual function of drawing the bullets the player shot onto the screen if j is the correct y-position of the bullets

Parameters:
lcdthe screen where the bullets is drawn on
jwhich y-position hitboxes are currently being printed

Definition at line 154 of file Player.cpp.

bool entity_to_map_collision_test ( float  pos_x,
float  pos_y,
char *  two_d_map,
bool *  doorways 
) [inherited]

checks if the entity collides the map

Parameters:
pos_xentity's x-position
pos_yentity's y-position
two_d_mapthe 2d map array that dictates where there are walls or empty space
doorwaysan array that dictates which side of the wall has a doorway
Returns:
true if entity collide with the map

Definition at line 21 of file Entity.cpp.

int get_attack (  ) [inherited]

gets the entity's attack

Returns:
_attack

Definition at line 114 of file Entity.cpp.

int get_bullet_speed (  )

getting the player's bullet speed

Returns:
_bullet_speed

Definition at line 45 of file Player.cpp.

int get_face (  ) [inherited]

gets the entity's face

Returns:
_face

Definition at line 78 of file Entity.cpp.

int get_hearts_height (  )

getting the heart sprite's height

Returns:
height of the heart sprite

Definition at line 53 of file Player.cpp.

char * get_hearts_sprite (  )

getting the heart sprite char array

Returns:
char pointer array to the heart sprite

Definition at line 57 of file Player.cpp.

int get_hearts_width (  )

getting the heart sprite's width

Returns:
width of the heart sprite

Definition at line 49 of file Player.cpp.

int get_hitbox_height (  ) [inherited]

gets the entity's hitbox height

Returns:
_hitbox.height

Definition at line 74 of file Entity.cpp.

int get_hitbox_width (  ) [inherited]

gets the entity's hitbox width

Returns:
_hitbox.width

Definition at line 70 of file Entity.cpp.

int get_hp (  ) [inherited]

gets the entity's hp

Returns:
_hp

Definition at line 118 of file Entity.cpp.

int get_hp_drop_chance (  ) [inherited]

gets the entity's chance to drop a health

Returns:
_hp_drop_chance

Definition at line 66 of file Entity.cpp.

int get_offset_x (  ) [inherited]

gets the entity's sprite x-offset

Returns:
_sprite_size.offset_x

Definition at line 90 of file Entity.cpp.

int get_offset_y (  ) [inherited]

gets the entity's sprite y-offset

Returns:
_sprite_size.offset_y

Definition at line 94 of file Entity.cpp.

int get_pos_x (  ) [inherited]

gets the entity's x-position

Returns:
_position.x

Definition at line 98 of file Entity.cpp.

int get_pos_y (  ) [inherited]

gets the entity's y-position

Returns:
_position.y

Definition at line 102 of file Entity.cpp.

int get_prev_pos_x (  ) [inherited]

gets the entity's previous x-position

Returns:
_prev_pos.x

Definition at line 106 of file Entity.cpp.

int get_prev_pos_y (  ) [inherited]

gets the entity's previous y-position

Returns:
_prev_pos.y

Definition at line 110 of file Entity.cpp.

int get_sprite_height (  ) [inherited]

gets the entity's sprite height

Returns:
_sprite_size.height

Definition at line 86 of file Entity.cpp.

int get_sprite_width (  ) [inherited]

gets the entity's sprite width

Returns:
_sprite_size.width

Definition at line 82 of file Entity.cpp.

float get_velocity (  ) [inherited]

gets the entity's velocity

Returns:
_velocity

Definition at line 122 of file Entity.cpp.

void move ( float  x_value,
float  y_value,
char *  map,
bool *  doorways 
) [virtual]

function calls both movement of player and movement of bullets

Parameters:
x_valuejoystick x
y_valuejoystick y
mapthe 2d map array that dictates where there are walls or empty space
doorwaysan array that dictates which side of the wall has a doorway

Implements Entity.

Definition at line 63 of file Player.cpp.

void position_add_x ( float  change_x ) [inherited]

adds change_x onto x-position of the entity

Parameters:
change_xdisplacement x

Definition at line 56 of file Entity.cpp.

void position_add_y ( float  change_y ) [inherited]

adds change_y onto y-position of the entity

Parameters:
change_ydisplacement y

Definition at line 60 of file Entity.cpp.

void set_position ( float  x,
float  y 
) [inherited]

mutates position of the entity to x and y

Parameters:
xx-coordinate value
yy-coordinate value

Definition at line 50 of file Entity.cpp.

void take_damage ( int  damage ) [virtual]

reduce _hp by damage

Parameters:
damagethe amount of damage to be taken

Implements Entity.

Definition at line 113 of file Player.cpp.

void undo_move_x ( bool  condition ) [inherited]

a function to undo entity's movement in the x direction if condition is true

Parameters:
conditiona boolean statement

Definition at line 4 of file Entity.cpp.

void undo_move_y ( bool  condition ) [inherited]

a function to undo entity's movement in the y direction if condition is true

Parameters:
conditiona boolean statement

Definition at line 10 of file Entity.cpp.

void update_prev_pos (  ) [inherited]

updates the _prev_pos into _position

Definition at line 16 of file Entity.cpp.


Field Documentation

int _attack [protected, inherited]

The damage the entity does if it attacks another entity.

Definition at line 67 of file Entity.h.

int _face [protected, inherited]

The direction the entity is facing.

Definition at line 71 of file Entity.h.

FrameCount _frame [protected, inherited]

A struct containing frame count, frame number and frame max.

Used to animate entities

Definition at line 59 of file Entity.h.

Hitbox _hitbox [protected, inherited]

A struct containing hitbox data for the entity width and height.

Definition at line 42 of file Entity.h.

int _hp [protected, inherited]

The health point of an entity.

Definition at line 63 of file Entity.h.

int _hp_drop_chance [protected, inherited]

The chance(out of 100) of dropping a heart when the entity is deleted.

Definition at line 79 of file Entity.h.

Position _position [protected, inherited]

A struct containing the position of the entity, this position is the top-left corner of the hitbox.

Definition at line 51 of file Entity.h.

Position _prev_pos [protected, inherited]

A struct containing the position of the entity one loop behind.

Definition at line 55 of file Entity.h.

SpriteSize _sprite_size [protected, inherited]

A struct containing sprite size data for the entity, to be used when drawing sprites on top of their hitboxes sprite width, sprite height, sprite offset x from hitbox, sprite offset y from hitbox.

Definition at line 47 of file Entity.h.

float _velocity [protected, inherited]

The speed the entity moves.

Definition at line 75 of file Entity.h.

Bullets* bullets_array[bullets_max]

a bullets pointer array that holds all the possible bullets the player can shoot

Definition at line 146 of file Player.h.

bool valid_bullets[bullets_max]

a boolean array that dictates which bullets in the bullets array exist

Definition at line 150 of file Player.h.