aboutsummaryrefslogtreecommitdiff
path: root/Simulation/Pellet.cpp
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2024-02-29 19:27:35 +0100
committerPaul Oliver <contact@pauloliver.dev>2024-02-29 19:27:49 +0100
commit17909d029c6a8872b2fddf4e171d7925bbbe9c5c (patch)
treecbb08af84cd68d24acc362d593a2048b0fa79689 /Simulation/Pellet.cpp
Initial commitHEADmaster
Diffstat (limited to 'Simulation/Pellet.cpp')
-rw-r--r--Simulation/Pellet.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/Simulation/Pellet.cpp b/Simulation/Pellet.cpp
new file mode 100644
index 0000000..1a911ff
--- /dev/null
+++ b/Simulation/Pellet.cpp
@@ -0,0 +1,66 @@
+#include "Pellet.hpp"
+#include "SimBase.hpp"
+
+void Pellet::startup(SimBase *sim)
+{
+ hSim = sim;
+ radius = Params::PELLET_RAD;
+}
+
+
+void Pellet::update()
+{
+ if (!body)
+ {
+ return;
+ }
+
+ if (toBeDestroyed)
+ {
+ destroy();
+ }
+}
+
+
+void Pellet::destroy()
+{
+ toBeDestroyed = false;
+ hSim->tank.world.DestroyBody(body);
+ body = nullptr;
+
+ --hSim->pelletCount;
+ hSim->text.pelletCnt.setString("Pellet count: " + nts(hSim->pelletCount) + " / " + nts(hSim->prms.pelletQtty));
+}
+
+
+void Pellet::draw()
+{
+ if (!body)
+ {
+ return;
+ }
+
+ sf::Vector2f vSize = hSim->window.getView().getSize();
+ sf::Vector2f vCent = hSim->window.getView().getCenter();
+ if ( body->GetPosition().x + radius < vCent.x - vSize.x / 2.f ||
+ body->GetPosition().y + radius < vCent.y - vSize.y / 2.f ||
+ body->GetPosition().x - radius > vCent.x + vSize.x / 2.f ||
+ body->GetPosition().y - radius > vCent.y + vSize.y / 2.f )
+ {
+ return;
+ }
+
+ if (hSim->camera.zoom > Params::PELLET_RAD / 2.f)
+ {
+ hSim->pelletPoint.setPosition(body->GetPosition().x, body->GetPosition().y);
+ hSim->window.draw(hSim->pelletPoint);
+ }
+ else
+ {
+ hSim->pelletShell.setPosition(body->GetPosition().x, body->GetPosition().y);
+ hSim->pelletNucleus.setPosition(body->GetPosition().x, body->GetPosition().y);
+ hSim->pelletNucleus.setRotation(body->GetAngle() * hSim->prms.RAD_DGRS);
+ hSim->window.draw(hSim->pelletShell);
+ hSim->window.draw(hSim->pelletNucleus);
+ }
+}