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
Diff: Entity/Player/Player.cpp
- Revision:
- 52:7d05e5472022
- Parent:
- 51:4d0cd75e7ed3
- Child:
- 57:1c12361b6e3d
diff -r 4d0cd75e7ed3 -r 7d05e5472022 Entity/Player/Player.cpp
--- a/Entity/Player/Player.cpp Thu May 09 07:39:49 2019 +0000
+++ b/Entity/Player/Player.cpp Thu May 09 07:47:58 2019 +0000
@@ -60,15 +60,15 @@
}
// Functions
-void Player::move(float mapped_x, float mapped_y, char * map, bool * doorways)
+void Player::move(float mapped_x, float mapped_y, char * map, bool * doorways) // Update all bullet movement and player movement, also takes care of animation
{
move_player(mapped_x, mapped_y, map, doorways);
move_bullets();
- increment_frames(mapped_x, mapped_y);
- invulnerability_counter++;
+ increment_frames(mapped_x, mapped_y); // Sets the face of the person, and increment frame count
+ invulnerability_counter++; // for damage checking
}
-void Player::move_player(float mapped_x, float mapped_y, char * map, bool * doorways)
+void Player::move_player(float mapped_x, float mapped_y, char * map, bool * doorways) // Moves the player unless if the player walks onto a wall
{
update_prev_pos();
position.y -= velocity*mapped_y;
@@ -78,7 +78,7 @@
undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
}
-void Player::move_bullets()
+void Player::move_bullets() // For each bullet, move them
{
for (int i = 0; i < bullets_max; i++) {
if (valid_bullets[i]) {
@@ -89,7 +89,7 @@
void Player::increment_frames(float mapped_x, float mapped_y)
{
- if (abs(mapped_x) + abs(mapped_y) > 0.1f) {
+ if (abs(mapped_x) + abs(mapped_y) > 0.1f) { // If player is moving
if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)) {
face = 2;
} else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)) {
@@ -99,18 +99,18 @@
} else if (mapped_x < 0 && abs(mapped_x) > abs(mapped_y)) {
face = 3;
}
- if (frame.number < frame.max) {
+ if (frame.number < frame.max) { // Animate frames by incrementing and reseting frames
frame.count++;
} else {
frame.count = 0;
}
} else {
- frame.count = 0;
+ frame.count = 0; // If the player is not moving, don't animate
}
- frame.number = (frame.count/8) % frame.max;
+ frame.number = (frame.count/8) % frame.max; // Frame number is used in chosing sprite-frame for animation; the constant 8 is the number of frames per sprite-frame
}
-void Player::take_damage(int damage)
+void Player::take_damage(int damage) // Takes damage unless if player just got damaged within invulnerability period
{
if (damage < 0){
hp -= damage;
@@ -119,12 +119,12 @@
hp -= damage;
invulnerability_counter = 0;
}
- if (hp > 5) {
+ if (hp > 5) { // Max HP is a constant 5, this might be an upgradable status later
hp = 5;
}
}
-bool Player::delete_out_of_bounds_bullets(char * map, bool * doorways)
+bool Player::delete_out_of_bounds_bullets(char * map, bool * doorways) // Attempts to delete bullets that are out of bounds or colliding with the wall, returns true if any bullets are deleted
{
bool result = false;
for (int i = 0; i < bullets_max; i++) {
@@ -160,7 +160,7 @@
}
}
-void Player::delete_bullets()
+void Player::delete_bullets() // Delete all bullets, normally used in unloading
{
for (int i = 0; i < bullets_max; i++) {
if (valid_bullets[i]) {
@@ -170,7 +170,7 @@
}
}
-char * Player::get_frame()
+char * Player::get_frame() // Returns the current frame's sprite pointer
{
if ((invulnerability_counter < INVULNERABILITY_PERIOD) && (invulnerability_counter % 10 <= 4)) {
return (char*) sprite_transparent_player;
@@ -178,7 +178,7 @@
return (char *) sprite_player[face][frame.number];
}
-void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X)
+void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X) // Summons new bullets and overloads the player face when buttons are pressed
{
fire_rate_counter++;
if (button_Y) {
@@ -192,7 +192,7 @@
}
if (button_Y || button_B || button_A || button_X) {
for (int i = 0; i < bullets_max; i++) {
- if (!valid_bullets[i] && (fire_rate_counter >= fire_rate_delay)) {
+ if (!valid_bullets[i] && (fire_rate_counter >= fire_rate_delay)) { // waits until fire_rate_delay is done before creating a bullet in an invalid slot of bullet_array
bullets_array[i] = new Bullets(position.x+2, position.y+2, face);
valid_bullets[i] = true;
fire_rate_counter = 0;