A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.

Dependencies:   mbed MotionSensor

Revision:
56:ef9521b7ed78
Parent:
51:4d0cd75e7ed3
Child:
57:1c12361b6e3d
--- a/Entity/Bosses/Skull/Skull.cpp	Thu May 09 08:18:36 2019 +0000
+++ b/Entity/Bosses/Skull/Skull.cpp	Thu May 09 08:42:52 2019 +0000
@@ -36,39 +36,10 @@
 
 void Skull::move(float player_x, float player_y, char * map, bool * doorways)
 {
-    // Approaching Movement
-    if (_dash_counter < DASH_DELAY) {
-        _dash = false;
-        std::complex<double> pos_diff(player_x - position.x, player_y - position.y);     // defining difference in position as a vector
-        position.x += velocity * pos_diff.real() / std::abs(pos_diff);
-        position.y += velocity * pos_diff.imag() / std::abs(pos_diff);
-        
-        // Setting Face
-        if (abs(pos_diff.real()) > abs(pos_diff.imag())) {
-            if (pos_diff.real() > 0) {
-                face = 1;
-            } else {
-                face = 3;
-            }
-        } else {
-            if (pos_diff.imag() > 0) {
-                face = 2;
-            } else {
-                face = 0;
-            }
-        }
-    } else if (_dash_counter < DASH_DELAY + 28){
-        _dash = true;
-        velocity = skull_velocity_pattern[(int)((_dash_counter - DASH_DELAY)/4)];
-        if (face == 0){
-            position.y -= velocity;
-        } else if (face == 1){
-            position.x += velocity;
-        } else if (face == 2){
-            position.y += velocity;
-        } else if (face == 3){
-            position.x -= velocity;
-        }
+    if (_dash_counter < DASH_DELAY) { // Approaching Movement
+        approaching_movement(player_x, player_y);
+    } else if (_dash_counter < DASH_DELAY + 28){ // Dashing movement; const 28 = 4(velocity_index_increment_delay) * 7 (length of the velocity_pattern)
+        dash_movement();
     } else {
         _dash_counter = 0;
         velocity = 0.2;
@@ -80,6 +51,43 @@
     increment_frames();
 }
 
+void Skull::approaching_movement(float player_x, float player_y)
+{
+    _dash = false;
+    std::complex<double> pos_diff(player_x - position.x, player_y - position.y);     // defining difference in position as a vector for simplicity, similar to Headless
+    position.x += velocity * pos_diff.real() / std::abs(pos_diff);
+    position.y += velocity * pos_diff.imag() / std::abs(pos_diff);
+    // Setting Face
+    if (abs(pos_diff.real()) > abs(pos_diff.imag())) {
+        if (pos_diff.real() > 0) {
+            face = 1;
+        } else {
+            face = 3;
+        }
+    } else {
+        if (pos_diff.imag() > 0) {
+            face = 2;
+        } else {
+            face = 0;
+        }
+    }
+}
+
+void Skull::dash_movement() // Changes velocity over time using the velocity pattern
+{
+    _dash = true;
+    velocity = skull_velocity_pattern[(int)((_dash_counter - DASH_DELAY)/4)];
+    if (face == 0){
+        position.y -= velocity;
+    } else if (face == 1){
+        position.x += velocity;
+    } else if (face == 2){
+        position.y += velocity;
+    } else if (face == 3){
+        position.x -= velocity;
+    }
+}
+
 void Skull::draw(N5110 &lcd)
 {
     update_offsets();
@@ -100,7 +108,7 @@
     hp -= 1;
 }
 
-// Private Functions
+// Methods
 
 void Skull::increment_frames()
 {
@@ -112,7 +120,7 @@
     frame.number = (frame.count/20) % frame.max;
 }
 
-void Skull::update_offsets()
+void Skull::update_offsets()    // Animates the shadows by offsetting the skull from the shadow periodically
 {
     if (frame.number == 0) {
         sprite_size.offset_y = -14;