src/object/wind.cpp

Go to the documentation of this file.
00001 //  SuperTux - Wind
00002 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "object/wind.hpp"
00018 
00019 #include "math/random_generator.hpp"
00020 #include "object/particles.hpp"
00021 #include "object/player.hpp"
00022 #include "scripting/squirrel_util.hpp"
00023 #include "scripting/wind.hpp"
00024 #include "supertux/object_factory.hpp"
00025 #include "supertux/sector.hpp"
00026 #include "util/reader.hpp"
00027 #include "video/drawing_context.hpp"
00028 
00029 Wind::Wind(const Reader& reader) :
00030   blowing(true), 
00031   speed(),
00032   acceleration(100), 
00033   elapsed_time(0)
00034 {
00035   reader.get("name", name);
00036   reader.get("x", bbox.p1.x);
00037   reader.get("y", bbox.p1.y);
00038   float w = 32, h = 32;
00039   reader.get("width", w);
00040   reader.get("height", h);
00041   bbox.set_size(w, h);
00042 
00043   reader.get("blowing", blowing);
00044 
00045   float speed_x = 0, speed_y = 0;
00046   reader.get("speed-x", speed_x);
00047   reader.get("speed-y", speed_y);
00048   speed = Vector(speed_x, speed_y);
00049 
00050   reader.get("acceleration", acceleration);
00051 
00052   set_group(COLGROUP_TOUCHABLE);
00053 }
00054 
00055 void
00056 Wind::update(float elapsed_time)
00057 {
00058   this->elapsed_time = elapsed_time;
00059 
00060   if (!blowing) return;
00061 
00062   // TODO: nicer, configurable particles for wind?
00063   if (graphicsRandom.rand(0, 100) < 20) {
00064     // emit a particle
00065     Vector ppos = Vector(graphicsRandom.randf(bbox.p1.x+8, bbox.p2.x-8), graphicsRandom.randf(bbox.p1.y+8, bbox.p2.y-8));
00066     Vector pspeed = Vector(speed.x, speed.y);
00067     Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f,
00068                                                 LAYER_BACKGROUNDTILES+1));
00069   }
00070 }
00071 
00072 void
00073 Wind::draw(DrawingContext& )
00074 {
00075 }
00076 
00077 HitResponse
00078 Wind::collision(GameObject& other, const CollisionHit& )
00079 {
00080   if (!blowing) return ABORT_MOVE;
00081 
00082   Player* player = dynamic_cast<Player*> (&other);
00083   if (player) {
00084     if (!player->on_ground()) {
00085       player->add_velocity(speed * acceleration * elapsed_time, speed);
00086     }
00087   }
00088 
00089   return ABORT_MOVE;
00090 }
00091 
00092 void
00093 Wind::expose(HSQUIRRELVM vm, SQInteger table_idx)
00094 {
00095   if (name == "")
00096     return;
00097 
00098   scripting::Wind* _this = new scripting::Wind(this);
00099   expose_object(vm, table_idx, _this, name, true);
00100 }
00101 
00102 void
00103 Wind::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
00104 {
00105   if (name == "")
00106     return;
00107 
00108   scripting::unexpose_object(vm, table_idx, name);
00109 }
00110 
00111 void
00112 Wind::start()
00113 {
00114   blowing = true;
00115 }
00116 
00117 void
00118 Wind::stop()
00119 {
00120   blowing = false;
00121 }
00122 
00123 /* EOF */

Generated on Mon Jun 9 03:38:20 2014 for SuperTux by  doxygen 1.5.1