// we get slower when not pressing any keys
if(dirsign == 0) {
- if(fabs(vx) < WALK_SPEED) {
+ if ((on_ground()) && (fabs(vx) < WALK_SPEED)) {
vx = 0;
ax = 0;
} else if(vx < 0) {
}
void
+Player::add_velocity(const Vector& velocity, const Vector& end_speed)
+{
+ if (end_speed.x > 0) physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
+ if (end_speed.x < 0) physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
+ if (end_speed.y > 0) physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
+ if (end_speed.y < 0) physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
+}
+
+void
Player::bounce(BadGuy& )
{
if(controller->hold(Controller::JUMP))
--- /dev/null
+// $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 distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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.
+
+#include <config.h>
+
+#include "wind.hpp"
+#include "video/drawing_context.hpp"
+#include "object/player.hpp"
+#include "object_factory.hpp"
+#include "random_generator.hpp"
+#include "sector.hpp"
+#include "particles.hpp"
+
+Wind::Wind(const lisp::Lisp& reader) : acceleration(100), elapsed_time(0)
+{
+ reader.get("x", bbox.p1.x);
+ reader.get("y", bbox.p1.y);
+ float w = 32, h = 32;
+ reader.get("width", w);
+ reader.get("height", h);
+ bbox.set_size(w, h);
+
+ float speed_x = 0, speed_y = 0;
+ reader.get("speed-x", speed_x);
+ reader.get("speed-y", speed_y);
+ speed = Vector(speed_x, speed_y);
+
+ reader.get("acceleration", acceleration);
+
+ set_group(COLGROUP_TOUCHABLE);
+}
+
+void
+Wind::update(float elapsed_time)
+{
+ this->elapsed_time = elapsed_time;
+ // 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));
+ }
+}
+
+void
+Wind::draw(DrawingContext& )
+{
+}
+
+HitResponse
+Wind::collision(GameObject& other, const CollisionHit& )
+{
+ Player* player = dynamic_cast<Player*> (&other);
+ if (player) {
+ if (!player->on_ground()) {
+ player->add_velocity(speed * acceleration * elapsed_time, speed);
+ }
+ }
+
+ return ABORT_MOVE;
+}
+
+IMPLEMENT_FACTORY(Wind, "wind");
--- /dev/null
+// $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 distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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.
+
+#ifndef SUPERTUX_WIND_H
+#define SUPERTUX_WIND_H
+
+#include <set>
+#include "moving_object.hpp"
+#include "math/rect.hpp"
+#include "sprite/sprite.hpp"
+
+class Player;
+
+/**
+ * Defines an area that will gently push Players in one direction
+ */
+class Wind : public MovingObject
+{
+public:
+ Wind(const lisp::Lisp& reader);
+
+ void update(float elapsed_time);
+ void draw(DrawingContext& context);
+ HitResponse collision(GameObject& other, const CollisionHit& hit);
+
+private:
+ Vector speed;
+ float acceleration;
+
+ float elapsed_time; /**< stores last elapsed_time gotten at update() */
+};
+
+#endif
+