blob: 24b4af9f409977059e66d8a40d73954c601c6761 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}
}
|