summaryrefslogtreecommitdiffhomepage
path: root/Bullets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bullets.cpp')
-rw-r--r--Bullets.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/Bullets.cpp b/Bullets.cpp
index 312e12e..62b6ea3 100644
--- a/Bullets.cpp
+++ b/Bullets.cpp
@@ -1,21 +1,42 @@
#include "Bullets.h"
-#include <vector>
-
#include <raylib.h>
+ConstantVelocitySystem::ConstantVelocitySystem() :
+ ConstantVelocitySystem(10000)
+{
+}
+
+
+ConstantVelocitySystem::ConstantVelocitySystem(int reserved)
+{
+ m_bullets.reserve(reserved);
+}
+
+
void
-update(const float dt, std::vector<ConstantVelocityBullet>& bullets)
+ConstantVelocitySystem::update(const float dt)
{
- auto it = bullets.begin();
- while (it != bullets.end()) {
+ 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;
- if (bullet.position.y > 800)
- it = bullets.erase(it);
+ if (bullet.position.y > max_height || bullet.position.x < min_width || bullet.position.x > max_width)
+ 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);
+}