Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Revision:
30:ec915d24d3e9
Parent:
29:6b8411bb040a
Child:
32:fe6359ef9916
diff -r 6b8411bb040a -r ec915d24d3e9 Entity/Player/Player.cpp
--- a/Entity/Player/Player.cpp	Sat May 04 15:39:20 2019 +0000
+++ b/Entity/Player/Player.cpp	Sun May 05 18:04:43 2019 +0000
@@ -58,6 +58,14 @@
 // Functions
 void Player::move(float mapped_x, float mapped_y, int * map, bool * doorways)
 {
+    move_player(mapped_x, mapped_y, map, doorways);
+    move_bullets();
+    increment_frames(mapped_x, mapped_y);
+    invulnerability_counter++;
+}
+
+void Player::move_player(float mapped_x, float mapped_y, int * map, bool * doorways)
+{
     if(!entity_to_map_collision_test(position.x + velocity*mapped_x, position.y, map, doorways)) {
         position.x += velocity*mapped_x;
     }
@@ -65,6 +73,19 @@
         position.y -= velocity*mapped_y;
     }
     moving = false;
+}
+
+void Player::move_bullets()
+{
+    for (int i = 0; i < bullets_max; i++) {
+        if (valid_bullets[i]) {
+            bullets_array[i]->move(get_bullet_speed(), 0, 0, (bool *) 0);
+        }
+    }
+}
+
+void Player::increment_frames(float mapped_x, float mapped_y)
+{
     if (abs(mapped_x) + abs(mapped_y) > 0.1f) {
         moving = true;
         if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)) {
@@ -85,7 +106,6 @@
         frame.count = 0;
     }
     frame.number = (frame.count/8) % frame.max;
-    invulnerability_counter++;
 }
 
 void Player::take_damage(int damage)
@@ -101,6 +121,48 @@
         hp = 5;
     }
 }
+
+bool Player::update_bullets(int * map, bool * doorways)
+{
+    bool result = false;
+    for (int i = 0; i < bullets_max; i++) {
+        if((valid_bullets[i]) && (bullets_array[i]->out_of_bounds_check(map, doorways))) {
+            valid_bullets[i] = false;
+            delete bullets_array[i];
+            result = true;
+        }
+    }
+    return result;
+}
+
+void Player::draw(N5110 &lcd)
+{
+    draw_player(lcd);
+    draw_bullets(lcd);
+}
+
+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,
+                              get_frame());
+}
+
+void Player::draw_bullets(N5110 &lcd)
+{
+    for (int i = 0; i < bullets_max; i++) {
+        if (valid_bullets[i]) {
+            lcd.drawSpriteTransparent(bullets_array[i]->get_pos_x()-bullets_array[i]->get_offset_x(),
+                                      bullets_array[i]->get_pos_y()-bullets_array[i]->get_offset_y(),
+                                      bullets_array[i]->get_sprite_height(),
+                                      bullets_array[i]->get_sprite_width(),
+                                      bullets_array[i]->get_frame());
+        }
+    }
+}
+
 void Player::delete_bullets()
 {
     for (int i = 0; i < bullets_max; i++) {