diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2025-01-08 16:14:25 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2025-01-08 16:14:25 +0100 |
commit | f1f6f08bf15e7ef1520810524a5e50a126629432 (patch) | |
tree | 239f1d19fb890a7badc2f7887c460605770614e1 /game/prefab/ZapperPoolScript.cpp | |
parent | 31b068a3d2a275656ec310552f1ab27034aa184d (diff) | |
parent | 94e2988cc8c42e83a4b7b858c48458f997130963 (diff) |
Merge remote-tracking branch 'origin/loek/game' into niels/game
Diffstat (limited to 'game/prefab/ZapperPoolScript.cpp')
-rw-r--r-- | game/prefab/ZapperPoolScript.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/game/prefab/ZapperPoolScript.cpp b/game/prefab/ZapperPoolScript.cpp index b9b2a76..b832ddd 100644 --- a/game/prefab/ZapperPoolScript.cpp +++ b/game/prefab/ZapperPoolScript.cpp @@ -23,36 +23,38 @@ void ZapperPoolScript::init() { } void ZapperPoolScript::fixed_update(crepe::duration_t) { - float threshold = camera_transform->position.x - camera_camera->viewport_size.x / 2 - OFFSCREEN_MARGIN; + 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 < threshold) - zapper.set_active(false); + if (zapper.transform.position.x < threshold) zapper.set_active(false); } } void ZapperPoolScript::spawn_random() { OptionalRef<ZapperObject> zapper = this->get_next_zapper(); if (!zapper) return; // pool exhausted - - vec2 pos = { - .x = camera_transform->position.x + camera_camera->viewport_size.x / 2 + OFFSCREEN_MARGIN, - .y = Random::f(0.5, -0.5) * HALLWAY_HEIGHT, - }; bool horizontal = Random::b(); + vec2 pos; float rotation, length; + pos.x + = camera_transform->position.x + camera_camera->viewport_size.x / 2 + OFFSCREEN_MARGIN; if (horizontal) { rotation = 90; length = Random::f(400, 200); + pos.y = Random::f(0.5, -0.5) * HALLWAY_HEIGHT; + // align zapper to right edge of camera + pos.x -= MAX_LENGTH - (length / 2); } else { rotation = 0; - length = Random::f(200, 50); - if (abs(pos.y) + length / 2 > HALLWAY_HEIGHT / 2) { - // TODO: fix offset - } + length = Random::f(200, 75); + // ensure zapper doesn't crash into ceiling or floor + pos.y = Random::f(0.5, -0.5) * (HALLWAY_HEIGHT - length); + // align zapper to right edge of camera + pos.x -= MAX_LENGTH; } zapper->place(pos, rotation, length); @@ -66,4 +68,3 @@ OptionalRef<ZapperObject> ZapperPoolScript::get_next_zapper() { } return {}; } - |