#include "ConstantVelocity.h" #include ConstantVelocitySystem::ConstantVelocitySystem() { m_bullets.reserve(RESERVED); } 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; auto it = m_bullets.begin(); while (it != m_bullets.end()) { auto& bullet = *it; bullet.position.x += bullet.velocity.x * dt; bullet.position.y += bullet.velocity.y * dt; 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; } } void ConstantVelocitySystem::draw() { for (const auto& bullet : m_bullets) DrawCircle(bullet.position.x, bullet.position.y, bullet.radius, bullet.color); }