00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00063 if (graphicsRandom.rand(0, 100) < 20) {
00064
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