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 | } |
---|
60 | |
---|
61 | |
---|
62 | bool LighteningEffect::init() |
---|
63 | { |
---|
64 | lighteningActivate = false; |
---|
65 | |
---|
66 | this->time = 0.0; |
---|
67 | this->flashFrequency = 0.6f; |
---|
68 | this->flashConstTime = 0.07f; |
---|
69 | |
---|
70 | this->width = 40.0f; |
---|
71 | this->height = 10.0f; |
---|
72 | this->bNewCoordinate = false; |
---|
73 | |
---|
74 | this->seedX = 10.f; |
---|
75 | this->seedZ = 10.0f; |
---|
76 | this->seedTime = 4.0f; |
---|
77 | |
---|
78 | this->billboard = new Billboard(NULL); |
---|
79 | this->billboard->setTexture("maps/lightning_bolt.png"); |
---|
80 | this->billboard->setSize(this->width, this->height); |
---|
81 | this->billboard->setAbsCoor(0.0f, 50.0f, 0.0f); |
---|
82 | this->billboard->setVisibiliy(false); |
---|
83 | |
---|
84 | /* |
---|
85 | this->soundSource = NULL; |
---|
86 | this->thunderBuffer = NULL; |
---|
87 | |
---|
88 | this->soundSource.setSourceNode(this); |
---|
89 | |
---|
90 | //load sound |
---|
91 | if (this->thunderBuffer != NULL) |
---|
92 | ResourceManager::getInstance()->unload(this->thunderBuffer); |
---|
93 | this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ |
---|
94 | } |
---|
95 | |
---|
96 | void LighteningEffect::coord(float x, float y, float z) |
---|
97 | { |
---|
98 | this->billboard->setAbsCoor(x, y, z); |
---|
99 | this->mainPosX = x; |
---|
100 | this->mainPosY = y; |
---|
101 | this->mainPosZ = z; |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | bool LighteningEffect::activate() |
---|
106 | { |
---|
107 | PRINTF(0)( "Activating LighteningEffect\n" ); |
---|
108 | this->billboard->setVisibiliy(true); |
---|
109 | lighteningActivate = true; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | bool LighteningEffect::deactivate() |
---|
114 | { |
---|
115 | PRINTF(0)("Deactivating LighteningEffect\n"); |
---|
116 | this->billboard->setVisibiliy(false); |
---|
117 | lighteningActivate = false; |
---|
118 | } |
---|
119 | |
---|
120 | void LighteningEffect::tick (float dt) |
---|
121 | { |
---|
122 | if(!lighteningActivate) |
---|
123 | return; |
---|
124 | |
---|
125 | this->time += dt; |
---|
126 | |
---|
127 | if( this->time > this->flashFrequency) |
---|
128 | { |
---|
129 | this->billboard->setVisibiliy(true); |
---|
130 | this->time = 0.0f; |
---|
131 | //this->soundSource.play(this->thunderBuffer); |
---|
132 | } |
---|
133 | else if( this->billboard->isVisible() && this->time > this->flashConstTime) |
---|
134 | { |
---|
135 | this->billboard->setVisibiliy(false); |
---|
136 | this->time = 0.0f; |
---|
137 | this->bNewCoordinate = true; |
---|
138 | } |
---|
139 | |
---|
140 | if( this->bNewCoordinate) |
---|
141 | { |
---|
142 | this->flashFrequency = this->seedTime * (float)rand()/(float)RAND_MAX + 0.1; |
---|
143 | this->billboard->setAbsCoor(this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX, this->mainPosY, this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX); |
---|
144 | this->bNewCoordinate = false; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | void LighteningEffect::draw() const |
---|
149 | { |
---|
150 | /*if(!this->billboard->isVisible()) |
---|
151 | return; |
---|
152 | |
---|
153 | LightManager* lightMan = LightManager::getInstance(); |
---|
154 | |
---|
155 | (new Light())->setAbsCoor(this->billboard->getAbsCoor().x, this->billboard->getAbsCoor().y, this->billboard->getAbsCoor().z); |
---|
156 | (new Light())->setDiffuseColor(1,1,1); |
---|
157 | LightManager::getInstance()->draw(); |
---|
158 | |
---|
159 | delete lightMan;*/ |
---|
160 | } |
---|