diff options
Diffstat (limited to 'Simulation/Pellet.cpp')
-rw-r--r-- | Simulation/Pellet.cpp | 66 |
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); + } +} |