4 // Copyright (C) 2005 Marek Moeckel <wansti@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "platform.hpp"
24 #include "video/drawing_context.hpp"
25 #include "resources.hpp"
27 #include "sprite/sprite_manager.hpp"
28 #include "lisp/lisp.hpp"
29 #include "object_factory.hpp"
31 Platform::Platform(const lisp::Lisp& reader)
36 reader.get("x", bbox.p1.x);
37 reader.get("y", bbox.p1.y);
38 reader.get("type", type);
39 reader.get("use_path", use_path);
40 sprite = sprite_manager->create("platform");
41 sprite->set_action(type);
42 bbox.set_size(sprite->get_width(), sprite->get_height());
46 path = Path::GetByName(use_path);
48 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";
51 path_offset = bbox.p1 - path->GetStart();
59 //TODO: Squish Tux when standing between platform and solid tile/object
60 // Improve collision handling
61 // Move all MovingObjects lying on the platform instead of only the player
63 Platform::collision(GameObject& other, const CollisionHit& hit)
65 if (typeid(other) == typeid(Player)) {
66 Player* player = (Player*) &other;
67 if ((hit.normal.x == 0) && (hit.normal.y == 1)) {
68 //Tux is standing on the platform
69 player->movement += path->GetLastMovement();
72 if(other.get_flags() & FLAG_SOLID) {
73 //Collision with a solid tile
74 //does nothing, because the movement vector isn't used at the moment
81 Platform::update(float elapsed_time)
83 set_pos(path->GetPosition() + path_offset);
87 Platform::draw(DrawingContext& context)
89 sprite->draw(context, get_pos(), LAYER_OBJECTS);
92 IMPLEMENT_FACTORY(Platform, "platform");