1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: hdavid, amaechler |
---|
13 | */ |
---|
14 | |
---|
15 | #include "lightening_effect.h" |
---|
16 | |
---|
17 | #include "state.h" |
---|
18 | #include "util/loading/load_param.h" |
---|
19 | #include "util/loading/factory.h" |
---|
20 | #include "effects/billboard.h" |
---|
21 | |
---|
22 | #include "glincl.h" |
---|
23 | #include "parser/tinyxml/tinyxml.h" |
---|
24 | |
---|
25 | #include "shell_command.h" |
---|
26 | #include "light.h" |
---|
27 | |
---|
28 | SHELL_COMMAND(activate, LighteningEffect, activateLightening); |
---|
29 | SHELL_COMMAND(deactivate, LighteningEffect, deactivateLightening); |
---|
30 | |
---|
31 | using namespace std; |
---|
32 | |
---|
33 | CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT); |
---|
34 | |
---|
35 | LighteningEffect::LighteningEffect(const TiXmlElement* root) |
---|
36 | { |
---|
37 | this->setClassID(CL_LIGHTENING_EFFECT, "LighteningEffect"); |
---|
38 | |
---|
39 | this->init(); |
---|
40 | |
---|
41 | if (root != NULL) |
---|
42 | this->loadParams(root); |
---|
43 | |
---|
44 | if(this->lighteningActivate) |
---|
45 | this->activate(); |
---|
46 | } |
---|
47 | |
---|
48 | LighteningEffect::~LighteningEffect() |
---|
49 | { |
---|
50 | this->deactivate(); |
---|
51 | } |
---|
52 | |
---|
53 | void LighteningEffect::loadParams(const TiXmlElement* root) |
---|
54 | { |
---|
55 | WeatherEffect::loadParams(root); |
---|
56 | |
---|
57 | LoadParam(root, "coord", this, LighteningEffect, coord); |
---|
58 | LoadParam(root, "option", this, LighteningEffect, setLighteningOption); |
---|
59 | LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency); |
---|
60 | LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime); |
---|
61 | LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime); |
---|
62 | LoadParam(root, "size", this, LighteningEffect, setFlashSize); |
---|
63 | LoadParam(root, "seed", this, LighteningEffect, setFlashSeed); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | bool LighteningEffect::init() |
---|
68 | { |
---|
69 | lighteningActivate = false; |
---|
70 | |
---|
71 | this->time = 0.0; |
---|
72 | this->flashFrequency = 1.4f; |
---|
73 | this->mainFrequency = 1.4f; |
---|
74 | this->flashConstTime = 0.5f; |
---|
75 | this->flashRisingTime = 0.1f; |
---|
76 | |
---|
77 | this->width = 400.0f; |
---|
78 | this->height = 100.0f; |
---|
79 | this->seedWidth = 50; |
---|
80 | this->seedHeight = 50; |
---|
81 | this->bNewCoordinate = false; |
---|
82 | |
---|
83 | this->seedX = 500.f; |
---|
84 | this->seedZ = 1000.0f; |
---|
85 | this->seedTime = 4.0f; |
---|
86 | |
---|
87 | this->billboard[0] = new Billboard(NULL); |
---|
88 | this->billboard[0]->setTexture("maps/lightning_bolt1.png"); |
---|
89 | this->billboard[0]->setSize(this->width, this->height); |
---|
90 | this->billboard[0]->setAbsCoor(3000,850,0); |
---|
91 | this->billboard[0]->setVisibiliy(false); |
---|
92 | |
---|
93 | this->billboard[1] = new Billboard(NULL); |
---|
94 | this->billboard[1]->setTexture("maps/lightning_bolt2.png"); |
---|
95 | this->billboard[1]->setSize(this->width, this->height); |
---|
96 | this->billboard[1]->setAbsCoor(3000,850,0); |
---|
97 | this->billboard[1]->setVisibiliy(false); |
---|
98 | |
---|
99 | this->billboard[2] = new Billboard(NULL); |
---|
100 | this->billboard[2]->setTexture("maps/lightning_bolt3.png"); |
---|
101 | this->billboard[2]->setSize(this->width, this->height); |
---|
102 | this->billboard[2]->setAbsCoor(3000,850,0); |
---|
103 | this->billboard[2]->setVisibiliy(false); |
---|
104 | |
---|
105 | this->billboard[3] = new Billboard(NULL); |
---|
106 | this->billboard[3]->setTexture("maps/lightning_bolt4.png"); |
---|
107 | this->billboard[3]->setSize(this->width, this->height); |
---|
108 | this->billboard[3]->setAbsCoor(3000,850,0); |
---|
109 | this->billboard[3]->setVisibiliy(false); |
---|
110 | /* |
---|
111 | this->soundSource = NULL; |
---|
112 | this->thunderBuffer = NULL; |
---|
113 | |
---|
114 | this->soundSource.setSourceNode(this); |
---|
115 | |
---|
116 | //load sound |
---|
117 | if (this->thunderBuffer != NULL) |
---|
118 | ResourceManager::getInstance()->unload(this->thunderBuffer); |
---|
119 | this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ |
---|
120 | } |
---|
121 | |
---|
122 | void LighteningEffect::coord(float x, float y, float z) |
---|
123 | { |
---|
124 | this->billboard[0]->setAbsCoor(x, y, z); |
---|
125 | this->billboard[1]->setAbsCoor(x, y, z); |
---|
126 | this->billboard[2]->setAbsCoor(x, y, z); |
---|
127 | this->billboard[3]->setAbsCoor(x, y, z); |
---|
128 | this->mainPosX = x; |
---|
129 | this->mainPosY = y; |
---|
130 | this->mainPosZ = z; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight) |
---|
135 | { |
---|
136 | this->width = width; |
---|
137 | this->height = height; |
---|
138 | this->seedWidth = seedWidth; |
---|
139 | this->seedHeight = seedHeight; |
---|
140 | this->billboard[0]->setSize(this->width, this->height); |
---|
141 | this->billboard[1]->setSize(this->width, this->height); |
---|
142 | this->billboard[2]->setSize(this->width, this->height); |
---|
143 | this->billboard[3]->setSize(this->width, this->height); |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | bool LighteningEffect::activate() |
---|
148 | { |
---|
149 | PRINTF(0)( "Activating LighteningEffect\n" ); |
---|
150 | this->time = 0; |
---|
151 | lighteningActivate = true; |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | bool LighteningEffect::deactivate() |
---|
156 | { |
---|
157 | PRINTF(0)("Deactivating LighteningEffect\n"); |
---|
158 | this->billboard[0]->setVisibiliy(false); |
---|
159 | this->billboard[1]->setVisibiliy(false); |
---|
160 | this->billboard[2]->setVisibiliy(false); |
---|
161 | this->billboard[3]->setVisibiliy(false); |
---|
162 | lighteningActivate = false; |
---|
163 | } |
---|
164 | |
---|
165 | void LighteningEffect::tick (float dt) |
---|
166 | { |
---|
167 | if(!lighteningActivate) |
---|
168 | return; |
---|
169 | |
---|
170 | this->time += dt; |
---|
171 | |
---|
172 | /*if( flashLight != NULL) |
---|
173 | { |
---|
174 | if((int)(100*time)%2) |
---|
175 | this->flashLight->setDiffuseColor(0,0,0); |
---|
176 | else |
---|
177 | this->flashLight->setDiffuseColor(100,100,100); |
---|
178 | |
---|
179 | //PRINTF(0)("100*time: %f %i\n", 100*time, (int)(100*time)); |
---|
180 | }*/ |
---|
181 | |
---|
182 | if( this->time > this->flashFrequency) |
---|
183 | { |
---|
184 | this->billboard[0]->setVisibiliy(true); |
---|
185 | this->time = 0.0f; |
---|
186 | |
---|
187 | this->flashLight = new Light(); |
---|
188 | this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z); |
---|
189 | this->flashLight->setDiffuseColor(100,100,100); |
---|
190 | |
---|
191 | //this->soundSource.play(this->thunderBuffer); |
---|
192 | } |
---|
193 | else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) |
---|
194 | { |
---|
195 | this->billboard[3]->setVisibiliy(false); |
---|
196 | this->time = 0.0f; |
---|
197 | this->bNewCoordinate = true; |
---|
198 | |
---|
199 | if(flashLight != NULL) |
---|
200 | { |
---|
201 | delete this->flashLight; |
---|
202 | flashLight = NULL; |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) |
---|
207 | { |
---|
208 | this->billboard[2]->setVisibiliy(false); |
---|
209 | this->billboard[3]->setVisibiliy(true); |
---|
210 | this->flashLight->setDiffuseColor(100,100,100); |
---|
211 | } |
---|
212 | else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) |
---|
213 | { |
---|
214 | this->billboard[1]->setVisibiliy(false); |
---|
215 | this->billboard[2]->setVisibiliy(true); |
---|
216 | this->flashLight->setDiffuseColor(0,0,0); |
---|
217 | } |
---|
218 | else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) |
---|
219 | { |
---|
220 | this->billboard[0]->setVisibiliy(false); |
---|
221 | this->billboard[1]->setVisibiliy(true); |
---|
222 | this->flashLight->setDiffuseColor(100,100,100); |
---|
223 | } |
---|
224 | |
---|
225 | if( this->bNewCoordinate) |
---|
226 | { |
---|
227 | float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX; |
---|
228 | float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX; |
---|
229 | this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
230 | this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
231 | this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
232 | this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
233 | this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX; |
---|
234 | |
---|
235 | this->bNewCoordinate = false; |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | void LighteningEffect::draw() const |
---|
240 | { |
---|
241 | } |
---|