| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // burstshot_pattern.cxx
- // danmaku
- //
- // Created by Sam Jaffe on 5/26/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #include <json/json.h>
- #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 &);
- 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; }
- if (clockwise) { covered = -covered; }
- 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 * actor,
- Json::Value const & json) {
- 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()));
- }
- void burstshot::update(float delta) {}
- namespace danmaku {
- BIND_BULLET_PATTERN("burstshot", &burstshot::create);
- }
|