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/wind.hpp"
19 #include "math/random_generator.hpp"
20 #include "object/particles.hpp"
21 #include "object/player.hpp"
22 #include "scripting/squirrel_util.hpp"
23 #include "scripting/wind.hpp"
24 #include "supertux/object_factory.hpp"
25 #include "supertux/sector.hpp"
26 #include "util/reader.hpp"
27 #include "video/drawing_context.hpp"
29 Wind::Wind(const Reader& reader) :
35 reader.get("name", name);
36 reader.get("x", bbox.p1.x);
37 reader.get("y", bbox.p1.y);
39 reader.get("width", w);
40 reader.get("height", h);
43 reader.get("blowing", blowing);
45 float speed_x = 0, speed_y = 0;
46 reader.get("speed-x", speed_x);
47 reader.get("speed-y", speed_y);
48 speed = Vector(speed_x, speed_y);
50 reader.get("acceleration", acceleration);
52 set_group(COLGROUP_TOUCHABLE);
56 Wind::update(float elapsed_time)
58 this->elapsed_time = elapsed_time;
62 // TODO: nicer, configurable particles for wind?
63 if (systemRandom.rand(0, 100) < 20) {
65 Vector ppos = Vector(systemRandom.randf(bbox.p1.x+8, bbox.p2.x-8), systemRandom.randf(bbox.p1.y+8, bbox.p2.y-8));
66 Vector pspeed = Vector(speed.x, speed.y);
67 Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f,
68 LAYER_BACKGROUNDTILES+1));
73 Wind::draw(DrawingContext& )
78 Wind::collision(GameObject& other, const CollisionHit& )
80 if (!blowing) return ABORT_MOVE;
82 Player* player = dynamic_cast<Player*> (&other);
84 if (!player->on_ground()) {
85 player->add_velocity(speed * acceleration * elapsed_time, speed);
93 Wind::expose(HSQUIRRELVM vm, SQInteger table_idx)
98 Scripting::Wind* interface = new Scripting::Wind(this);
99 expose_object(vm, table_idx, interface, name, true);
103 Wind::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
108 Scripting::unexpose_object(vm, table_idx, name);
123 IMPLEMENT_FACTORY(Wind, "wind");