Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Revision:
57:1c12361b6e3d
Parent:
54:03ddad11d202
--- a/Entity/Mobs/Snake/Snake.cpp	Thu May 09 08:42:52 2019 +0000
+++ b/Entity/Mobs/Snake/Snake.cpp	Thu May 09 09:50:19 2019 +0000
@@ -5,69 +5,69 @@
 // Constructor
 Snake::Snake(float pos_x, float pos_y)
 {
-    hp = 4;
-    attack = 1;
-    face = 0;
+    _hp = 4;
+    _attack = 1;
+    _face = 0;
     _prev_face = 0;
     _hp_drop_chance = 10; // out of 100
     
-    hitbox.width = 4;
-    hitbox.height = 7;
+    _hitbox.width = 4;
+    _hitbox.height = 7;
     
-    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 = -1;
-    sprite_size.offset_y = -6;
+    _sprite_size.width = 6;
+    _sprite_size.height = 12;
+    _sprite_size.offset_x = -1;
+    _sprite_size.offset_y = -6;
     
-    frame.count = 0;
-    frame.number = 0;
-    frame.max = 6;
+    _frame.count = 0;
+    _frame.number = 0;
+    _frame.max = 6;
     
-    velocity = 0;
+    _velocity = 0;
     _velocity_index = 0;
 }
 // Member Function
 void Snake::update_prev_face()
 {
-    _prev_face = face;
+    _prev_face = _face;
 }
 
 // Member Mutator
-void Snake::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)     // Offset, Hitbox and Frame Count update
+void Snake::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)     // Offset, Hitbox and Frame Count update
 {
-    if (_prev_face != face) {
-        frame.number = 0;   // Resets animation everytime face changes
-        hitbox.width = hitbox_width;
-        hitbox.height = hitbox_height;
+    if (_prev_face != _face) {
+        _frame.number = 0;   // Resets animation everytime face changes
+        _hitbox.width = _hitbox_width;
+        _hitbox.height = _hitbox_height;
         
-        sprite_size.width = sprite_size_width;
-        sprite_size.height = sprite_size_height;
-        sprite_size.offset_x = sprite_size_offset_x;
-        sprite_size.offset_y = sprite_size_offset_y;
+        _sprite_size.width = _sprite_size_width;
+        _sprite_size.height = _sprite_size_height;
+        _sprite_size.offset_x = _sprite_size_offset_x;
+        _sprite_size.offset_y = _sprite_size_offset_y;
         
-        frame.max = max_frame;
+        _frame.max = max_frame;
     }
 }
 
 // Functions
 void Snake::move(float player_x, float player_y, char * map, bool * doorways)
 {
-    float diff_x = player_x - position.x;
-    float diff_y = player_y - position.y;
-    velocity = snake_velocity_pattern[_velocity_index]; // Creating slithering effect, changing velocity of movement
+    float diff_x = player_x - _position.x;
+    float diff_y = player_y - _position.y;
+    _velocity = snake_velocity_pattern[_velocity_index]; // Creating slithering effect, changing velocity of movement
     update_prev_face();
 
     // Setting Face
     update_face(diff_x, diff_y);
 
     // Movement
-    move_snake(); // Movement and updating hitboxes
+    move_snake(); // Movement and updating _hitboxes
 
-    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));
 
     increment_frame();
 }
@@ -77,77 +77,77 @@
     if (_velocity_index == 0) {
         if (abs(diff_x) > abs(diff_y)) {
             if (diff_x > 0) {
-                face = 1;
+                _face = 1;
             } else {
-                face = 3;
+                _face = 3;
             }
         } else {
             if (diff_y > 0) {
-                face = 2;
+                _face = 2;
             } else {
-                face = 0;
+                _face = 0;
             }
         }
     }
 }
 
-void Snake::move_snake()    // Moves the Snake according to velocity, updates the hitboxes everytime it changes face
+void Snake::move_snake()    // Moves the Snake according to velocity, updates the _hitboxes everytime it changes face
 {
-    if (face == 0) {
-        position.y -= velocity;
+    if (_face == 0) {
+        _position.y -= _velocity;
         update_hitbox(4, 7, 6, 12, -1, -6, 6);
-    } else if (face == 1) {
-        position.x += velocity;
+    } else if (_face == 1) {
+        _position.x += _velocity;
         update_hitbox(7, 4, 12, 7, -6, -4, 4);
-    } else if (face == 2) {
-        position.y += velocity;
+    } else if (_face == 2) {
+        _position.y += _velocity;
         update_hitbox(4, 7, 6, 12, -1, -5, 6);
-    } else if (face == 3) {
-        position.x -= velocity;
+    } else if (_face == 3) {
+        _position.x -= _velocity;
         update_hitbox(7, 4, 12, 7, 0, -4, 4);
     }
 }
 
 void Snake::increment_frame()   // Frame increment and velocity index increment
 {
-    frame.count++;
-    if (frame.count >= 10) {    // Every 10 frames, sprite_frames increments and velocity_index increments
-        frame.count = 0;
+    _frame.count++;
+    if (_frame.count >= 10) {    // Every 10 frames, sprite_frames increments and velocity_index increments
+        _frame.count = 0;
         _velocity_index++;
-        frame.number++;
+        _frame.number++;
         if (_velocity_index >= 6) { // Velocity_index max; reset
             _velocity_index = 0;
         }
-        if (frame.number >= frame.max) {    // Frame.number max; reset
-            frame.number = 0;
+        if (_frame.number >= _frame.max) {    // Frame.number max; reset
+            _frame.number = 0;
         }
     }
 }
 
 void Snake::take_damage(int damage)
 {
-    hp -= damage;
+    _hp -= damage;
 }
 
 char * Snake::get_frame()   // Returns the frame needed
 {
-    if(face == 0) {
-        return (char *) sprite_snake_y[0][frame.number];
-    } else if(face == 1) {
-        return (char *) sprite_snake_x[0][frame.number];
-    } else if(face == 2) {
-        return (char *) sprite_snake_y[1][frame.number];
-    } else if(face == 3) {
-        return (char *) sprite_snake_x[1][frame.number];
+    if(_face == 0) {
+        return (char *) sprite_snake_y[0][_frame.number];
+    } else if(_face == 1) {
+        return (char *) sprite_snake_x[0][_frame.number];
+    } else if(_face == 2) {
+        return (char *) sprite_snake_y[1][_frame.number];
+    } else if(_face == 3) {
+        return (char *) sprite_snake_x[1][_frame.number];
     }
     return 0;
 }
 
 void Snake::draw(N5110 &lcd)
 {
-    lcd.drawSpriteTransparent(get_pos_x()+sprite_size.offset_x,
-                              get_pos_y()+sprite_size.offset_y,
-                              sprite_size.height,
-                              sprite_size.width,
+    lcd.drawSpriteTransparent(get_pos_x()+_sprite_size.offset_x,
+                              get_pos_y()+_sprite_size.offset_y,
+                              _sprite_size.height,
+                              _sprite_size.width,
                               get_frame());
 }
\ No newline at end of file