-// $Id$
-//
// SuperTux - Wind
// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <config.h>
+#include "object/wind.hpp"
-#include "wind.hpp"
-#include "video/drawing_context.hpp"
+#include "math/random_generator.hpp"
+#include "object/particles.hpp"
#include "object/player.hpp"
-#include "object_factory.hpp"
-#include "random_generator.hpp"
-#include "sector.hpp"
-#include "particles.hpp"
+#include "scripting/squirrel_util.hpp"
+#include "scripting/wind.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
+#include "util/reader.hpp"
+#include "video/drawing_context.hpp"
-Wind::Wind(const lisp::Lisp& reader) : acceleration(100), elapsed_time(0)
+Wind::Wind(const Reader& reader) :
+ blowing(true),
+ speed(),
+ acceleration(100),
+ elapsed_time(0)
{
+ reader.get("name", name);
reader.get("x", bbox.p1.x);
reader.get("y", bbox.p1.y);
float w = 32, h = 32;
reader.get("height", h);
bbox.set_size(w, h);
+ reader.get("blowing", blowing);
+
float speed_x = 0, speed_y = 0;
reader.get("speed-x", speed_x);
reader.get("speed-y", speed_y);
}
void
-Wind::update(float elapsed_time)
+Wind::update(float elapsed_time_)
{
- this->elapsed_time = elapsed_time;
+ this->elapsed_time = elapsed_time_;
+
+ if (!blowing) return;
+
// TODO: nicer, configurable particles for wind?
- if (systemRandom.rand(0, 100) < 20) {
+ if (graphicsRandom.rand(0, 100) < 20) {
// emit a particle
- Vector ppos = Vector(systemRandom.randf(bbox.p1.x+8, bbox.p2.x-8), systemRandom.randf(bbox.p1.y+8, bbox.p2.y-8));
- Vector pspeed = Vector(speed.x, -speed.y);
- Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4, .4, .4), 3, .1, LAYER_BACKGROUNDTILES+1));
+ Vector ppos = Vector(graphicsRandom.randf(bbox.p1.x+8, bbox.p2.x-8), graphicsRandom.randf(bbox.p1.y+8, bbox.p2.y-8));
+ Vector pspeed = Vector(speed.x, speed.y);
+ Sector::current()->add_object(std::make_shared<Particles>(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f,
+ LAYER_BACKGROUNDTILES+1));
}
}
HitResponse
Wind::collision(GameObject& other, const CollisionHit& )
{
+ if (!blowing) return ABORT_MOVE;
+
Player* player = dynamic_cast<Player*> (&other);
if (player) {
if (!player->on_ground()) {
return ABORT_MOVE;
}
-IMPLEMENT_FACTORY(Wind, "wind");
+void
+Wind::expose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+ if (name == "")
+ return;
+
+ scripting::Wind* _this = new scripting::Wind(this);
+ expose_object(vm, table_idx, _this, name, true);
+}
+
+void
+Wind::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+ if (name == "")
+ return;
+
+ scripting::unexpose_object(vm, table_idx, name);
+}
+
+void
+Wind::start()
+{
+ blowing = true;
+}
+
+void
+Wind::stop()
+{
+ blowing = false;
+}
+
+/* EOF */