aboutsummaryrefslogtreecommitdiff
path: root/game/prefab/ZapperPoolScript.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-01-08 11:59:51 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2025-01-08 11:59:51 +0100
commit46c2cbdcbe5e7dbc4d86a5d43b3bd7275b7a1c33 (patch)
tree31491ac6bfd880890861f1583547ff2eba3ba715 /game/prefab/ZapperPoolScript.cpp
parent06d41eb2d58de21a8340ca59952b96cabc8caee6 (diff)
WIP
Diffstat (limited to 'game/prefab/ZapperPoolScript.cpp')
-rw-r--r--game/prefab/ZapperPoolScript.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/game/prefab/ZapperPoolScript.cpp b/game/prefab/ZapperPoolScript.cpp
index 812024b..e201149 100644
--- a/game/prefab/ZapperPoolScript.cpp
+++ b/game/prefab/ZapperPoolScript.cpp
@@ -23,10 +23,11 @@ void ZapperPoolScript::init() {
}
void ZapperPoolScript::fixed_update(crepe::duration_t) {
+ float threshold = camera_transform->position.x - camera_camera->viewport_size.x / 2 - OFFSCREEN_MARGIN;
for (ZapperObject & zapper : this->pool) {
if (!zapper.active) continue;
- if (zapper.transform.position.x < camera_transform->position.x)
+ if (zapper.transform.position.x < threshold)
zapper.set_active(false);
}
@@ -40,11 +41,16 @@ void ZapperPoolScript::spawn_random() {
if (!zapper) return; // pool exhausted
vec2 pos = {
- .x = camera_transform->position.x + camera_camera->viewport_size.x / 2,
+ .x = camera_transform->position.x + camera_camera->viewport_size.x / 2 + OFFSCREEN_MARGIN,
.y = Random::f(0.5, -0.5) * HALLWAY_HEIGHT,
};
- zapper->place(pos, 0, Random::f(400, 200));
+ bool horizontal = Random::b();
+ float rotation = 90.0 * horizontal;
+ float length = horizontal ? Random::f(400, 200) : Random::f(200, 50);
+
+ zapper->place(pos, rotation, length);
+ zapper->set_active(true);
}
OptionalRef<ZapperObject> ZapperPoolScript::get_next_zapper() {