Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Files at this revision

API Documentation at this revision

Comitter:
el17sm
Date:
Wed Apr 24 03:09:00 2019 +0000
Parent:
13:d04a6caba40d
Child:
15:44d5cc33d389
Commit message:
Death of Entities and Bullets done, Laser problem (fire rate);

Changed in this revision

Entity/Bullets/Bullets.cpp Show annotated file Show diff for this revision Revisions of this file
Entity/Bullets/Bullets.h Show annotated file Show diff for this revision Revisions of this file
Entity/Entity.cpp Show annotated file Show diff for this revision Revisions of this file
Entity/Entity.h Show annotated file Show diff for this revision Revisions of this file
Entity/Player/Player.cpp Show annotated file Show diff for this revision Revisions of this file
Entity/Player/Player.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Entity/Bullets/Bullets.cpp	Wed Apr 24 02:33:33 2019 +0000
+++ b/Entity/Bullets/Bullets.cpp	Wed Apr 24 03:09:00 2019 +0000
@@ -16,10 +16,30 @@
 }
 
 void Bullets::move(float speed, float unused){
-    position.x += (direction < 2)*speed;
-    position.y += (direction < 2)*speed;
+    if (direction == 0){
+        position.y -= speed;
+    }
+    else if (direction == 1){
+        position.x += speed;
+    }
+    else if (direction == 2){
+        position.y += speed;
+    }
+    else if (direction == 3){
+        position.x -= speed;
+    }
 }
 
 int * Bullets::get_frame(){
     return (int *) bullets_sprite;
+}
+
+bool Bullets::out_of_bounds_check(){
+    if (matrix_collision_test(position.x, position.y, 0)){
+        return true;
+    }
+    else if ((!(0 < position.x < 84)) || (!(0 < position.y < 48))){
+        return true;
+    }
+    return false;
 }
\ No newline at end of file
--- a/Entity/Bullets/Bullets.h	Wed Apr 24 02:33:33 2019 +0000
+++ b/Entity/Bullets/Bullets.h	Wed Apr 24 03:09:00 2019 +0000
@@ -11,6 +11,7 @@
     // Functions
     virtual void move(float, float);
     virtual int * get_frame();
+    bool out_of_bounds_check();
     
     private:
     // Member Variable
--- a/Entity/Entity.cpp	Wed Apr 24 02:33:33 2019 +0000
+++ b/Entity/Entity.cpp	Wed Apr 24 03:09:00 2019 +0000
@@ -29,6 +29,13 @@
     hp -= damage;
 }
 
+bool Entity::death_check(){
+    if (hp <= 0){
+        return true;
+    }
+    return false;
+}
+
 // mutators
 
 // accessors
--- a/Entity/Entity.h	Wed Apr 24 02:33:33 2019 +0000
+++ b/Entity/Entity.h	Wed Apr 24 03:09:00 2019 +0000
@@ -47,6 +47,7 @@
         void undo_move_y(bool);
         void update_prev_pos();
         void take_damage(int);
+        bool death_check();
         
         // Mutator
         
--- a/Entity/Player/Player.cpp	Wed Apr 24 02:33:33 2019 +0000
+++ b/Entity/Player/Player.cpp	Wed Apr 24 03:09:00 2019 +0000
@@ -18,10 +18,11 @@
     frame.number = 0;
     frame.max = 4;
     for (int i = 0; i < bullets_max; i++){valid_bullets[i] = false;}
+    fire_rate_bullets = 0;
 }
 
 // Accessors
-int get_attack(){return 1;};
+int Player::get_attack(){return 1;};
 
 // Functions
 void Player::move(float mapped_x, float mapped_y){
@@ -65,6 +66,7 @@
 }
 
 void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X){
+    fire_rate_bullets++;
     if (button_Y){
         face = 0;
     }
@@ -77,11 +79,14 @@
     else if (button_X){
         face = 3;
     }
-    for (int i = 0; i < bullets_max; i++){
-        if (!valid_bullets[i]){
-            bullets_array[i] = new Bullets(position.x, position.y, face);
-            valid_bullets[i] = true;
-            break;
+    if (button_Y || button_B || button_A || button_X){
+        for (int i = 0; i < bullets_max; i++){
+            if (!valid_bullets[i] || fire_rate_bullets > 10){
+                bullets_array[i] = new Bullets(position.x, position.y, face);
+                valid_bullets[i] = true;
+                fire_rate_bullets = 0;
+                break;
+            }
         }
     }
 }
--- a/Entity/Player/Player.h	Wed Apr 24 02:33:33 2019 +0000
+++ b/Entity/Player/Player.h	Wed Apr 24 03:09:00 2019 +0000
@@ -21,6 +21,7 @@
     // variables
     Bullets *bullets_array[bullets_max];
     bool valid_bullets[bullets_max];
+    int fire_rate_bullets;
 };
 
 const float player_speed = 1.2;
--- a/main.cpp	Wed Apr 24 02:33:33 2019 +0000
+++ b/main.cpp	Wed Apr 24 03:09:00 2019 +0000
@@ -114,6 +114,10 @@
                                 player.bullets_array[i]->~Bullets;
                             }
                         }
+                        if (player.bullets_array[i]->out_of_bounds_check()){
+                            player.valid_bullets[i] = false;
+                            player.bullets_array[i]->~Bullets;
+                        }
                     };
                 }
             };
@@ -123,6 +127,14 @@
             player.move(mapped_coord.x, mapped_coord.y);
             player.buttons(gamepad.check_event(Gamepad::A_PRESSED), gamepad.check_event(Gamepad::B_PRESSED), gamepad.check_event(Gamepad::Y_PRESSED), gamepad.check_event(Gamepad::X_PRESSED));
             
+            // Enemy Death
+            for (int i = 0; i < no_of_enemies; i++){
+                if(enemies[i]->death_check()){
+                    valid_enemies[i] = false;
+                    enemies[i]->~Entity;
+                }
+            }
+            
             // Enemy Movement
             for (int i = 0; i < no_of_enemies; i++){
                 if (valid_enemies[i]){
@@ -130,6 +142,11 @@
                     enemies[i]->move(pos_x, pos_y);
                 }
             };
+            for (int i = 0; i < bullets_max; i++){
+                if (player.valid_bullets[i]){
+                    player.bullets_array[i]->move(1, 0);
+                }
+            };
             for (int i = 0; i < no_of_enemies; i++){
                 if (valid_enemies[i]){
                     enemies[i]->undo_move_x(entity_move_check_x(enemies[i], enemies, no_of_enemies, i, valid_enemies));