start balls now weigh more
[physics.git] / src / entityCreator.cpp
CommitLineData
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 22#include "entityManager.h"
10baa49b
PG
23#include "input/inputManager.h"
24
a483ed75
PG
25#include "Entities/Ball.h"
26#include "graphics/colors.h"
27
10baa49b 28
617dcc71
PG
29/// ***** Private Variables *****
30
f72f4a59 31typedef std::queue<Ball*> queBall;
10baa49b
PG
32
33queBall startBalls;
34queBall mouseBalls;
35
36/// ***** Private Method Headers *****
37
38Ball* addBall(const Vector2& pos,
39 float radius,
40 const float* color,
41 queBall& que);
42
43void removeBall(queBall& que);
44void removeAllBalls(queBall& que);
a483ed75 45
617dcc71 46/// ***** Initializers/Cleaners *****
a483ed75 47
054d658f
PG
48void creator::init()
49{
6a40b627
PG
50 Ball* ball;
51
52 ball = addBall(Vector2(50, 50), 20, cWhite, startBalls);
53 ball->mass = 10;
54
55 ball = addBall(Vector2(150, 50), 20, cGrey, startBalls);
56 ball->mass = 10;
57
58 ball = addBall(Vector2(50, 100), 20, cRed, startBalls);
59 ball->mass = 10;
60
61 ball = addBall(Vector2(100, 100), 20, cGreen, startBalls);
62 ball->mass = 10;
63
64 ball = addBall(Vector2(150, 100), 20, cBlue, startBalls);
65 ball->mass = 10;
66
67 ball = addBall(Vector2(50, 150), 20, cYellow, startBalls);
68 ball->mass = 10;
69
70 ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls);
71 ball->mass = 10;
72
73 ball = addBall(Vector2(150, 150), 20, cCyan, startBalls);
74 ball->mass = 10;
054d658f
PG
75}
76void creator::clean()
77{
10baa49b
PG
78 removeAllBalls(startBalls);
79 removeAllBalls(mouseBalls);
054d658f
PG
80}
81
617dcc71
PG
82/// ***** Public Methods *****
83
88e62c4f 84void creator::addBall(const Vector2& pos, float radius, const float* color)
054d658f 85{
10baa49b
PG
86 addBall(pos, radius, color, mouseBalls);
87}
88void creator::removeBall()
89{
90 removeBall(mouseBalls);
91}
92void creator::removeAllBalls()
93{
94 removeAllBalls(mouseBalls);
95}
96
97void creator::handleInput()
98{
99 if(input::mouseLeft())
100 addBall(input::mousePosition(), 10, cCyan);
101
102 if(input::mouseRight() && ! mouseBalls.empty())
103 removeBall();
104}
105
106/// ***** Private Methods *****
107
108Ball* addBall(const Vector2& pos,
109 float radius,
110 const float* color,
111 queBall& que)
112{
88e62c4f
PG
113 Ball* ball = new Ball(pos, radius, color);
114
10baa49b 115 que.push(ball);
88e62c4f 116 manager::add(ball);
10baa49b
PG
117
118 return ball;
054d658f 119}
10baa49b
PG
120
121void removeBall(queBall& que)
054d658f 122{
10baa49b 123 Ball* ball = que.front();
88e62c4f 124
10baa49b
PG
125 manager::remove(ball);
126 que.pop();
88e62c4f
PG
127
128 delete ball;
054d658f 129}
10baa49b 130void removeAllBalls(queBall& que)
054d658f 131{
10baa49b 132 while(! que.empty() )
f72f4a59 133 {
10baa49b
PG
134 Ball* ball = que.front();
135 que.pop();
f72f4a59 136 manager::remove(ball);
054d658f 137
f72f4a59
PG
138 delete ball;
139 }
054d658f 140}