From 60672810d676498f610657e4c17931d15483b7d4 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 18 Apr 2022 22:05:26 +0200 Subject: Added removal of bullets above the field in ConstantVelocity --- ConstantVelocity.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ConstantVelocity.cpp b/ConstantVelocity.cpp index efe3117..b7f3b99 100644 --- a/ConstantVelocity.cpp +++ b/ConstantVelocity.cpp @@ -12,6 +12,7 @@ ConstantVelocitySystem::ConstantVelocitySystem() void ConstantVelocitySystem::update(const float dt) { + const int min_height = 0 - 3 * MARGIN; const int max_height = GetScreenHeight() + MARGIN; const int min_width = 0 - MARGIN; const int max_width = GetScreenWidth() + MARGIN; @@ -20,7 +21,9 @@ ConstantVelocitySystem::update(const float dt) auto& bullet = *it; bullet.position.x += bullet.velocity.x * dt; bullet.position.y += bullet.velocity.y * dt; - if (bullet.position.y > max_height || bullet.position.x < min_width || bullet.position.x > max_width) + const bool y_exceeded = bullet.position.y < min_height || bullet.position.y > max_height; + const bool x_exceeded = bullet.position.x < min_width || bullet.position.x > max_width; + if (y_exceeded || x_exceeded) it = m_bullets.erase(it); else ++it; -- cgit v1.1