- fix a bunch of msvc warnings (mostly assigning double constants to float variables)
[supertux.git] / src / object / wind.cpp
index 60669aa..638ab69 100644 (file)
 #include "random_generator.hpp"
 #include "sector.hpp"
 #include "particles.hpp"
+#include "scripting/wind.hpp"
+#include "scripting/squirrel_util.hpp"
 
-Wind::Wind(const lisp::Lisp& reader) : acceleration(100), elapsed_time(0)
+Wind::Wind(const lisp::Lisp& reader)
+  : blowing(true), 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;
@@ -36,6 +40,8 @@ Wind::Wind(const lisp::Lisp& reader) : acceleration(100), elapsed_time(0)
   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);
@@ -50,12 +56,15 @@ void
 Wind::update(float elapsed_time)
 {
   this->elapsed_time = elapsed_time;
+
+  if (!blowing) return;
+
   // TODO: nicer, configurable particles for wind?
   if (systemRandom.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));
+    Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f, LAYER_BACKGROUNDTILES+1));
   }
 }
 
@@ -67,6 +76,8 @@ Wind::draw(DrawingContext& )
 HitResponse
 Wind::collision(GameObject& other, const CollisionHit& )
 {
+  if (!blowing) return ABORT_MOVE;
+
   Player* player = dynamic_cast<Player*> (&other);
   if (player) {
     if (!player->on_ground()) {
@@ -77,4 +88,35 @@ Wind::collision(GameObject& other, const CollisionHit& )
   return ABORT_MOVE;
 }
 
+void
+Wind::expose(HSQUIRRELVM vm, SQInteger table_idx)
+{
+  if (name == "")
+    return;
+
+  Scripting::Wind* interface = new Scripting::Wind(this);
+  expose_object(vm, table_idx, interface, 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;
+}
+
 IMPLEMENT_FACTORY(Wind, "wind");