summaryrefslogtreecommitdiffhomepage
path: root/ConstantVelocity.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-18 11:05:24 +0200
committerAki <please@ignore.pl>2022-04-18 11:05:24 +0200
commit2773854a3e749512826fa8b71b77e754be79836f (patch)
treedf3771aae7025eae7505c53eebb36d5b3ff56f01 /ConstantVelocity.cpp
parentf0891205710c2d5c9b78a9d275de88a77c2ccda3 (diff)
downloadbullethell2022-2773854a3e749512826fa8b71b77e754be79836f.zip
bullethell2022-2773854a3e749512826fa8b71b77e754be79836f.tar.gz
bullethell2022-2773854a3e749512826fa8b71b77e754be79836f.tar.bz2
Renamed bullets header to simply ConstantVelocity
Diffstat (limited to 'ConstantVelocity.cpp')
-rw-r--r--ConstantVelocity.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/ConstantVelocity.cpp b/ConstantVelocity.cpp
new file mode 100644
index 0000000..37f3c3d
--- /dev/null
+++ b/ConstantVelocity.cpp
@@ -0,0 +1,42 @@
+#include "ConstantVelocity.h"
+
+#include <raylib.h>
+
+
+ConstantVelocitySystem::ConstantVelocitySystem() :
+ ConstantVelocitySystem(10000)
+{
+}
+
+
+ConstantVelocitySystem::ConstantVelocitySystem(int reserved)
+{
+ m_bullets.reserve(reserved);
+}
+
+
+void
+ConstantVelocitySystem::update(const float dt)
+{
+ 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 > 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);
+}