diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 19:27:35 +0100 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 19:27:49 +0100 |
commit | 17909d029c6a8872b2fddf4e171d7925bbbe9c5c (patch) | |
tree | cbb08af84cd68d24acc362d593a2048b0fa79689 /Simulation/Zapper.cpp |
Diffstat (limited to 'Simulation/Zapper.cpp')
-rw-r--r-- | Simulation/Zapper.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Simulation/Zapper.cpp b/Simulation/Zapper.cpp new file mode 100644 index 0000000..f31b996 --- /dev/null +++ b/Simulation/Zapper.cpp @@ -0,0 +1,46 @@ +#include "Zapper.hpp" +#include "SimBase.hpp" + +void Zapper::startup(SimBase *sim) +{ + hSim = sim; + radius = Params::ZAPPER_RAD; +} + + +void Zapper::update() +{ + float forceX = realRand(-hSim->prms.zapperForce, hSim->prms.zapperForce); + float forceY = realRand(-hSim->prms.zapperForce, hSim->prms.zapperForce); + body->ApplyForceToCenter(b2Vec2(forceX, forceY)); + float torque = realRand(-hSim->prms.zapperTorque, hSim->prms.zapperTorque); + body->ApplyTorque(torque); +} + + +void Zapper::draw() +{ + 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::ZAPPER_RAD / 2.f) + { + hSim->zapperPoint.setPosition(body->GetPosition().x, body->GetPosition().y); + hSim->window.draw(hSim->zapperPoint); + } + else + { + hSim->zapperShell.setPosition(body->GetPosition().x, body->GetPosition().y); + hSim->zapperNucleus.setPosition(body->GetPosition().x, body->GetPosition().y); + hSim->zapperNucleus.setRotation(body->GetAngle() * hSim->prms.RAD_DGRS); + hSim->window.draw(hSim->zapperShell); + hSim->window.draw(hSim->zapperNucleus); + } +} |