Browse Source

Start writing ctor.

Sam Jaffe 6 years ago
parent
commit
bf7697c653
4 changed files with 36 additions and 3 deletions
  1. 2 1
      include/danmaku/actor.hpp
  2. 17 1
      include/danmaku/enemy.hpp
  3. 14 0
      src/entity/enemy.cxx
  4. 3 1
      src/level.cxx

+ 2 - 1
include/danmaku/actor.hpp

@@ -21,6 +21,7 @@ namespace graphics {
 namespace danmaku {
   class level;
   struct actor : public engine::entity {
+    using engine::entity::entity;
     virtual ~actor() = default;
     virtual void update(float delta) = 0;
     virtual void level(class level *) = 0;
@@ -29,7 +30,7 @@ namespace danmaku {
 
   using actor_factory =
       objects::prototype::factory<std::unique_ptr<actor>, Json::Value const &,
-                                  graphics::manager const &>;
+                                  graphics::object const &>;
 }
 
 #define BIND_ACTOR(name, function)                                             \

+ 17 - 1
include/danmaku/enemy.hpp

@@ -11,5 +11,21 @@
 #include "actor.hpp"
 
 namespace danmaku {
-  class enemy : public actor {};
+  struct bullet_patern;
+}
+
+namespace danmaku {
+  struct points_map {
+    int on_damage;
+    int on_kill;
+  };
+
+  class enemy : public actor {
+  public:
+    enemy(Json::Value const & json, graphics::object const & obj);
+
+  private:
+    points_map points_;
+    std::vector<std::shared_ptr<bullet_patern>> attack_;
+  };
 }

+ 14 - 0
src/entity/enemy.cxx

@@ -7,3 +7,17 @@
 //
 
 #include "danmaku/enemy.hpp"
+
+#include <json/json.h>
+
+#include "danmaku/bullet_pattern.hpp"
+#include "resource_factory/prototype_factory.hpp"
+
+using namespace danmaku;
+
+points_map to_points_map(Json::Value const & json) {
+  return {json["damage"].asInt(), json["kill"].asInt()};
+}
+
+enemy::enemy(Json::Value const & json, graphics::object const & obj)
+    : actor(json, obj), points_(to_points_map(json["points"])), attack_() {}

+ 3 - 1
src/level.cxx

@@ -13,6 +13,7 @@
 #include "danmaku/actor.hpp"
 #include "danmaku/bullet.hpp"
 #include "danmaku/player.hpp"
+#include "game/engine/serial.hpp"
 #include "game/graphics/renderer.hpp"
 #include "game/math/common.hpp"
 #include "resource_factory/prototype_factory.hpp"
@@ -24,7 +25,8 @@ get_wave(Json::Value const & json, graphics::manager const & manager) {
   std::vector<std::unique_ptr<actor>> out;
   for (int i = 0; i < json.size(); ++i) {
     auto & factory = actor_factory::instance();
-    out.emplace_back(factory.get(json["type"].asString(), json, manager));
+    out.emplace_back(factory.get(json["type"].asString(), json,
+                                 engine::to_object(json, manager)));
   }
   return out;
 }