X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2FentityCreator.cpp;h=191d3960ab350bc7e60809179c18835a6aa75c23;hb=30a93c3992f0e1fc44193dde6d53216d3ae4f4e9;hp=eddfb3d56338f526182fdc15445e6cc4e3a4998c;hpb=88e62c4ff5f422b930c38ab643121e5f8607d889;p=physics.git diff --git a/src/entityCreator.cpp b/src/entityCreator.cpp index eddfb3d..191d396 100644 --- a/src/entityCreator.cpp +++ b/src/entityCreator.cpp @@ -20,55 +20,135 @@ #include #include "entityManager.h" +#include "input/inputManager.h" + #include "Entities/Ball.h" +#include "Entities/Polygon.h" #include "graphics/colors.h" + /// ***** Private Variables ***** typedef std::queue queBall; -queBall Balls; + +queBall startBalls; +queBall mouseBalls; + +/// ***** Private Method Headers ***** + +Ball* addBall(const Vector2& pos, + float radius, + const float* color, + queBall& que); + +void removeBall(queBall& que); +void removeAllBalls(queBall& que); /// ***** Initializers/Cleaners ***** void creator::init() { - addBall(Vector2(50, 50), 20, cWhite); - addBall(Vector2(150, 50), 20, cGrey); - addBall(Vector2(50, 100), 20, cRed); - addBall(Vector2(100, 100), 20, cGreen); - addBall(Vector2(150, 100), 20, cBlue); - addBall(Vector2(50, 150), 20, cYellow); - addBall(Vector2(100, 150), 20, cMagenta); - addBall(Vector2(150, 150), 20, cCyan); + Ball* ball; + float startMass = 5; + + ball = addBall(Vector2(50, 50), 20, cWhite, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(150, 50), 20, cGrey, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(50, 100), 20, cRed, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(100, 100), 20, cGreen, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(150, 100), 20, cBlue, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(50, 150), 20, cYellow, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls); + ball->mass = startMass; + + ball = addBall(Vector2(150, 150), 20, cCyan, startBalls); + ball->mass = startMass; + + for( int i = 0; i<50; i++) + { + addBall(Vector2(200+i*2, 200+i*2), 10, cCyan); + } + + // HACK + // add a polygon into the mix (currently not cleaned up) + vector points; + points.push_back(Vector2(500,500)); + points.push_back(Vector2(300,500)); + points.push_back(Vector2(500,300)); + + manager::add(new Polygon(points, cRed)); } void creator::clean() { - removeAllBalls(); + removeAllBalls(startBalls); + removeAllBalls(mouseBalls); } /// ***** Public Methods ***** void creator::addBall(const Vector2& pos, float radius, const float* color) { + addBall(pos, radius, color, mouseBalls); +} +void creator::removeBall() +{ + removeBall(mouseBalls); +} +void creator::removeAllBalls() +{ + removeAllBalls(mouseBalls); +} + +void creator::handleInput() +{ + if(input::mouseLeft()) + addBall(input::mousePosition(), 10, cCyan); + + if(input::mouseRight() && ! mouseBalls.empty()) + removeBall(); +} + +/// ***** Private Methods ***** + +Ball* addBall(const Vector2& pos, + float radius, + const float* color, + queBall& que) +{ Ball* ball = new Ball(pos, radius, color); - Balls.push(ball); + que.push(ball); manager::add(ball); + + return ball; } -void creator::removeBall() + +void removeBall(queBall& que) { - Ball* ball = Balls.front(); + Ball* ball = que.front(); - Balls.pop(); + manager::remove(ball); + que.pop(); delete ball; } -void creator::removeAllBalls() +void removeAllBalls(queBall& que) { - while(! Balls.empty() ) + while(! que.empty() ) { - Ball* ball = Balls.front(); - Balls.pop(); + Ball* ball = que.front(); + que.pop(); manager::remove(ball); delete ball;