// $Id$
-//
+//
// SuperTux
-// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+// Copyright (C) 2005 Marek Moeckel <wansti@gmx.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms 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 "platform.h"
-#include "video/drawing_context.h"
-#include "resources.h"
-#include "player.h"
-#include "sprite/sprite_manager.h"
-#include "lisp/lisp.h"
-#include "lisp/writer.h"
-#include "object_factory.h"
+#include "platform.hpp"
+
+#include <stdexcept>
+#include "msg.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::update(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
sprite->draw(context, get_pos(), LAYER_OBJECTS);
}
-IMPLEMENT_FACTORY(Platform, "flying_platform");
+IMPLEMENT_FACTORY(Platform, "platform");