diff options
author | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-10 14:47:17 +0100 |
---|---|---|
committer | Max-001 <maxsmits21@kpnmail.nl> | 2025-01-10 14:47:17 +0100 |
commit | bcf9bd69f173ecee0104c84e4eadc990f17569c6 (patch) | |
tree | 712d36dec5257a5524269dde85345ceaf90504d1 /game/missile/SpawnEvent.cpp | |
parent | 433c840c14782d84b4b95265b3e6f7a1f67ade3b (diff) | |
parent | 798237b661e8e49284e78ffb1a16599cf6a46a6d (diff) |
Merge remote-tracking branch 'origin/master' into max/game2
Diffstat (limited to 'game/missile/SpawnEvent.cpp')
-rw-r--r-- | game/missile/SpawnEvent.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp index 03a9b8c..c7209b7 100644 --- a/game/missile/SpawnEvent.cpp +++ b/game/missile/SpawnEvent.cpp @@ -1,14 +1,15 @@ #include "SpawnEvent.h" +#include "Random.h" #include <crepe/api/Animator.h> #include <crepe/api/AudioSource.h> #include <crepe/api/BehaviorScript.h> #include <crepe/api/Camera.h> +#include <crepe/api/CircleCollider.h> #include <crepe/api/Sprite.h> #include <crepe/api/Transform.h> #include <cstdlib> -#include <random> using namespace crepe; @@ -18,28 +19,29 @@ void MissileSpawnEventHandler::init() { }); } -std::random_device rd; -std::mt19937 gen(rd()); - bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { - auto missile_sprites = this->get_components_by_name<Sprite>("missile"); auto missile_transforms = this->get_components_by_name<Transform>("missile"); + auto alert_sprites = this->get_components_by_name<Sprite>("missile_alert"); + auto alert_transforms = this->get_components_by_name<Transform>("missile_alert"); + auto colliders = this->get_components_by_name<CircleCollider>("missile"); auto missile_behaviorscripts = this->get_components_by_name<BehaviorScript>("missile"); auto missile_audiosources = this->get_components_by_name<AudioSource>("missile"); auto & camera_transform = this->get_components_by_name<Transform>("camera").front().get(); for (size_t i = 0; i < missile_behaviorscripts.size(); ++i) { - auto & script = missile_behaviorscripts[i].get(); + auto & script = missile_behaviorscripts[i * 2].get(); if (script.active) continue; script.active = true; - + colliders[i].get().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); + transform.position.y = Random::i(this->MAX_RANGE, this->MIN_RANGE); + auto & alert_transform = alert_transforms[i].get(); + auto & alert_sprite = alert_sprites[i].get(); + alert_sprite.active = true; break; } |