grav well only follows mouse when space is pressed
[physics.git] / src / effectManager.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
f206d19d
PG
18#include "effectManager.h"
19
33b8c69b 20#include "Effects/Effect.h"
f206d19d 21#include "Effects/Gravity.h"
46e842c7 22#include "Effects/GravityWell.h"
2c18685d 23#include "Effects/Screen.h"
f206d19d 24
46e842c7 25#include "Vector2.h"
a823a800 26#include "input/inputManager.h"
a860c0c7 27#include "config/config.h"
46e842c7 28
33b8c69b 29/// ***** Private Variables *****
617dcc71 30
33b8c69b
PG
31Effect** effects;
32int numEffects;
33
a823a800
PG
34GravityWell* mouseWell;
35
617dcc71 36/// ***** Initializers/Cleaners *****
33b8c69b
PG
37
38void effect::init()
39{
46e842c7 40 numEffects = 3;
33b8c69b
PG
41 effects = new Effect*[numEffects]();
42
a823a800
PG
43 mouseWell = new GravityWell(input::mousePosition());
44
a860c0c7 45 effects[0] = new Screen();
a823a800 46 effects[1] = new Gravity();
a860c0c7 47 effects[2] = mouseWell;
33b8c69b
PG
48}
49void effect::clean()
50{
51 for(int i=0; i < numEffects; i++)
52 {
53 delete effects[i];
54 }
55
b8adb435 56 delete[] effects;
33b8c69b 57}
f206d19d 58
617dcc71
PG
59/// ***** Public Methods *****
60
a823a800
PG
61void effect::update(float)
62{
63
64}
65void effect::handleInput()
66{
a860c0c7
PG
67 if(cfg::mouseWellOn())
68 {
69 numEffects = 3;
70 mouseWell->setPosition(input::mousePosition());
71 }
72 else
73 {
74 numEffects = 2;
75 }
a823a800
PG
76}
77
f206d19d
PG
78Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step)
79{
33b8c69b
PG
80 Vector2 acc(0,0);
81
82 for(int i=0; i < numEffects; i++)
83 {
84 acc += effects[i]->positionDelta(e, time_step);
85 }
86
87 return acc;
f206d19d
PG
88}
89Vector2 effect::velocityDelta(const PhysicsEntity* e, float time_step)
90{
33b8c69b
PG
91 Vector2 acc(0,0);
92
93 for(int i=0; i < numEffects; i++)
94 {
95 acc += effects[i]->velocityDelta(e, time_step);
96 }
97
98 return acc;
f206d19d
PG
99}
100Vector2 effect::forceDelta(const PhysicsEntity* e, float time_step)
101{
33b8c69b
PG
102 Vector2 acc(0,0);
103
104 for(int i=0; i < numEffects; i++)
105 {
106 acc += effects[i]->forceDelta(e, time_step);
107 }
108
109 return acc;
f206d19d 110}