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 | using namespace std; |
---|
26 | |
---|
27 | CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT); |
---|
28 | |
---|
29 | LighteningEffect::LighteningEffect(const TiXmlElement* root) |
---|
30 | { |
---|
31 | this->setClassID(CL_LIGHTENING_EFFECT, "LighteningEffect"); |
---|
32 | |
---|
33 | this->init(); |
---|
34 | |
---|
35 | if (root != NULL) |
---|
36 | this->loadParams(root); |
---|
37 | |
---|
38 | this->activate(); |
---|
39 | } |
---|
40 | |
---|
41 | LighteningEffect::~LighteningEffect() |
---|
42 | { |
---|
43 | this->deactivate(); |
---|
44 | } |
---|
45 | |
---|
46 | void LighteningEffect::loadParams(const TiXmlElement* root) |
---|
47 | { |
---|
48 | WeatherEffect::loadParams(root); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | bool LighteningEffect::init() |
---|
53 | { |
---|
54 | this->time = 0.0; |
---|
55 | this->flashFrequency = 0.6f; |
---|
56 | this->flashConstTime = 0.07f; |
---|
57 | |
---|
58 | //this->material = new Material(); |
---|
59 | //this->material->setDiffuseMap("maps/lightning_bolt.png"); |
---|
60 | //this->offset = Vector(-1440.00, 100.00, 280.00); |
---|
61 | |
---|
62 | // this->billboard->setAbsCoor(50, 0, 0); |
---|
63 | this->width = 20.0f; |
---|
64 | this->height = 5.0f; |
---|
65 | this->bNewCoordinate = false; |
---|
66 | |
---|
67 | this->seedX = 20.f; |
---|
68 | this->seedZ = 50.0f; |
---|
69 | this->seedTime = 4.0f; |
---|
70 | |
---|
71 | this->billboard = new Billboard(NULL); |
---|
72 | this->billboard->setTexture("maps/lightning_bolt.png"); |
---|
73 | this->billboard->setSize(this->width, this->height); |
---|
74 | this->billboard->setAbsCoor(50, 0, 0); |
---|
75 | this->billboard->setVisibiliy(false); |
---|
76 | //this->billboard->setAbsCoor(50, 0, 0); |
---|
77 | //this->billboard->setVisibiliy(true); |
---|
78 | |
---|
79 | /* |
---|
80 | this->soundSource = NULL; |
---|
81 | this->thunderBuffer = NULL; |
---|
82 | |
---|
83 | this->soundSource.setSourceNode(this); |
---|
84 | |
---|
85 | //load sound |
---|
86 | if (this->thunderBuffer != NULL) |
---|
87 | ResourceManager::getInstance()->unload(this->thunderBuffer); |
---|
88 | this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | bool LighteningEffect::activate() |
---|
93 | { |
---|
94 | PRINTF(0)( "Activating LighteningEffect\n" ); |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | bool LighteningEffect::deactivate() |
---|
100 | { |
---|
101 | PRINTF(0)("Deactivating LighteningEffect\n"); |
---|
102 | } |
---|
103 | |
---|
104 | void LighteningEffect::tick (float dt) |
---|
105 | { |
---|
106 | this->time += dt; |
---|
107 | |
---|
108 | if( this->time > this->flashFrequency) |
---|
109 | { |
---|
110 | this->billboard->setVisibiliy(true); |
---|
111 | this->time = 0.0f; |
---|
112 | //this->soundSource.play(this->thunderBuffer); |
---|
113 | } |
---|
114 | else if( this->billboard->isVisible() && this->time > this->flashConstTime) |
---|
115 | { |
---|
116 | this->billboard->setVisibiliy(false); |
---|
117 | this->time = 0.0f; |
---|
118 | this->bNewCoordinate = true; |
---|
119 | } |
---|
120 | |
---|
121 | if( this->bNewCoordinate) |
---|
122 | { |
---|
123 | //this->flashFrequency = this->seedTime * (float)rand()/(float)RAND_MAX + 0.1; |
---|
124 | //this->billboard>setAbsCoor( - 800.0f - this->seedX * (float)rand()/(float)RAND_MAX, 250.00, -200.0f + this->seedZ * (float)rand()/(float)RAND_MAX); |
---|
125 | this->bNewCoordinate = false; |
---|
126 | } |
---|
127 | } |
---|