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/globals.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),
40 reader.get("name", name);
41 reader.get("running", running);
42 reader.get("interval", interval);
44 log_warning << "Running a thunderstorm with non-positive time interval is a bad idea" << std::endl;
46 reader.get("layer", layer);
48 sound_manager->preload("sounds/explosion.wav");
49 sound_manager->preload("sounds/upgrade.wav");
52 running = false; // else start() is ignored
58 Thunderstorm::update(float )
61 if (time_to_thunder.check()) {
63 time_to_lightning.start(LIGHTNING_DELAY);
65 if (time_to_lightning.check()) {
67 time_to_thunder.start(interval);
72 Thunderstorm::draw(DrawingContext& context)
74 if (!flash_display_timer.started()) return;
77 context.push_transform();
78 context.set_translation(Vector(0, 0));
79 context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), Color(1, 1, 1, alpha), layer);
80 context.pop_transform();
85 Thunderstorm::expose(HSQUIRRELVM vm, SQInteger table_idx)
87 if (name == "") return;
88 Scripting::Thunderstorm* interface = new Scripting::Thunderstorm(this);
89 expose_object(vm, table_idx, interface, name, true);
93 Thunderstorm::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
95 if (name == "") return;
96 Scripting::unexpose_object(vm, table_idx, name);
100 Thunderstorm::start()
104 time_to_thunder.start(interval);
105 time_to_lightning.stop();
111 if (!running) return;
113 time_to_thunder.stop();
114 time_to_lightning.stop();
118 Thunderstorm::thunder()
120 sound_manager->play("sounds/explosion.wav");
124 Thunderstorm::lightning()
131 Thunderstorm::flash()
133 sound_manager->play("sounds/upgrade.wav");
134 sound_manager->play("sounds/explosion.wav");
135 flash_display_timer.start(FLASH_DISPLAY_TIME);
139 Thunderstorm::electrify()
141 Sector::current()->add_object(new Electrifier(75, 1421, 0.5));
142 Sector::current()->add_object(new Electrifier(76, 1422, 0.5));
145 IMPLEMENT_FACTORY(Thunderstorm, "thunderstorm");