Commit | Line | Data |
---|---|---|
e68f847b PG |
1 | /* |
2 | * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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/>. | |
16 | */ | |
17 | ||
054d658f PG |
18 | #include "entityCreator.h" |
19 | ||
f72f4a59 PG |
20 | #include <queue> |
21 | ||
a483ed75 PG |
22 | #include "entityManager.h" |
23 | #include "Entities/Ball.h" | |
24 | #include "graphics/colors.h" | |
25 | ||
617dcc71 PG |
26 | /// ***** Private Variables ***** |
27 | ||
f72f4a59 PG |
28 | typedef std::queue<Ball*> queBall; |
29 | queBall Balls; | |
a483ed75 | 30 | |
617dcc71 | 31 | /// ***** Initializers/Cleaners ***** |
a483ed75 | 32 | |
054d658f PG |
33 | void creator::init() |
34 | { | |
88e62c4f PG |
35 | addBall(Vector2(50, 50), 20, cWhite); |
36 | addBall(Vector2(150, 50), 20, cGrey); | |
37 | addBall(Vector2(50, 100), 20, cRed); | |
38 | addBall(Vector2(100, 100), 20, cGreen); | |
39 | addBall(Vector2(150, 100), 20, cBlue); | |
40 | addBall(Vector2(50, 150), 20, cYellow); | |
41 | addBall(Vector2(100, 150), 20, cMagenta); | |
42 | addBall(Vector2(150, 150), 20, cCyan); | |
054d658f PG |
43 | } |
44 | void creator::clean() | |
45 | { | |
f72f4a59 | 46 | removeAllBalls(); |
054d658f PG |
47 | } |
48 | ||
617dcc71 PG |
49 | /// ***** Public Methods ***** |
50 | ||
88e62c4f | 51 | void creator::addBall(const Vector2& pos, float radius, const float* color) |
054d658f | 52 | { |
88e62c4f PG |
53 | Ball* ball = new Ball(pos, radius, color); |
54 | ||
55 | Balls.push(ball); | |
56 | manager::add(ball); | |
054d658f PG |
57 | } |
58 | void creator::removeBall() | |
59 | { | |
88e62c4f PG |
60 | Ball* ball = Balls.front(); |
61 | ||
62 | Balls.pop(); | |
63 | ||
64 | delete ball; | |
054d658f PG |
65 | } |
66 | void creator::removeAllBalls() | |
67 | { | |
f72f4a59 PG |
68 | while(! Balls.empty() ) |
69 | { | |
70 | Ball* ball = Balls.front(); | |
71 | Balls.pop(); | |
72 | manager::remove(ball); | |
054d658f | 73 | |
f72f4a59 PG |
74 | delete ball; |
75 | } | |
054d658f | 76 | } |