2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "entityCreator.h"
22 #include "entityManager.h"
23 #include "input/inputManager.h"
25 #include "Entities/Ball.h"
26 #include "graphics/colors.h"
29 /// ***** Private Variables *****
31 typedef std::queue<Ball*> queBall;
36 /// ***** Private Method Headers *****
38 Ball* addBall(const Vector2& pos,
43 void removeBall(queBall& que);
44 void removeAllBalls(queBall& que);
46 /// ***** Initializers/Cleaners *****
53 ball = addBall(Vector2(50, 50), 20, cWhite, startBalls);
54 ball->mass = startMass;
56 ball = addBall(Vector2(150, 50), 20, cGrey, startBalls);
57 ball->mass = startMass;
59 ball = addBall(Vector2(50, 100), 20, cRed, startBalls);
60 ball->mass = startMass;
62 ball = addBall(Vector2(100, 100), 20, cGreen, startBalls);
63 ball->mass = startMass;
65 ball = addBall(Vector2(150, 100), 20, cBlue, startBalls);
66 ball->mass = startMass;
68 ball = addBall(Vector2(50, 150), 20, cYellow, startBalls);
69 ball->mass = startMass;
71 ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls);
72 ball->mass = startMass;
74 ball = addBall(Vector2(150, 150), 20, cCyan, startBalls);
75 ball->mass = startMass;
77 for( int i = 0; i<100; i++)
79 addBall(Vector2(200+i*2, 200+i*2), 10, cCyan);
84 removeAllBalls(startBalls);
85 removeAllBalls(mouseBalls);
88 /// ***** Public Methods *****
90 void creator::addBall(const Vector2& pos, float radius, const float* color)
92 addBall(pos, radius, color, mouseBalls);
94 void creator::removeBall()
96 removeBall(mouseBalls);
98 void creator::removeAllBalls()
100 removeAllBalls(mouseBalls);
103 void creator::handleInput()
105 if(input::mouseLeft())
106 addBall(input::mousePosition(), 10, cCyan);
108 if(input::mouseRight() && ! mouseBalls.empty())
112 /// ***** Private Methods *****
114 Ball* addBall(const Vector2& pos,
119 Ball* ball = new Ball(pos, radius, color);
127 void removeBall(queBall& que)
129 Ball* ball = que.front();
131 manager::remove(ball);
136 void removeAllBalls(queBall& que)
138 while(! que.empty() )
140 Ball* ball = que.front();
142 manager::remove(ball);