Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Revision:
57:1c12361b6e3d
Parent:
52:7d05e5472022
--- a/Entity/Player/Player.cpp	Thu May 09 08:42:52 2019 +0000
+++ b/Entity/Player/Player.cpp	Thu May 09 09:50:19 2019 +0000
@@ -4,35 +4,35 @@
 // Constructor
 Player::Player(float pos_x, float pos_y)
 {
-    hp = 3;
-    attack = 1;
-    face = 2;
+    _hp = 3;
+    _attack = 1;
+    _face = 2;
     
-    hitbox.width = 6;
-    hitbox.height = 5;
+    _hitbox.width = 6;
+    _hitbox.height = 5;
     
-    position.x = pos_x;
-    position.y = pos_y;
+    _position.x = pos_x;
+    _position.y = pos_y;
     
-    sprite_size.width = 6;
-    sprite_size.height = 12;
-    sprite_size.offset_x = 0;
-    sprite_size.offset_y = -7;
+    _sprite_size.width = 6;
+    _sprite_size.height = 12;
+    _sprite_size.offset_x = 0;
+    _sprite_size.offset_y = -7;
     
-    frame.count = 0;
-    frame.number = 0;
-    frame.max = 4;
+    _frame.count = 0;
+    _frame.number = 0;
+    _frame.max = 4;
     
     for (int i = 0; i < bullets_max; i++) {
         valid_bullets[i] = false;
     }
     
-    invulnerability_counter = INVULNERABILITY_PERIOD;
+    _invulnerability_counter = INVULNERABILITY_PERIOD;
 
     // Upgradable status
-    fire_rate_delay = 30;
-    fire_rate_counter = fire_rate_delay;
-    velocity = 0.7;
+    _fire_rate_delay = 30;
+    _fire_rate_counter = _fire_rate_delay;
+    _velocity = 0.7;
     _bullet_speed = 1;
 }
 
@@ -65,17 +65,17 @@
     move_player(mapped_x, mapped_y, map, doorways);
     move_bullets();
     increment_frames(mapped_x, mapped_y);   // Sets the face of the person, and increment frame count
-    invulnerability_counter++;  // for damage checking
+    _invulnerability_counter++;  // for damage checking
 }
 
 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;
-    position.x += velocity*mapped_x;
+    _position.y -= _velocity*mapped_y;
+    _position.x += _velocity*mapped_x;
     
-    undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
-    undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
+    undo_move_x(entity_to_map_collision_test(_position.x, _prev_pos.y, map, doorways));
+    undo_move_y(entity_to_map_collision_test(_prev_pos.x, _position.y, map, doorways));
 }
 
 void Player::move_bullets() // For each bullet, move them
@@ -91,36 +91,36 @@
 {
     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;
+            _face = 2;
         } else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)) {
-            face = 0;
+            _face = 0;
         } else if (mapped_x > 0 && abs(mapped_x) > abs(mapped_y)) {
-            face = 1;
+            _face = 1;
         } else if (mapped_x < 0 && abs(mapped_x) > abs(mapped_y)) {
-            face = 3;
+            _face = 3;
         }
-        if (frame.number < frame.max) { // Animate frames by incrementing and reseting frames
-            frame.count++;
+        if (_frame.number < _frame.max) { // Animate frames by incrementing and reseting frames
+            _frame.count++;
         } else {
-            frame.count = 0;
+            _frame.count = 0;
         }
     } else {
-        frame.count = 0;    // If the player is not moving, don't animate
+        _frame.count = 0;    // If the player is not moving, don't animate
     }
-    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
+    _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)    // Takes damage unless if player just got damaged within invulnerability period
 {
     if (damage < 0){
-        hp -= damage;
+        _hp -= damage;
     }
-    else if (invulnerability_counter >= INVULNERABILITY_PERIOD) {
-        hp -= damage;
-        invulnerability_counter = 0;
+    else if (_invulnerability_counter >= INVULNERABILITY_PERIOD) {
+        _hp -= damage;
+        _invulnerability_counter = 0;
     }
-    if (hp > 5) {   // Max HP is a constant 5, this might be an upgradable status later
-        hp = 5;
+    if (_hp > 5) {   // Max HP is a constant 5, this might be an upgradable status later
+        _hp = 5;
     }
 }
 
@@ -144,10 +144,10 @@
 
 void Player::draw_player(N5110 &lcd)
 {
-    lcd.drawSpriteTransparent(position.x+sprite_size.offset_x,
-                              position.y+sprite_size.offset_y,
-                              sprite_size.height,
-                              sprite_size.width,
+    lcd.drawSpriteTransparent(_position.x+_sprite_size.offset_x,
+                              _position.y+_sprite_size.offset_y,
+                              _sprite_size.height,
+                              _sprite_size.width,
                               get_frame());
 }
 
@@ -172,30 +172,30 @@
 
 char * Player::get_frame()  // Returns the current frame's sprite pointer
 {
-    if ((invulnerability_counter < INVULNERABILITY_PERIOD) && (invulnerability_counter % 10 <= 4)) {
+    if ((_invulnerability_counter < INVULNERABILITY_PERIOD) && (_invulnerability_counter % 10 <= 4)) {
         return (char*) sprite_transparent_player;
     }
-    return (char *) sprite_player[face][frame.number];
+    return (char *) sprite_player[_face][_frame.number];
 }
 
 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++;
+    _fire_rate_counter++;
     if (button_Y) {
-        face = 0;
+        _face = 0;
     } else if (button_B) {
-        face = 1;
+        _face = 1;
     } else if (button_A) {
-        face = 2;
+        _face = 2;
     } else if (button_X) {
-        face = 3;
+        _face = 3;
     }
     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)) {  // 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);
+            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;
+                _fire_rate_counter = 0;
                 break;
             }
         }