3 // SuperTux - Thunderstorm Game Object
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "thunderstorm.hpp"
23 #include "scripting/squirrel_util.hpp"
24 #include "audio/sound_manager.hpp"
25 #include "video/drawing_context.hpp"
26 #include "object_factory.hpp"
27 #include "object/electrifier.hpp"
32 #include "resources.hpp"
34 #include "gettext.hpp"
35 #include "object/player.hpp"
36 #include "lisp/list_iterator.hpp"
40 const float LIGHTNING_DELAY = 2.0f;
41 const float FLASH_DISPLAY_TIME = 0.1f;
44 Thunderstorm::Thunderstorm(const lisp::Lisp& reader)
45 : running(true), interval(10.0f)
47 reader.get("name", name);
48 reader.get("running", running);
49 reader.get("interval", interval);
51 log_warning << "Running a thunderstorm with non-positive time interval is a bad idea" << std::endl;
54 sound_manager->preload("sounds/explosion.wav");
55 sound_manager->preload("sounds/upgrade.wav");
58 running = false; // else start() is ignored
64 Thunderstorm::update(float )
67 if (time_to_thunder.check()) {
69 time_to_lightning.start(LIGHTNING_DELAY);
71 if (time_to_lightning.check()) {
73 time_to_thunder.start(interval);
78 Thunderstorm::draw(DrawingContext& context)
80 if (!flash_display_timer.started()) return;
83 context.push_transform();
84 context.set_translation(Vector(0, 0));
85 context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), Color(1, 1, 1, alpha), LAYER_BACKGROUNDTILES-1);
86 context.pop_transform();
91 Thunderstorm::expose(HSQUIRRELVM vm, SQInteger table_idx)
93 if (name == "") return;
94 Scripting::Thunderstorm* interface = new Scripting::Thunderstorm(this);
95 expose_object(vm, table_idx, interface, name, true);
99 Thunderstorm::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
101 if (name == "") return;
102 Scripting::unexpose_object(vm, table_idx, name);
106 Thunderstorm::start()
110 time_to_thunder.start(interval);
111 time_to_lightning.stop();
117 if (!running) return;
119 time_to_thunder.stop();
120 time_to_lightning.stop();
124 Thunderstorm::thunder()
126 sound_manager->play("sounds/explosion.wav");
130 Thunderstorm::lightning()
137 Thunderstorm::flash()
139 sound_manager->play("sounds/upgrade.wav");
140 sound_manager->play("sounds/explosion.wav");
141 flash_display_timer.start(FLASH_DISPLAY_TIME);
145 Thunderstorm::electrify()
147 Sector::current()->add_object(new Electrifier(75, 1421, 0.5));
148 Sector::current()->add_object(new Electrifier(76, 1422, 0.5));
151 IMPLEMENT_FACTORY(Thunderstorm, "thunderstorm");