+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include "entityCreator.h"
+#include <queue>
+
#include "entityManager.h"
+#include "input/inputManager.h"
+
#include "Entities/Ball.h"
#include "graphics/colors.h"
-/// ***** Private Method Headers *****
-Ball* ball1;
/// ***** Private Variables *****
-/// ***** Public Methods *****
+typedef std::queue<Ball*> queBall;
+
+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()
{
- Vector2 pos(400, 400);
- ball1 = new Ball(pos, 20, cBlue);
+ 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;
- manager::add(ball1);
+ 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;
}
void creator::clean()
{
- manager::remove(ball1);
+ removeAllBalls(startBalls);
+ removeAllBalls(mouseBalls);
+}
- delete ball1;
+/// ***** 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::addBall()
+void creator::handleInput()
{
+ if(input::mouseLeft())
+ addBall(input::mousePosition(), 10, cCyan);
+ if(input::mouseRight() && ! mouseBalls.empty())
+ removeBall();
}
-void creator::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 creator::removeAllBalls()
+
+void removeBall(queBall& que)
+{
+ Ball* ball = que.front();
+
+ manager::remove(ball);
+ que.pop();
+
+ delete ball;
+}
+void removeAllBalls(queBall& que)
{
+ while(! que.empty() )
+ {
+ Ball* ball = que.front();
+ que.pop();
+ manager::remove(ball);
+ delete ball;
+ }
}