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"
20 #include <bear/Queue.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 //static bear::Queue<int> s_test;
34 typedef bear::Queue<Ball*> queBall;
35 typedef bear::Queue<Polygon*> quePoly;
37 static queBall s_startBalls;
38 static queBall s_mouseBalls;
40 static quePoly s_startPolys;
42 /// ***** Private Method Headers *****
44 static Ball* addBall(const Vector2& vecPos,
49 static Polygon* addPoly(const vector<Vector2>& vecPoints,
53 static void removeBall(queBall& que);
54 static void removeAllBalls(queBall& que);
56 static void removePoly(quePoly& que);
57 static void removeAllPolys(quePoly& que);
59 /// ***** Initializers/Cleaners *****
71 pBall = addBall(Vector2(50, 50), 20, cWhite, s_startBalls);
72 pBall->mass = fStartMass;
74 pBall = addBall(Vector2(150, 50), 20, cGrey, s_startBalls);
75 pBall->mass = fStartMass;
77 pBall = addBall(Vector2(50, 100), 20, cRed, s_startBalls);
78 pBall->mass = fStartMass;
80 pBall = addBall(Vector2(100, 100), 20, cGreen, s_startBalls);
81 pBall->mass = fStartMass;
83 pBall = addBall(Vector2(150, 100), 20, cBlue, s_startBalls);
84 pBall->mass = fStartMass;
86 pBall = addBall(Vector2(50, 150), 20, cYellow, s_startBalls);
87 pBall->mass = fStartMass;
89 pBall = addBall(Vector2(100, 150), 20, cMagenta, s_startBalls);
90 pBall->mass = fStartMass;
92 pBall = addBall(Vector2(150, 150), 20, cCyan, s_startBalls);
93 pBall->mass = fStartMass;
96 for( int i = 0; i < 50; i++)
98 addBall(Vector2(200 + i * 2, 200 + i * 2), 10, cCyan);
102 vector<Vector2> points;
103 points.push_back(Vector2(500,500));
104 points.push_back(Vector2(300,500));
105 points.push_back(Vector2(500,300));
107 addPoly(points, cRed, s_startPolys);
109 void creator::clean()
111 removeAllPolys(s_startPolys);
114 removeAllBalls(s_mouseBalls);
117 removeAllBalls(s_startBalls);
121 /// ***** Public Methods *****
123 void creator::addBall(const Vector2& pos, float radius, const float* color)
125 addBall(pos, radius, color, s_mouseBalls);
127 void creator::removeBall()
129 removeBall(s_mouseBalls);
131 void creator::removeAllBalls()
133 removeAllBalls(s_mouseBalls);
136 void creator::handleInput()
138 if(input::mouseLeft())
139 addBall(input::mousePosition(), 10, cCyan);
141 if(input::mouseRight() && ! s_mouseBalls.isEmpty())
145 /// ***** Private Methods *****
147 Ball* addBall(const Vector2& vecPos,
152 Ball* pBall = new Ball(vecPos, fRadius, color);
159 Polygon* addPoly(const vector<Vector2>& vecPoints,
163 Polygon* pPoly = new Polygon(vecPoints, color);
171 void removeBall(queBall& que)
173 Ball* pBall = que.getFront();
175 manager::remove(pBall);
180 void removeAllBalls(queBall& que)
182 while(! que.isEmpty() )
188 static void removePoly(quePoly& que)
190 Polygon* pPoly = que.getFront();
192 manager::remove(pPoly);
197 static void removeAllPolys(quePoly& que)
199 while(! que.isEmpty() )