From: Christoph Sommer Date: Thu, 8 Jun 2006 01:22:13 +0000 (+0000) Subject: New Wind object: gently pushes players in one direction / X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7d731b516a5181ce4f39b0339c7bce1cdc7c0baa;p=supertux.git New Wind object: gently pushes players in one direction / ATTN: changes were made to the handle_input section of player.cpp, need testing! SVN-Revision: 3640 --- diff --git a/data/images/engine/editor/wind.png b/data/images/engine/editor/wind.png new file mode 100644 index 000000000..defb4c438 Binary files /dev/null and b/data/images/engine/editor/wind.png differ diff --git a/data/levels/test/wind.stl b/data/levels/test/wind.stl new file mode 100644 index 000000000..6e8ff3ba6 --- /dev/null +++ b/data/levels/test/wind.stl @@ -0,0 +1,91 @@ +(supertux-level + (version 2) + (name (_ "Flying Platform Test")) + (author "Marek") + (sector + (name "main") + (background + (x 0) + (y 0) + (speed 0.5) + (image "images/background/arctis.jpg") + ) + (tilemap + (z-pos -100) + (solid #f) + (speed 1) + (width 30) + (height 30) + (tiles 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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713 0 0 0 0 0 1349 0 0 1349 0 0 0 0 0 0 0 0 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 79 0 0 0 0 0 1731 1732 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1355 0 0 0 0 1731 1732 79 0 0 0 0 0 1733 1734 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1356 0 0 0 0 1733 1734 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) + ) + (tilemap + (z-pos 0) + (solid #t) + (speed 1) + (width 30) + (height 30) + (tiles 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 47 27 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 29 47 61 61 0 0 0 0 211 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 211 61 61 0 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 212 61 61 0 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 212 61 61 0 0 0 0 212 0 0 0 47 27 28 28 28 28 28 28 28 28 28 28 28 28 29 47 0 0 0 212 61 61 0 0 0 0 212 0 0 0 211 0 0 0 0 0 0 0 0 0 0 0 0 0 0 211 0 0 0 212 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 212 0 0 0 212 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 213 0 0 0 213 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 53 55 55 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 54 56 56 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 212 0 0 0 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 213 0 0 0 213 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 48 48 48 48 48 0 0 0 0 0 0 57 58 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 59 60 0 0 0 61 61 0 1000 1003 0 0 0 0 0 0 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x 783) + (y 768) + ) + (wind + (speed-x -600) + (speed-y 0) + (acceleration 3) + (width 64) + (height 32) + (x 768) + (y 688) + ) + (wind + (speed-x 0) + (speed-y 600) + (acceleration 600) + (width 116) + (height 488) + (x 183.3066) + (y 338.4975) + ) + (wind + (speed-x 600) + (speed-y 0) + (acceleration 600) + (width 615) + (height 116) + (x 181.3066) + (y 342.4975) + ) + (wind + (speed-x -300) + (speed-y 0) + (acceleration 10) + (width 160) + (height 224) + (x 416) + (y 608) + ) + ) +) diff --git a/src/object/player.cpp b/src/object/player.cpp index 13b41012b..5fb722e58 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -296,7 +296,7 @@ Player::handle_horizontal_input() // 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) { @@ -1004,6 +1004,15 @@ Player::add_velocity(const Vector& velocity) } 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)) diff --git a/src/object/player.hpp b/src/object/player.hpp index 5a0a8b944..c212822c5 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -167,6 +167,11 @@ public: */ void add_velocity(const Vector& velocity); + /** + * Adds velocity to the player until given end speed is reached + */ + void add_velocity(const Vector& velocity, const Vector& end_speed); + void bounce(BadGuy& badguy); bool is_dead() const diff --git a/src/object/wind.cpp b/src/object/wind.cpp new file mode 100644 index 000000000..a1265c534 --- /dev/null +++ b/src/object/wind.cpp @@ -0,0 +1,80 @@ +// $Id$ +// +// SuperTux - Wind +// Copyright (C) 2006 Christoph Sommer +// +// 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 + +#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 (&other); + if (player) { + if (!player->on_ground()) { + player->add_velocity(speed * acceleration * elapsed_time, speed); + } + } + + return ABORT_MOVE; +} + +IMPLEMENT_FACTORY(Wind, "wind"); diff --git a/src/object/wind.hpp b/src/object/wind.hpp new file mode 100644 index 000000000..39e5fd594 --- /dev/null +++ b/src/object/wind.hpp @@ -0,0 +1,50 @@ +// $Id$ +// +// SuperTux - Wind +// Copyright (C) 2006 Christoph Sommer +// +// 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 +#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 +