Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Revision:
36:27aa597db3d2
Parent:
35:577c65bf914e
Child:
40:71f947254fda
--- a/People/People.cpp	Fri May 15 14:19:54 2020 +0000
+++ b/People/People.cpp	Fri May 15 16:31:25 2020 +0000
@@ -17,6 +17,7 @@
 }
 
 void People::init(Gamepad &pad, int position_x_start) {
+    // Define variables
     sprite_x_length = 4;
     sprite_y_length = 5;
     position_x_ = position_x_start;
@@ -33,22 +34,28 @@
     off_screen_x_y_checker(map_length_, position_x_map_);
     
     // move alien to top of screen if collision with alien
-    if(alien_collision_flag){
-        //people moves on its own but at half speed of spaceship 
-        if (people_move_counter_%2 == 0) {
-            if (random_move_counter_ == 0){
-                //move alien to top of screen
-                random_direction_ = 6;   
-                random_move_counter_ = 43;
-            }
-            move_direction();
-            off_screen_x_y_checker(map_length_, position_x_map_);
-            random_move_counter_ --;     
-        }
-    }
+    collision_with_alien();
+    
     people_move_counter_++;
 } 
 
+void People::collision_with_alien(){
+if(alien_collision_flag){
+    //people moves on its own but at half speed of spaceship 
+    if (people_move_counter_%2 == 0) {
+        if (random_move_counter_ == 0){
+            //move alien to top of screen
+            random_direction_ = 6;   
+            random_move_counter_ = 43;
+        }
+        
+    //move poeple
+    move_direction();
+    random_move_counter_ --;     
+    }
+}    
+}
+
 void People::off_screen_x_y_checker(int map_length_, int position_x_map_){
     // loops the people round if it reaches the end of the map 
     if(position_x_ <= (84 - map_length_)){