Forráskód Böngészése

Add bullet to level stub.

Sam Jaffe 6 éve
szülő
commit
d4d0f9d7a5

+ 2 - 0
include/danmaku/actor.hpp

@@ -11,8 +11,10 @@
 #include "game/engine/engine_fwd.hpp"
 
 namespace danmaku {
+  class level;
   struct actor {
     virtual ~actor() = default;
     virtual void update(engine::entity & ent) = 0;
+    virtual std::shared_ptr<class level> level() const = 0;
   };
 }

+ 12 - 0
include/danmaku/level.hpp

@@ -7,3 +7,15 @@
 //
 
 #pragma once
+
+#include "game/engine/scene.hpp"
+
+namespace danmaku {
+  class bullet;
+  class level : public engine::scene {
+  public:
+    void add_bullet(bullet const &, engine::entity const &);
+
+  private:
+  };
+}

+ 4 - 0
src/level.cxx

@@ -7,3 +7,7 @@
 //
 
 #include "danmaku/level.hpp"
+
+using namespace danmaku;
+
+void level::add_bullet(bullet const &, engine::entity const &) {}

+ 18 - 8
src/pattern/burstshot_pattern.cxx

@@ -11,8 +11,8 @@
 
 #include "danmaku/bullet.hpp"
 #include "danmaku/bullet_pattern.hpp"
-#include "game/engine/serial.hpp"
-#include "game/graphics/object.hpp"
+#include "danmaku/level.hpp"
+#include "game/engine/entity.hpp"
 #include "game/math/angle.hpp"
 #include "game/math/common.hpp"
 #include "game/math/math_fwd.hpp"
@@ -28,15 +28,16 @@ struct burstshot : public danmaku::bullet_pattern {
   create(danmaku::actor *, Json::Value const &, graphics::manager &);
 
   burstshot(danmaku::actor *, float shot_interval, std::vector<shot> shots,
-            bullet bullet, graphics::object object);
+            bullet bullet, engine::entity ent);
   void update(float delta) override;
 
   danmaku::actor * actor;
   danmaku::bullet_timer shot_timer;
   float last_fired{std::numeric_limits<float>::lowest()};
+  std::size_t idx{0};
   std::vector<shot> shots;
   bullet bullet_proto;
-  graphics::object object_proto;
+  engine::entity entity_proto;
 };
 
 std::vector<shot> shot_vector(std::size_t count, float facing, float covered,
@@ -60,9 +61,9 @@ std::vector<shot> shot_vector(std::size_t count, float facing, float covered,
 }
 
 burstshot::burstshot(danmaku::actor * actor, float shot_interval,
-                     std::vector<shot> shots, bullet blt, graphics::object obj)
+                     std::vector<shot> shots, bullet blt, engine::entity ent)
     : actor(actor), shot_timer{shot_interval}, shots(shots), bullet_proto(blt),
-      object_proto(obj) {}
+      entity_proto(ent) {}
 
 std::shared_ptr<burstshot> burstshot::create(danmaku::actor * actor,
                                              Json::Value const & json,
@@ -73,10 +74,19 @@ std::shared_ptr<burstshot> burstshot::create(danmaku::actor * actor,
                   json["centerAngle"].asFloat(), json["burstAngle"].asFloat(),
                   json["bulletSpeed"].asFloat(), json["clockwise"].asBool()),
       json["prototype"]["damage"].asInt(),
-      engine::to_object(json["prototype"], manager));
+      engine::entity(json["prototype"], manager));
 }
 
-void burstshot::update(float delta) {}
+void burstshot::update(float delta) {
+  if ((shot_timer.remaining -= delta) <= 0.f) {
+    shot_timer.remaining = shot_timer.interval;
+    std::size_t shots_fired = std::size_t(delta / shots.size());
+    while (shots_fired-- > 0) {
+      actor->level()->add_bullet(bullet_proto, entity_proto);
+      if (idx == shots.size()) { idx = 0; }
+    }
+  }
+}
 
 namespace danmaku {
   BIND_BULLET_PATTERN("burstshot", &burstshot::create);