1 // SuperTux - Thunderstorm Game Object
2 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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.
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.
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/>.
17 #include "object/thunderstorm.hpp"
19 #include "audio/sound_manager.hpp"
20 #include "object/electrifier.hpp"
21 #include "scripting/squirrel_util.hpp"
22 #include "supertux/main.hpp"
23 #include "supertux/object_factory.hpp"
24 #include "supertux/sector.hpp"
25 #include "util/reader.hpp"
28 const float LIGHTNING_DELAY = 2.0f;
29 const float FLASH_DISPLAY_TIME = 0.1f;
32 Thunderstorm::Thunderstorm(const Reader& reader) :
35 layer(LAYER_BACKGROUNDTILES-1)
37 reader.get("name", name);
38 reader.get("running", running);
39 reader.get("interval", interval);
41 log_warning << "Running a thunderstorm with non-positive time interval is a bad idea" << std::endl;
43 reader.get("layer", layer);
45 sound_manager->preload("sounds/explosion.wav");
46 sound_manager->preload("sounds/upgrade.wav");
49 running = false; // else start() is ignored
55 Thunderstorm::update(float )
58 if (time_to_thunder.check()) {
60 time_to_lightning.start(LIGHTNING_DELAY);
62 if (time_to_lightning.check()) {
64 time_to_thunder.start(interval);
69 Thunderstorm::draw(DrawingContext& context)
71 if (!flash_display_timer.started()) return;
74 context.push_transform();
75 context.set_translation(Vector(0, 0));
76 context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), Color(1, 1, 1, alpha), layer);
77 context.pop_transform();
82 Thunderstorm::expose(HSQUIRRELVM vm, SQInteger table_idx)
84 if (name == "") return;
85 Scripting::Thunderstorm* interface = new Scripting::Thunderstorm(this);
86 expose_object(vm, table_idx, interface, name, true);
90 Thunderstorm::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
92 if (name == "") return;
93 Scripting::unexpose_object(vm, table_idx, name);
101 time_to_thunder.start(interval);
102 time_to_lightning.stop();
108 if (!running) return;
110 time_to_thunder.stop();
111 time_to_lightning.stop();
115 Thunderstorm::thunder()
117 sound_manager->play("sounds/explosion.wav");
121 Thunderstorm::lightning()
128 Thunderstorm::flash()
130 sound_manager->play("sounds/upgrade.wav");
131 sound_manager->play("sounds/explosion.wav");
132 flash_display_timer.start(FLASH_DISPLAY_TIME);
136 Thunderstorm::electrify()
138 Sector::current()->add_object(new Electrifier(75, 1421, 0.5));
139 Sector::current()->add_object(new Electrifier(76, 1422, 0.5));
142 IMPLEMENT_FACTORY(Thunderstorm, "thunderstorm");