#include "SpawnEvent.h" #include #include #include #include #include #include #include #include using namespace crepe; void MissileSpawnEventHandler::init() { subscribe([this](const MissileSpawnEvent & ev) -> bool { return this->on_event(ev); }); } std::random_device rd; std::mt19937 gen(rd()); bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { auto missile_sprites = this->get_components_by_name("missile"); auto missile_transforms = this->get_components_by_name("missile"); auto missile_behaviorscripts = this->get_components_by_name("missile"); auto missile_audiosources = this->get_components_by_name("missile"); auto & camera_transform = this->get_components_by_name("camera").front().get(); for (size_t i = 0; i < missile_behaviorscripts.size(); ++i) { auto & script = missile_behaviorscripts[i].get(); if (script.active) continue; script.active = true; missile_audiosources[i * 2].get().play(); auto & transform = missile_transforms[i].get(); transform.position.x = camera_transform.position.x + this->MISSILE_OFFSET; std::uniform_int_distribution<> dist(this->MIN_RANGE, this->MAX_RANGE); transform.position.y = dist(gen); break; } return false; }