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