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 "Entities/Polygon.h"
27 #include "graphics/colors.h"
30 /// ***** Private Variables *****
32 typedef std::queue<Ball*> queBall;
37 /// ***** Private Method Headers *****
39 Ball* addBall(const Vector2& pos,
44 void removeBall(queBall& que);
45 void removeAllBalls(queBall& que);
47 /// ***** Initializers/Cleaners *****
54 ball = addBall(Vector2(50, 50), 20, cWhite, startBalls);
55 ball->mass = startMass;
57 ball = addBall(Vector2(150, 50), 20, cGrey, startBalls);
58 ball->mass = startMass;
60 ball = addBall(Vector2(50, 100), 20, cRed, startBalls);
61 ball->mass = startMass;
63 ball = addBall(Vector2(100, 100), 20, cGreen, startBalls);
64 ball->mass = startMass;
66 ball = addBall(Vector2(150, 100), 20, cBlue, startBalls);
67 ball->mass = startMass;
69 ball = addBall(Vector2(50, 150), 20, cYellow, startBalls);
70 ball->mass = startMass;
72 ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls);
73 ball->mass = startMass;
75 ball = addBall(Vector2(150, 150), 20, cCyan, startBalls);
76 ball->mass = startMass;
78 for( int i = 0; i<50; i++)
80 addBall(Vector2(200+i*2, 200+i*2), 10, cCyan);
83 // add a polygon into the mix (currently not cleaned up)
84 vector<Vector2> points;
85 points.push_back(Vector2(50,50));
86 points.push_back(Vector2(50,100));
87 points.push_back(Vector2(100,50));
89 manager::add(new Polygon(points));
93 removeAllBalls(startBalls);
94 removeAllBalls(mouseBalls);
97 /// ***** Public Methods *****
99 void creator::addBall(const Vector2& pos, float radius, const float* color)
101 addBall(pos, radius, color, mouseBalls);
103 void creator::removeBall()
105 removeBall(mouseBalls);
107 void creator::removeAllBalls()
109 removeAllBalls(mouseBalls);
112 void creator::handleInput()
114 if(input::mouseLeft())
115 addBall(input::mousePosition(), 10, cCyan);
117 if(input::mouseRight() && ! mouseBalls.empty())
121 /// ***** Private Methods *****
123 Ball* addBall(const Vector2& pos,
128 Ball* ball = new Ball(pos, radius, color);
136 void removeBall(queBall& que)
138 Ball* ball = que.front();
140 manager::remove(ball);
145 void removeAllBalls(queBall& que)
147 while(! que.empty() )
149 Ball* ball = que.front();
151 manager::remove(ball);