瀏覽代碼

Start writing initialization code for burstshot systems.

Sam Jaffe 6 年之前
父節點
當前提交
a9fc0609d5
共有 3 個文件被更改,包括 53 次插入4 次删除
  1. 2 0
      danmaku.xcodeproj/project.pbxproj
  2. 6 0
      include/danmaku/bullet_pattern.hpp
  3. 45 4
      src/pattern/burstshot_pattern.cxx

+ 2 - 0
danmaku.xcodeproj/project.pbxproj

@@ -25,6 +25,7 @@
 		CD49F76D229B0A8000EB8926 /* bullet_pattern.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F76C229B0A8000EB8926 /* bullet_pattern.cxx */; };
 		CD49F778229B0FCD00EB8926 /* actor.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F777229B0FCD00EB8926 /* actor.cxx */; };
 		CD49F783229B194C00EB8926 /* burstshot_pattern.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD49F782229B194C00EB8926 /* burstshot_pattern.cxx */; };
+		CD49F784229B25DE00EB8926 /* libmath.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD7E883022960DBC00D877FE /* libmath.dylib */; };
 		CD7E87A52295FCED00D877FE /* danmakuUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD7E87A42295FCED00D877FE /* danmakuUITests.m */; };
 /* End PBXBuildFile section */
 
@@ -108,6 +109,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CD49F784229B25DE00EB8926 /* libmath.dylib in Frameworks */,
 				CD1C833F2298A9E000825C4E /* libengine.dylib in Frameworks */,
 				CD1C83402298A9E000825C4E /* libgameutils.dylib in Frameworks */,
 				CD1C83412298A9E000825C4E /* libgraphics.dylib in Frameworks */,

+ 6 - 0
include/danmaku/bullet_pattern.hpp

@@ -17,6 +17,12 @@ namespace objects { namespace prototype {
 
 namespace danmaku {
   class actor;
+  
+  struct bullet_timer {
+    float const interval;
+    float remaining{0.f};
+  };
+  
   struct bullet_pattern {
     virtual ~bullet_pattern() = default;
     virtual void update(float delta) = 0;

+ 45 - 4
src/pattern/burstshot_pattern.cxx

@@ -6,19 +6,60 @@
 //  Copyright © 2019 Sam Jaffe. All rights reserved.
 //
 
+#include <vector>
+
 #include "danmaku/bullet_pattern.hpp"
+#include "game/math/angle.hpp"
+#include "game/math/common.hpp"
+#include "game/math/math_fwd.hpp"
 #include "resource_factory/prototype_factory.hpp"
+#include "vector/vector.hpp"
+
+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 &);
   
-  void update(float delta) override {}
+  burstshot(danmaku::actor *, float shot_interval, std::vector<shot> shots);
+  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;
 };
+  
+std::vector<shot> shot_vector(std::size_t count, float facing, float covered,
+                              float speed, bool clockwise) {
+  if (covered == 360.f) { ++count; }
+  std::vector<shot> out(count);
+  float start = facing + (.5f * covered);
+  float end = start - covered;
+  if (clockwise != (end < start)) { std::swap(start, end); }
+  
+  float const delta = (end - start) / count;
+  float current = start;
+  for (std::size_t i = 0; i < count; ++i, current += delta) {
+    out[i].first = math::rotate({{speed, 0}}, math::degree(current));
+    out[i].second = current + 90;
+  }
+  return out;
+}
+
+burstshot::burstshot(danmaku::actor * actor, float shot_interval,
+                     std::vector<shot> shots)
+    : actor(actor), shot_timer{shot_interval}, shots(shots) {}
 
-std::shared_ptr<burstshot> burstshot::create(danmaku::actor*,
-                                             Json::Value const &) {
-  return std::make_shared<burstshot>();
+std::shared_ptr<burstshot> burstshot::create(danmaku::actor* actor,
+                                             Json::Value const & json) {
+  return std::make_shared<burstshot>(actor, 0.f, shot_vector(0, 0.f, 0.f, 0.f, false));
+}
+
+void burstshot::update(float delta) {
+  
 }
 
 namespace danmaku {