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);
84 // add a polygon into the mix (currently not cleaned up)
85 vector<Vector2> points;
86 points.push_back(Vector2(500,500));
87 points.push_back(Vector2(300,500));
88 points.push_back(Vector2(500,300));
90 manager::add(new Polygon(points));
94 removeAllBalls(startBalls);
95 removeAllBalls(mouseBalls);
98 /// ***** Public Methods *****
100 void creator::addBall(const Vector2& pos, float radius, const float* color)
102 addBall(pos, radius, color, mouseBalls);
104 void creator::removeBall()
106 removeBall(mouseBalls);
108 void creator::removeAllBalls()
110 removeAllBalls(mouseBalls);
113 void creator::handleInput()
115 if(input::mouseLeft())
116 addBall(input::mousePosition(), 10, cCyan);
118 if(input::mouseRight() && ! mouseBalls.empty())
122 /// ***** Private Methods *****
124 Ball* addBall(const Vector2& pos,
129 Ball* ball = new Ball(pos, radius, color);
137 void removeBall(queBall& que)
139 Ball* ball = que.front();
141 manager::remove(ball);
146 void removeAllBalls(queBall& que)
148 while(! que.empty() )
150 Ball* ball = que.front();
152 manager::remove(ball);