// // burstshot_pattern.cxx // danmaku // // Created by Sam Jaffe on 5/26/19. // Copyright © 2019 Sam Jaffe. All rights reserved. // #include #include #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; struct burstshot : public danmaku::bullet_pattern { static std::shared_ptr create(danmaku::actor *, Json::Value const &); burstshot(danmaku::actor *, float shot_interval, std::vector shots); void update(float delta) override; danmaku::actor * actor; danmaku::bullet_timer shot_timer; float last_fired{std::numeric_limits::lowest()}; std::vector shots; }; std::vector 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 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 shots) : actor(actor), shot_timer{shot_interval}, shots(shots) {} std::shared_ptr burstshot::create(danmaku::actor * actor, Json::Value const & json) { return std::make_shared( 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); }