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->flashConstTime = 0.5f; |
---|
74 | this->flashRisingTime = 0.1f; |
---|
75 | |
---|
76 | this->width = 400.0f; |
---|
77 | this->height = 100.0f; |
---|
78 | this->seedWidth = 50; |
---|
79 | this->seedHeight = 50; |
---|
80 | this->bNewCoordinate = false; |
---|
81 | |
---|
82 | this->seedX = 500.f; |
---|
83 | this->seedZ = 1000.0f; |
---|
84 | this->seedTime = 4.0f; |
---|
85 | |
---|
86 | this->billboard[0] = new Billboard(NULL); |
---|
87 | this->billboard[0]->setTexture("maps/lightning_bolt1.png"); |
---|
88 | this->billboard[0]->setSize(this->width, this->height); |
---|
89 | this->billboard[0]->setAbsCoor(3000,850,0); |
---|
90 | this->billboard[0]->setVisibiliy(false); |
---|
91 | |
---|
92 | this->billboard[1] = new Billboard(NULL); |
---|
93 | this->billboard[1]->setTexture("maps/lightning_bolt2.png"); |
---|
94 | this->billboard[1]->setSize(this->width, this->height); |
---|
95 | this->billboard[1]->setAbsCoor(3000,850,0); |
---|
96 | this->billboard[1]->setVisibiliy(false); |
---|
97 | |
---|
98 | this->billboard[2] = new Billboard(NULL); |
---|
99 | this->billboard[2]->setTexture("maps/lightning_bolt3.png"); |
---|
100 | this->billboard[2]->setSize(this->width, this->height); |
---|
101 | this->billboard[2]->setAbsCoor(3000,850,0); |
---|
102 | this->billboard[2]->setVisibiliy(false); |
---|
103 | |
---|
104 | this->billboard[3] = new Billboard(NULL); |
---|
105 | this->billboard[3]->setTexture("maps/lightning_bolt4.png"); |
---|
106 | this->billboard[3]->setSize(this->width, this->height); |
---|
107 | this->billboard[3]->setAbsCoor(0.0f, 50.0f, 0.0f); |
---|
108 | this->billboard[3]->setVisibiliy(false); |
---|
109 | /* |
---|
110 | this->soundSource = NULL; |
---|
111 | this->thunderBuffer = NULL; |
---|
112 | |
---|
113 | this->soundSource.setSourceNode(this); |
---|
114 | |
---|
115 | //load sound |
---|
116 | if (this->thunderBuffer != NULL) |
---|
117 | ResourceManager::getInstance()->unload(this->thunderBuffer); |
---|
118 | this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ |
---|
119 | } |
---|
120 | |
---|
121 | void LighteningEffect::coord(float x, float y, float z) |
---|
122 | { |
---|
123 | this->billboard[0]->setAbsCoor(x, y, z); |
---|
124 | this->billboard[1]->setAbsCoor(x, y, z); |
---|
125 | this->billboard[2]->setAbsCoor(x, y, z); |
---|
126 | this->billboard[3]->setAbsCoor(x, y, z); |
---|
127 | this->mainPosX = x; |
---|
128 | this->mainPosY = y; |
---|
129 | this->mainPosZ = z; |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight) |
---|
134 | { |
---|
135 | this->width = width; |
---|
136 | this->height = height; |
---|
137 | this->seedWidth = seedWidth; |
---|
138 | this->seedHeight = seedHeight; |
---|
139 | this->billboard[0]->setSize(this->width, this->height); |
---|
140 | this->billboard[1]->setSize(this->width, this->height); |
---|
141 | this->billboard[2]->setSize(this->width, this->height); |
---|
142 | this->billboard[3]->setSize(this->width, this->height); |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | bool LighteningEffect::activate() |
---|
147 | { |
---|
148 | PRINTF(0)( "Activating LighteningEffect\n" ); |
---|
149 | this->time = 0; |
---|
150 | lighteningActivate = true; |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | bool LighteningEffect::deactivate() |
---|
155 | { |
---|
156 | PRINTF(0)("Deactivating LighteningEffect\n"); |
---|
157 | this->billboard[0]->setVisibiliy(false); |
---|
158 | this->billboard[1]->setVisibiliy(false); |
---|
159 | this->billboard[2]->setVisibiliy(false); |
---|
160 | this->billboard[3]->setVisibiliy(false); |
---|
161 | lighteningActivate = false; |
---|
162 | } |
---|
163 | |
---|
164 | void LighteningEffect::tick (float dt) |
---|
165 | { |
---|
166 | if(!lighteningActivate) |
---|
167 | return; |
---|
168 | |
---|
169 | this->time += dt; |
---|
170 | |
---|
171 | /*if( flashLight != NULL) |
---|
172 | { |
---|
173 | if((int)(100*time)%2) |
---|
174 | this->flashLight->setDiffuseColor(0,0,0); |
---|
175 | else |
---|
176 | this->flashLight->setDiffuseColor(100,100,100); |
---|
177 | |
---|
178 | //PRINTF(0)("100*time: %f %i\n", 100*time, (int)(100*time)); |
---|
179 | }*/ |
---|
180 | |
---|
181 | if( this->time > this->flashFrequency) |
---|
182 | { |
---|
183 | this->billboard[0]->setVisibiliy(true); |
---|
184 | this->time = 0.0f; |
---|
185 | |
---|
186 | this->flashLight = new Light(); |
---|
187 | this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z); |
---|
188 | this->flashLight->setDiffuseColor(100,100,100); |
---|
189 | |
---|
190 | //this->soundSource.play(this->thunderBuffer); |
---|
191 | } |
---|
192 | else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) |
---|
193 | { |
---|
194 | this->billboard[3]->setVisibiliy(false); |
---|
195 | this->time = 0.0f; |
---|
196 | this->bNewCoordinate = true; |
---|
197 | |
---|
198 | if(flashLight != NULL) |
---|
199 | { |
---|
200 | delete this->flashLight; |
---|
201 | flashLight = NULL; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) |
---|
206 | { |
---|
207 | this->billboard[2]->setVisibiliy(false); |
---|
208 | this->billboard[3]->setVisibiliy(true); |
---|
209 | this->flashLight->setDiffuseColor(100,100,100); |
---|
210 | } |
---|
211 | else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) |
---|
212 | { |
---|
213 | this->billboard[1]->setVisibiliy(false); |
---|
214 | this->billboard[2]->setVisibiliy(true); |
---|
215 | this->flashLight->setDiffuseColor(0,0,0); |
---|
216 | } |
---|
217 | else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) |
---|
218 | { |
---|
219 | this->billboard[0]->setVisibiliy(false); |
---|
220 | this->billboard[1]->setVisibiliy(true); |
---|
221 | this->flashLight->setDiffuseColor(100,100,100); |
---|
222 | } |
---|
223 | |
---|
224 | if( this->bNewCoordinate) |
---|
225 | { |
---|
226 | float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX; |
---|
227 | float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX; |
---|
228 | this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
229 | this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
230 | this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
231 | this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ); |
---|
232 | this->bNewCoordinate = false; |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | void LighteningEffect::draw() const |
---|
237 | { |
---|
238 | } |
---|