瀏覽代碼

Start defining bullet code.
Add more features to burstshot

Sam Jaffe 6 年之前
父節點
當前提交
faed41be64

+ 2 - 2
Resources/scripts/entity/drake.json

@@ -16,12 +16,12 @@
   },
   "attack":[
     {
-      "id":"burstShot",
+      "id":"burstshot",
       "timeBetweenBullets":0.1,
       "bulletsPerWave":15,
       "burstAngle":360,
       "bulletSpeed":900,
-      "bulletType":{
+      "prototype":{
         "damage":2,
         "size":10.0,
         "material":{

+ 9 - 0
include/danmaku/actor.hpp

@@ -7,3 +7,12 @@
 //
 
 #pragma once
+
+#include "game/engine/engine_fwd.hpp"
+
+namespace danmaku {
+  struct actor {
+    virtual ~actor() = default;
+    virtual void update(engine::entity & ent) = 0;
+  };
+}

+ 13 - 0
include/danmaku/bullet.hpp

@@ -7,3 +7,16 @@
 //
 
 #pragma once
+
+#include "actor.hpp"
+
+namespace danmaku {
+  class bullet {
+  public:
+    bullet(int damage);
+    void update(engine::entity & ent);
+
+  private:
+    int damage_;
+  };
+}

+ 5 - 1
include/danmaku/bullet_pattern.hpp

@@ -15,6 +15,10 @@ namespace objects { namespace prototype {
   template <typename, typename...> class factory;
 }}
 
+namespace graphics {
+  class manager;
+}
+
 namespace danmaku {
   class actor;
 
@@ -30,7 +34,7 @@ namespace danmaku {
 
   using bullet_pattern_factory =
       objects::prototype::factory<std::shared_ptr<bullet_pattern>, actor *,
-                                  Json::Value const &>;
+                                  Json::Value const &, graphics::manager &>;
 }
 
 #define BIND_BULLET_PATTERN(name, function)                                    \

+ 6 - 0
src/entity/bullet.cxx

@@ -7,3 +7,9 @@
 //
 
 #include "danmaku/bullet.hpp"
+
+using namespace danmaku;
+
+bullet::bullet(int damage) : damage_(damage) {}
+
+void bullet::update(engine::entity & ent) {}

+ 17 - 7
src/pattern/burstshot_pattern.cxx

@@ -9,7 +9,10 @@
 #include <json/json.h>
 #include <vector>
 
+#include "danmaku/bullet.hpp"
 #include "danmaku/bullet_pattern.hpp"
+#include "game/engine/serial.hpp"
+#include "game/graphics/object.hpp"
 #include "game/math/angle.hpp"
 #include "game/math/common.hpp"
 #include "game/math/math_fwd.hpp"
@@ -21,16 +24,19 @@ using namespace danmaku;
 using shot = std::pair<math::vec2, float>;
 
 struct burstshot : public danmaku::bullet_pattern {
-  static std::shared_ptr<burstshot> create(danmaku::actor *,
-                                           Json::Value const &);
+  static std::shared_ptr<burstshot>
+  create(danmaku::actor *, Json::Value const &, graphics::manager &);
 
-  burstshot(danmaku::actor *, float shot_interval, std::vector<shot> shots);
+  burstshot(danmaku::actor *, float shot_interval, std::vector<shot> shots,
+            bullet bullet, graphics::object object);
   void update(float delta) override;
 
   danmaku::actor * actor;
   danmaku::bullet_timer shot_timer;
   float last_fired{std::numeric_limits<float>::lowest()};
   std::vector<shot> shots;
+  bullet bullet_proto;
+  graphics::object object_proto;
 };
 
 std::vector<shot> shot_vector(std::size_t count, float facing, float covered,
@@ -54,16 +60,20 @@ 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)
-    : actor(actor), shot_timer{shot_interval}, shots(shots) {}
+                     std::vector<shot> shots, bullet blt, graphics::object obj)
+    : actor(actor), shot_timer{shot_interval}, shots(shots), bullet_proto(blt),
+      object_proto(obj) {}
 
 std::shared_ptr<burstshot> burstshot::create(danmaku::actor * actor,
-                                             Json::Value const & json) {
+                                             Json::Value const & json,
+                                             graphics::manager & manager) {
   return std::make_shared<burstshot>(
       actor, json["timeBetweenBullets"].asFloat(),
       shot_vector(json["bulletsPerWave"].asUInt(),
                   json["centerAngle"].asFloat(), json["burstAngle"].asFloat(),
-                  json["bulletSpeed"].asFloat(), json["clockwise"].asBool()));
+                  json["bulletSpeed"].asFloat(), json["clockwise"].asBool()),
+      json["prototype"]["damage"].asInt(),
+      engine::to_object(json["prototype"], manager));
 }
 
 void burstshot::update(float delta) {}