aboutsummaryrefslogtreecommitdiff
path: root/game/missile/SpawnEvent.cpp
diff options
context:
space:
mode:
authorheavydemon21 <48092678+heavydemon21@users.noreply.github.com>2025-01-10 14:44:59 +0100
committerGitHub <noreply@github.com>2025-01-10 14:44:59 +0100
commit798237b661e8e49284e78ffb1a16599cf6a46a6d (patch)
tree8f4881cf4abc58774625383620cf82fa55b9d1f0 /game/missile/SpawnEvent.cpp
parentbb2db93bfb8dd7e080d2708548eae660e6b33913 (diff)
parentd1cebcca2018ed4ef47ad125e45aafd018a2ab2e (diff)
Merge pull request #125 from lonkaars/niels/game
missile alerts
Diffstat (limited to 'game/missile/SpawnEvent.cpp')
-rw-r--r--game/missile/SpawnEvent.cpp20
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;
}