X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fplatform.cpp;h=b0b2a3b1c1bce0c23d44d778b89598f36cc6388e;hb=fe138b9ec292ca9679b43cf5c4555f0193bab25d;hp=69c6c0df2472dcd2947074bbd93544bff710ec4a;hpb=e3bb6e46812f108f093e9ad0751a945c34b18cd3;p=supertux.git diff --git a/src/object/platform.cpp b/src/object/platform.cpp index 69c6c0df2..b0b2a3b1c 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -1,73 +1,89 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// 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 "platform.h" -#include "video/drawing_context.h" -#include "resources.h" -#include "player.h" -#include "special/sprite_manager.h" -#include "lisp/lisp.h" -#include "lisp/writer.h" -#include "object_factory.h" +#include "platform.hpp" + +#include +#include "log.hpp" +#include "video/drawing_context.hpp" +#include "resources.hpp" +#include "player.hpp" +#include "path.hpp" +#include "path_walker.hpp" +#include "sprite/sprite_manager.hpp" +#include "lisp/lisp.hpp" +#include "object_factory.hpp" Platform::Platform(const lisp::Lisp& reader) { - sprite = sprite_manager->create("flying_platform"); - movement = Vector(0, 1); - reader.get("x", bbox.p1.x); - reader.get("y", bbox.p1.y); - bbox.set_size(sprite->get_width(), sprite->get_height()); + std::string sprite_name; + reader.get("sprite", sprite_name); + if(sprite_name == "") + throw std::runtime_error("No sprite specified in platform object"); + sprite.reset(sprite_manager->create(sprite_name)); - flags |= FLAG_SOLID; + const lisp::Lisp* pathLisp = reader.get_lisp("path"); + if(pathLisp == NULL) + throw std::runtime_error("No path specified for platform"); + path.reset(new Path()); + path->read(*pathLisp); + walker.reset(new PathWalker(path.get())); - state = 0; + bbox.p1 = path->get_base(); + bbox.set_size(sprite->get_width(), sprite->get_height()); + + set_group(COLGROUP_STATIC); + flags |= FLAG_SOLID; } Platform::~Platform() { - delete sprite; } +//TODO: Squish Tux when standing between platform and solid tile/object +// Improve collision handling +// Move all MovingObjects lying on the platform instead of only the player HitResponse -Platform::collision(GameObject& , const CollisionHit& ) +Platform::collision(GameObject& other, const CollisionHit& hit) { -#if 0 - if(typeid(object) == typeid(Player)) { - Player* player = (Player*) &object; - //player->movement += movement; + if (typeid(other) == typeid(Player)) { + if (hit.normal.y >= 0.9) { + //Tux is standing on the platform + //Player* player = (Player*) &other; + //player->add_velocity(speed * 1.5); + return PASS_MOVEMENT; + } + } + if(other.get_flags() & FLAG_SOLID) { + //Collision with a solid tile + return ABORT_MOVE; } -#endif return FORCE_MOVE; } void -Platform::action(float ) +Platform::update(float elapsed_time) { - // just some test code... - if(state == 0) { - movement = Vector(0, 1); - if(bbox.p1.y > 250) - state = 1; - } - if(state == 1) { - movement = Vector(0, -1); - if(bbox.p1.y < 50) - state = 2; - } - if(state == 2) { - movement = Vector(1, 0); - if(bbox.p1.x > 800) - state = 3; - } - if(state == 3) { - movement = Vector(-1, 0); - if(bbox.p1.x < 400) - state = 4; - } - if(state == 4) { - movement = Vector(-1, 1); - if(bbox.p1.x < 0) - state = 0; - } + movement = walker->advance(elapsed_time); + speed = movement / elapsed_time; } void @@ -76,4 +92,4 @@ Platform::draw(DrawingContext& context) sprite->draw(context, get_pos(), LAYER_OBJECTS); } -IMPLEMENT_FACTORY(Platform, "flying_platform"); +IMPLEMENT_FACTORY(Platform, "platform");