#include <queue>
#include "entityManager.h"
+#include "input/inputManager.h"
+
#include "Entities/Ball.h"
+#include "Entities/Polygon.h"
#include "graphics/colors.h"
+
/// ***** Private Variables *****
typedef std::queue<Ball*> queBall;
-queBall Balls;
-/// ***** Initializers/Cleaners *****
+queBall startBalls;
+queBall mouseBalls;
-void creator::init()
-{
- Ball* ball;
+/// ***** Private Method Headers *****
- ball = new Ball(Vector2(50, 50), 20, cWhite);
-
- ball->applyImpulse(Vector2(0.25,0.05)),
- Balls.push(ball);
- manager::add(ball);
-
- ball = new Ball(Vector2(100, 50), 20, cBlack);
-
- ball->applyImpulse(Vector2(-0.15,-0.05)),
- Balls.push(ball);
- manager::add(ball);
+Ball* addBall(const Vector2& pos,
+ float radius,
+ const float* color,
+ queBall& que);
- ball = new Ball(Vector2(150, 50), 20, cGrey);
+void removeBall(queBall& que);
+void removeAllBalls(queBall& que);
- ball->applyImpulse(Vector2(0.25,0.15)),
- Balls.push(ball);
- manager::add(ball);
+/// ***** Initializers/Cleaners *****
- ball = new Ball(Vector2(50, 100), 20, cRed);
+void creator::init()
+{
+ Ball* ball;
+ float startMass = 5;
- ball->applyImpulse(Vector2(0.35,-0.15)),
- Balls.push(ball);
- manager::add(ball);
+ ball = addBall(Vector2(50, 50), 20, cWhite, startBalls);
+ ball->mass = startMass;
- ball = new Ball(Vector2(100, 100), 20, cGreen);
+ ball = addBall(Vector2(150, 50), 20, cGrey, startBalls);
+ ball->mass = startMass;
- ball->applyImpulse(Vector2(-0.15,0.55)),
- Balls.push(ball);
- manager::add(ball);
+ ball = addBall(Vector2(50, 100), 20, cRed, startBalls);
+ ball->mass = startMass;
- ball = new Ball(Vector2(150, 100), 20, cBlue);
+ ball = addBall(Vector2(100, 100), 20, cGreen, startBalls);
+ ball->mass = startMass;
- ball->applyImpulse(Vector2(0.25,0.15)),
- Balls.push(ball);
- manager::add(ball);
+ ball = addBall(Vector2(150, 100), 20, cBlue, startBalls);
+ ball->mass = startMass;
- ball = new Ball(Vector2(50, 150), 20, cYellow);
+ ball = addBall(Vector2(50, 150), 20, cYellow, startBalls);
+ ball->mass = startMass;
- ball->applyImpulse(Vector2(0.25,-0.05)),
- Balls.push(ball);
- manager::add(ball);
+ ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls);
+ ball->mass = startMass;
- ball = new Ball(Vector2(100, 150), 20, cMagenta);
+ ball = addBall(Vector2(150, 150), 20, cCyan, startBalls);
+ ball->mass = startMass;
- ball->applyImpulse(Vector2(-0.15,-0.05)),
- Balls.push(ball);
- manager::add(ball);
+ for( int i = 0; i<50; i++)
+ {
+ addBall(Vector2(200+i*2, 200+i*2), 10, cCyan);
+ }
- ball = new Ball(Vector2(150, 150), 20, cCyan);
+ // HACK
+ // add a polygon into the mix (currently not cleaned up)
+ vector<Vector2> points;
+ points.push_back(Vector2(500,500));
+ points.push_back(Vector2(300,500));
+ points.push_back(Vector2(500,300));
- ball->applyImpulse(Vector2(-0.15,0.05)),
- Balls.push(ball);
- manager::add(ball);
+ manager::add(new Polygon(points));
}
void creator::clean()
{
- removeAllBalls();
+ removeAllBalls(startBalls);
+ removeAllBalls(mouseBalls);
}
/// ***** Public Methods *****
-void creator::addBall()
+void creator::addBall(const Vector2& pos, float radius, const float* color)
{
- //TODO
+ addBall(pos, radius, color, mouseBalls);
}
void creator::removeBall()
{
- //TODO
+ removeBall(mouseBalls);
}
void creator::removeAllBalls()
{
- while(! Balls.empty() )
+ 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);
+
+ que.push(ball);
+ manager::add(ball);
+
+ return ball;
+}
+
+void removeBall(queBall& que)
+{
+ Ball* ball = que.front();
+
+ manager::remove(ball);
+ que.pop();
+
+ delete ball;
+}
+void removeAllBalls(queBall& que)
+{
+ while(! que.empty() )
{
- Ball* ball = Balls.front();
- Balls.pop();
+ Ball* ball = que.front();
+ que.pop();
manager::remove(ball);
delete ball;