diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-10 14:50:50 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-10 14:50:50 +0100 |
commit | 7aa07561a52016007ff852acefa4db68260f0f1e (patch) | |
tree | ac438e906e581ee68f9d065dea90a2cbb8436d15 /game/missile/SpawnEvent.cpp | |
parent | d7c8cc30e1d37526cf142f950038500b96760514 (diff) | |
parent | 0f8bf257d86b5532f3d6f559e5368668c255af7c (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/game-improvements
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; } |