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 | ||
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" |
46e842c7 | 27 | |
33b8c69b | 28 | /// ***** Private Variables ***** |
617dcc71 | 29 | |
33b8c69b PG |
30 | Effect** effects; |
31 | int numEffects; | |
32 | ||
a823a800 PG |
33 | GravityWell* mouseWell; |
34 | ||
617dcc71 | 35 | /// ***** Initializers/Cleaners ***** |
33b8c69b PG |
36 | |
37 | void effect::init() | |
38 | { | |
46e842c7 | 39 | numEffects = 3; |
33b8c69b PG |
40 | effects = new Effect*[numEffects](); |
41 | ||
a823a800 PG |
42 | mouseWell = new GravityWell(input::mousePosition()); |
43 | ||
44 | effects[0] = mouseWell; | |
45 | effects[1] = new Gravity(); | |
46e842c7 | 46 | effects[2] = new Screen(); |
33b8c69b PG |
47 | } |
48 | void effect::clean() | |
49 | { | |
50 | for(int i=0; i < numEffects; i++) | |
51 | { | |
52 | delete effects[i]; | |
53 | } | |
54 | ||
b8adb435 | 55 | delete[] effects; |
33b8c69b | 56 | } |
f206d19d | 57 | |
617dcc71 PG |
58 | /// ***** Public Methods ***** |
59 | ||
a823a800 PG |
60 | void effect::update(float) |
61 | { | |
62 | ||
63 | } | |
64 | void effect::handleInput() | |
65 | { | |
66 | mouseWell->setPosition(input::mousePosition()); | |
67 | } | |
68 | ||
f206d19d PG |
69 | Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step) |
70 | { | |
33b8c69b PG |
71 | Vector2 acc(0,0); |
72 | ||
73 | for(int i=0; i < numEffects; i++) | |
74 | { | |
75 | acc += effects[i]->positionDelta(e, time_step); | |
76 | } | |
77 | ||
78 | return acc; | |
f206d19d PG |
79 | } |
80 | Vector2 effect::velocityDelta(const PhysicsEntity* e, float time_step) | |
81 | { | |
33b8c69b PG |
82 | Vector2 acc(0,0); |
83 | ||
84 | for(int i=0; i < numEffects; i++) | |
85 | { | |
86 | acc += effects[i]->velocityDelta(e, time_step); | |
87 | } | |
88 | ||
89 | return acc; | |
f206d19d PG |
90 | } |
91 | Vector2 effect::forceDelta(const PhysicsEntity* e, float time_step) | |
92 | { | |
33b8c69b PG |
93 | Vector2 acc(0,0); |
94 | ||
95 | for(int i=0; i < numEffects; i++) | |
96 | { | |
97 | acc += effects[i]->forceDelta(e, time_step); | |
98 | } | |
99 | ||
100 | return acc; | |
f206d19d | 101 | } |