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;
33 typedef std::queue<Polygon*> quePoly;
35 static queBall s_startBalls;
36 static queBall s_mouseBalls;
38 static quePoly s_startPolys;
40 /// ***** Private Method Headers *****
42 static Ball* addBall(const Vector2& vecPos,
47 static Polygon* addPoly(const vector<Vector2>& vecPoints,
51 static void removeBall(queBall& que);
52 static void removeAllBalls(queBall& que);
54 static void removePoly(quePoly& que);
55 static void removeAllPolys(quePoly& que);
57 /// ***** Initializers/Cleaners *****
64 pBall = addBall(Vector2(50, 50), 20, cWhite, s_startBalls);
65 pBall->mass = fStartMass;
67 pBall = addBall(Vector2(150, 50), 20, cGrey, s_startBalls);
68 pBall->mass = fStartMass;
70 pBall = addBall(Vector2(50, 100), 20, cRed, s_startBalls);
71 pBall->mass = fStartMass;
73 pBall = addBall(Vector2(100, 100), 20, cGreen, s_startBalls);
74 pBall->mass = fStartMass;
76 pBall = addBall(Vector2(150, 100), 20, cBlue, s_startBalls);
77 pBall->mass = fStartMass;
79 pBall = addBall(Vector2(50, 150), 20, cYellow, s_startBalls);
80 pBall->mass = fStartMass;
82 pBall = addBall(Vector2(100, 150), 20, cMagenta, s_startBalls);
83 pBall->mass = fStartMass;
85 pBall = addBall(Vector2(150, 150), 20, cCyan, s_startBalls);
86 pBall->mass = fStartMass;
89 for( int i = 0; i < 50; i++)
91 addBall(Vector2(200 + i * 2, 200 + i * 2), 10, cCyan);
95 vector<Vector2> points;
96 points.push_back(Vector2(500,500));
97 points.push_back(Vector2(300,500));
98 points.push_back(Vector2(500,300));
100 addPoly(points, cRed, s_startPolys);
102 void creator::clean()
104 removeAllBalls(s_startBalls);
105 removeAllBalls(s_mouseBalls);
107 removeAllPolys(s_startPolys);
110 /// ***** Public Methods *****
112 void creator::addBall(const Vector2& pos, float radius, const float* color)
114 addBall(pos, radius, color, s_mouseBalls);
116 void creator::removeBall()
118 removeBall(s_mouseBalls);
120 void creator::removeAllBalls()
122 removeAllBalls(s_mouseBalls);
125 void creator::handleInput()
127 if(input::mouseLeft())
128 addBall(input::mousePosition(), 10, cCyan);
130 if(input::mouseRight() && ! s_mouseBalls.empty())
134 /// ***** Private Methods *****
136 Ball* addBall(const Vector2& vecPos,
141 Ball* pBall = new Ball(vecPos, fRadius, color);
148 Polygon* addPoly(const vector<Vector2>& vecPoints,
152 Polygon* pPoly = new Polygon(vecPoints, color);
160 void removeBall(queBall& que)
162 Ball* pBall = que.front();
164 manager::remove(pBall);
169 void removeAllBalls(queBall& que)
171 while(! que.empty() )
177 static void removePoly(quePoly& que)
179 Polygon* pPoly = que.front();
181 manager::remove(pPoly);
186 static void removeAllPolys(quePoly& que)
188 while(! que.empty() )