+// $Id$
+//
+// SuperTux
+// 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
+// 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 "platform.h"
-#include "video/drawing_context.h"
-#include "resources.h"
-#include "player.h"
-#include "special/sprite_manager.h"
-#include "utils/lispreader.h"
+#include "platform.hpp"
-Platform::Platform(LispReader& reader)
+#include <iostream>
+#include "video/drawing_context.hpp"
+#include "resources.hpp"
+#include "player.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.read_float("x", bbox.p1.x);
- reader.read_float("y", bbox.p1.y);
+ std::string use_path;
+ std::string type;
+
+ reader.get("x", bbox.p1.x);
+ reader.get("y", bbox.p1.y);
+ reader.get("type", type);
+ reader.get("use_path", use_path);
+ sprite = sprite_manager->create("images/objects/flying_platform/platform.sprite");
+ sprite->set_action(type);
bbox.set_size(sprite->get_width(), sprite->get_height());
flags |= FLAG_SOLID;
- state = 0;
+ path = Path::GetByName(use_path);
+ if (path == NULL) {
+ std::cerr << "Warning: Path for moving platform not found! Make sure that the name is spelled correctly,\nand that the path is initialized before the platform in the level file!\n";
+ }
+
+ path_offset = bbox.p1;
}
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& object, const CollisionHit& hit)
+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)) {
+ Player* player = (Player*) &other;
+ if ((hit.normal.x == 0) && (hit.normal.y == 1)) {
+ //Tux is standing on the platform
+ player->movement += path->GetLastMovement();
+ }
+ }
+ if(other.get_flags() & FLAG_SOLID) {
+ //Collision with a solid tile
+ //does nothing, because the movement vector isn't used at the moment
+ return ABORT_MOVE;
}
-#endif
return FORCE_MOVE;
}
void
-Platform::action(float elapsed_time)
+Platform::update(float )
{
- // 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;
- }
+ set_pos(path->GetPosition() + path_offset);
}
void
{
sprite->draw(context, get_pos(), LAYER_OBJECTS);
}
+
+IMPLEMENT_FACTORY(Platform, "platform");