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.
23 #include "video/drawing_context.hpp"
24 #include "object/player.hpp"
25 #include "object_factory.hpp"
26 #include "random_generator.hpp"
28 #include "particles.hpp"
30 Wind::Wind(const lisp::Lisp& reader) : acceleration(100), elapsed_time(0)
32 reader.get("x", bbox.p1.x);
33 reader.get("y", bbox.p1.y);
35 reader.get("width", w);
36 reader.get("height", h);
39 float speed_x = 0, speed_y = 0;
40 reader.get("speed-x", speed_x);
41 reader.get("speed-y", speed_y);
42 speed = Vector(speed_x, speed_y);
44 reader.get("acceleration", acceleration);
46 set_group(COLGROUP_TOUCHABLE);
50 Wind::update(float elapsed_time)
52 this->elapsed_time = elapsed_time;
53 // TODO: nicer, configurable particles for wind?
54 if (systemRandom.rand(0, 100) < 20) {
56 Vector ppos = Vector(systemRandom.randf(bbox.p1.x+8, bbox.p2.x-8), systemRandom.randf(bbox.p1.y+8, bbox.p2.y-8));
57 Vector pspeed = Vector(speed.x, -speed.y);
58 Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4, .4, .4), 3, .1, LAYER_BACKGROUNDTILES+1));
63 Wind::draw(DrawingContext& )
68 Wind::collision(GameObject& other, const CollisionHit& )
70 Player* player = dynamic_cast<Player*> (&other);
72 if (!player->on_ground()) {
73 player->add_velocity(speed * acceleration * elapsed_time, speed);
80 IMPLEMENT_FACTORY(Wind, "wind");