Browse Source

Make bullet collidable.

Sam Jaffe 6 years ago
parent
commit
e37b39ce8c
3 changed files with 5 additions and 6 deletions
  1. 1 4
      include/danmaku/bullet.hpp
  2. 1 1
      src/entity/bullet.cxx
  3. 3 1
      src/level.cxx

+ 1 - 4
include/danmaku/bullet.hpp

@@ -11,19 +11,16 @@
 #include "actor.hpp"
 
 namespace danmaku {
-  class bullet {
+  class bullet : public engine::collidable {
   public:
     bullet(int damage, math::vec2 const & vel, graphics::object const & obj);
     void update(float delta);
 
-    graphics::object const & render_info() const { return render_info_; }
-
     void set_position(math::vec2 const & ll, math::radian facing);
     void set_velocity(math::vec2 const & v) { velocity_ = v; }
 
   private:
     int damage_;
     math::vec2 velocity_;
-    graphics::object render_info_;
   };
 }

+ 1 - 1
src/entity/bullet.cxx

@@ -14,7 +14,7 @@
 using namespace danmaku;
 
 bullet::bullet(int damage, math::vec2 const & vel, graphics::object const & obj)
-    : damage_(damage), velocity_(vel), render_info_(obj) {}
+    : engine::collidable(obj), damage_(damage), velocity_(vel) {}
 
 void bullet::update(float delta) {}
 

+ 3 - 1
src/level.cxx

@@ -48,7 +48,8 @@ level::~level() {}
 
 void level::add_bullet(bullet b) {
   bullets_.emplace_back(std::make_unique<bullet>(std::move(b)));
-  // TODO: Add to collision boxes...
+  // TODO: Add to correct collision boxes...
+  collidables[0].emplace_back(bullets_.back().get());
 }
 
 void level::update(float delta) {
@@ -60,6 +61,7 @@ void level::update(float delta) {
     b->update(delta);
   }
   check_collisions();
+  // TODO: This is a bad hack until I can properly disassociate collision info
   for (auto & b : bullets_) {
     if (math::intersects(player_->render_info().points,
                          b->render_info().points)) {