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 typedef bear::Queue<Ball*> queBall;
33 typedef bear::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 *****
69 pBall = addBall(Vector2(50, 50), 20, cWhite, s_startBalls);
70 pBall->m_mass = fStartMass;
72 pBall = addBall(Vector2(150, 50), 20, cGrey, s_startBalls);
73 pBall->m_mass = fStartMass;
75 pBall = addBall(Vector2(50, 100), 20, cRed, s_startBalls);
76 pBall->m_mass = fStartMass;
78 pBall = addBall(Vector2(100, 100), 20, cGreen, s_startBalls);
79 pBall->m_mass = fStartMass;
81 pBall = addBall(Vector2(150, 100), 20, cBlue, s_startBalls);
82 pBall->m_mass = fStartMass;
84 pBall = addBall(Vector2(50, 150), 20, cYellow, s_startBalls);
85 pBall->m_mass = fStartMass;
87 pBall = addBall(Vector2(100, 150), 20, cMagenta, s_startBalls);
88 pBall->m_mass = fStartMass;
90 pBall = addBall(Vector2(150, 150), 20, cCyan, s_startBalls);
91 pBall->m_mass = fStartMass;
94 for( int i = 0; i < 50; i++)
96 addBall(Vector2(200 + i * 2, 200 + i * 2), 10, cCyan);
100 vector<Vector2> points;
101 points.push_back(Vector2(500,500));
102 points.push_back(Vector2(300,500));
103 points.push_back(Vector2(500,300));
105 addPoly(points, cRed, s_startPolys);
111 void creator::clean()
113 removeAllPolys(s_startPolys);
116 removeAllBalls(s_mouseBalls);
119 removeAllBalls(s_startBalls);
123 /// ***** Public Methods *****
125 void creator::addBall(const Vector2& pos, float radius, const float* color)
127 addBall(pos, radius, color, s_mouseBalls);
129 void creator::removeBall()
131 removeBall(s_mouseBalls);
133 void creator::removeAllBalls()
135 removeAllBalls(s_mouseBalls);
138 void creator::handleInput()
140 if(input::mouseLeft())
141 addBall(input::mousePosition(), 10, cCyan);
143 if(input::mouseRight() && ! s_mouseBalls.isEmpty())
147 /// ***** Private Methods *****
149 Ball* addBall(const Vector2& vecPos,
154 Ball* pBall = new Ball(vecPos, fRadius, color);
161 Polygon* addPoly(const vector<Vector2>& vecPoints,
165 Polygon* pPoly = new Polygon(vecPoints, color);
173 void removeBall(queBall& que)
175 Ball* pBall = que.getFront();
177 manager::remove(pBall);
182 void removeAllBalls(queBall& que)
184 while(! que.isEmpty() )
190 static void removePoly(quePoly& que)
192 Polygon* pPoly = que.getFront();
194 manager::remove(pPoly);
199 static void removeAllPolys(quePoly& que)
201 while(! que.isEmpty() )