diff options
-rw-r--r-- | game/prefab/ZapperObject.cpp | 3 | ||||
-rw-r--r-- | game/prefab/ZapperPoolScript.cpp | 23 | ||||
-rw-r--r-- | game/prefab/ZapperPoolScript.h | 3 |
3 files changed, 12 insertions, 17 deletions
diff --git a/game/prefab/ZapperObject.cpp b/game/prefab/ZapperObject.cpp index 0a290e0..6139d53 100644 --- a/game/prefab/ZapperObject.cpp +++ b/game/prefab/ZapperObject.cpp @@ -81,12 +81,9 @@ ZapperObject::ZapperObject(crepe::GameObject && base) })}, collider {add_component<BoxCollider>(vec2(0, 0))} { this->set_active(false); - Log::logf(Log::DEBUG, "Creating zapper"); } void ZapperObject::place(const crepe::vec2 & position, float rotation, float length) { - Log::logf(Log::DEBUG, "Placing zapper [position = {}, rotation = {}, length = {}]", position, rotation, length); - this->transform.position = position; this->transform.rotation = rotation; diff --git a/game/prefab/ZapperPoolScript.cpp b/game/prefab/ZapperPoolScript.cpp index ac6ce96..168637c 100644 --- a/game/prefab/ZapperPoolScript.cpp +++ b/game/prefab/ZapperPoolScript.cpp @@ -30,33 +30,30 @@ void ZapperPoolScript::fixed_update(crepe::duration_t) { if (zapper.transform.position.x < threshold) zapper.set_active(false); } - - if (i-- > 0) return; - i = 200; - queue_event<CreateZapperEvent>(); } 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); diff --git a/game/prefab/ZapperPoolScript.h b/game/prefab/ZapperPoolScript.h index 6aee8b2..dd60071 100644 --- a/game/prefab/ZapperPoolScript.h +++ b/game/prefab/ZapperPoolScript.h @@ -28,6 +28,7 @@ private: void spawn_random(); private: - static constexpr float OFFSCREEN_MARGIN = 40; + static constexpr float MAX_LENGTH = 400; + static constexpr float OFFSCREEN_MARGIN = 50 + MAX_LENGTH; }; |