aboutsummaryrefslogtreecommitdiff
path: root/game/missile/AlertScript.cpp
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-10 14:47:17 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-10 14:47:17 +0100
commitbcf9bd69f173ecee0104c84e4eadc990f17569c6 (patch)
tree712d36dec5257a5524269dde85345ceaf90504d1 /game/missile/AlertScript.cpp
parent433c840c14782d84b4b95265b3e6f7a1f67ade3b (diff)
parent798237b661e8e49284e78ffb1a16599cf6a46a6d (diff)
Merge remote-tracking branch 'origin/master' into max/game2
Diffstat (limited to 'game/missile/AlertScript.cpp')
-rw-r--r--game/missile/AlertScript.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp
new file mode 100644
index 0000000..24b4af9
--- /dev/null
+++ b/game/missile/AlertScript.cpp
@@ -0,0 +1,38 @@
+#include "AlertScript.h"
+#include "../Config.h"
+
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+
+using namespace crepe;
+
+void AlertScript::fixed_update(crepe::duration_t dt) {
+ const auto & cam = this->get_components_by_name<Transform>("camera").front().get();
+ //missile transform
+ const auto & this_transform = this->get_component<Transform>();
+ auto missile_transforms = this->get_components_by_name<Transform>("missile");
+ const auto & this_collider = this->get_component<CircleCollider>();
+
+ auto alert_sprites = this->get_components_by_name<Sprite>("missile_alert");
+ auto alert_transforms = this->get_components_by_name<Transform>("missile_alert");
+
+ int idx = 0;
+ for (int i = 0; i < missile_transforms.size(); i++) {
+ const auto & missile_transform = missile_transforms[i].get();
+ if (this_transform.game_object_id == missile_transform.game_object_id) {
+ idx = i;
+ break;
+ }
+ }
+
+ auto & alert_transform = alert_transforms[idx].get();
+ alert_transform.position.x = cam.position.x + (VIEWPORT_X / 2 - 100);
+ alert_transform.position.y = this_transform.position.y;
+
+ // check if transform is in camera view
+ if (this_transform.position.x > cam.position.x - (VIEWPORT_X / 2)
+ && this_transform.position.x < cam.position.x + (VIEWPORT_X / 2)) {
+ alert_sprites[idx].get().active = false;
+ }
+}