summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ConstantVelocity.cpp5
1 files changed, 4 insertions, 1 deletions
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;