From 1c148c20eede15d02659203c417d01a9877103de Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Fri, 30 Jun 2006 21:42:04 +0000 Subject: [PATCH] Made flip_level_transformer flip platforms. SVN-Revision: 3815 --- src/flip_level_transformer.cpp | 13 +++++++++++++ src/flip_level_transformer.hpp | 3 +++ src/object/camera.cpp | 2 +- src/object/path.hpp | 24 ++++++++++++------------ src/object/path_walker.cpp | 8 ++------ src/object/path_walker.hpp | 2 -- src/object/platform.cpp | 2 +- src/object/platform.hpp | 4 ++++ 8 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/flip_level_transformer.cpp b/src/flip_level_transformer.cpp index 228c6200a..2d966de7a 100644 --- a/src/flip_level_transformer.cpp +++ b/src/flip_level_transformer.cpp @@ -52,6 +52,10 @@ FlipLevelTransformer::transform_sector(Sector* sector) if(badguy) { transform_badguy(height, badguy); } + Platform* platform = dynamic_cast (object); + if(platform) { + transform_platform(height, *platform); + } MovingObject* mobject = dynamic_cast (object); if(mobject) { transform_moving_object(height, mobject); @@ -110,3 +114,12 @@ FlipLevelTransformer::transform_moving_object(float height, MovingObject*object) object->set_pos(pos); } +void +FlipLevelTransformer::transform_platform(float height, Platform& platform) +{ + Path& path = platform.get_path(); + for (std::vector::iterator i = path.nodes.begin(); i != path.nodes.end(); i++) { + Vector& pos = i->position; + pos.y = height - pos.y - platform.get_bbox().get_height(); + } +} diff --git a/src/flip_level_transformer.hpp b/src/flip_level_transformer.hpp index d58bc93d7..fde90f8b8 100644 --- a/src/flip_level_transformer.hpp +++ b/src/flip_level_transformer.hpp @@ -21,6 +21,8 @@ #define __FLIP_LEVEL_TRANSFORMER_H__ #include "level_transformer.hpp" +#include "object/platform.hpp" +#include "object/path.hpp" class TileMap; class BadGuy; @@ -38,6 +40,7 @@ private: void transform_moving_object(float height, MovingObject* object); void transform_badguy(float height, BadGuy* badguy); void transform_spawnpoint(float height, SpawnPoint* spawnpoint); + void transform_platform(float height, Platform& platform); }; #endif diff --git a/src/object/camera.cpp b/src/object/camera.cpp index 6289b9e9f..9c46ca322 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -300,7 +300,7 @@ Camera::update_scroll_autoscroll(float elapsed_time) if(player->is_dying()) return; - translation += autoscroll_walker->advance(elapsed_time); + translation = autoscroll_walker->advance(elapsed_time); keep_in_bounds(translation); shake(); diff --git a/src/object/path.hpp b/src/object/path.hpp index 60812ecfb..5ac0fe032 100644 --- a/src/object/path.hpp +++ b/src/object/path.hpp @@ -38,6 +38,18 @@ public: Vector get_base() const; + /** + * Helper class that stores an individual node of a Path + */ + class Node + { + public: + Vector position; /**< the position of this node */ + float time; /**< time (in seconds) to get from this node to next node */ + }; + + std::vector nodes; + private: friend class PathWalker; @@ -50,18 +62,6 @@ private: CIRCULAR }; - /** - * Helper class that stores an individual node of a Path - */ - class Node - { - public: - Vector position; /**< the position of this node */ - float time; /**< time (in seconds) to get from this node to next node */ - }; - - std::vector nodes; - WalkMode mode; }; diff --git a/src/object/path_walker.cpp b/src/object/path_walker.cpp index d0d55ddfa..29ee6fcec 100644 --- a/src/object/path_walker.cpp +++ b/src/object/path_walker.cpp @@ -27,7 +27,6 @@ PathWalker::PathWalker(const Path* path, bool running) : path(path), running(running), current_node_nr(0), next_node_nr(0), stop_at_node_nr(running?-1:0), node_time(0), walking_speed(1.0) { - last_pos = path->nodes[0].position; node_mult = 1 / path->nodes[0].time; next_node_nr = path->nodes.size() > 1 ? 1 : 0; } @@ -39,7 +38,7 @@ PathWalker::~PathWalker() Vector PathWalker::advance(float elapsed_time) { - if (!running) return Vector(0,0); + if (!running) return path->nodes[current_node_nr].position; assert(elapsed_time >= 0); @@ -70,10 +69,7 @@ PathWalker::advance(float elapsed_time) Vector new_pos = current_node->position + (next_node->position - current_node->position) * node_time; - Vector result = new_pos - last_pos; - last_pos = new_pos; - - return result; + return new_pos; } void diff --git a/src/object/path_walker.hpp b/src/object/path_walker.hpp index 0b8357fe8..5bb330092 100644 --- a/src/object/path_walker.hpp +++ b/src/object/path_walker.hpp @@ -69,8 +69,6 @@ private: */ int stop_at_node_nr; - Vector last_pos; - /** * the position between the current node and the next node as fraction * between 0 and 1 diff --git a/src/object/platform.cpp b/src/object/platform.cpp index d6dde0a7c..333fd0714 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -83,7 +83,7 @@ Platform::collision(GameObject& other, const CollisionHit& hit) void Platform::update(float elapsed_time) { - movement = walker->advance(elapsed_time); + movement = walker->advance(elapsed_time) - get_pos(); speed = movement / elapsed_time; } diff --git a/src/object/platform.hpp b/src/object/platform.hpp index c38f24ace..f5e1d245e 100644 --- a/src/object/platform.hpp +++ b/src/object/platform.hpp @@ -56,6 +56,10 @@ public: virtual void expose(HSQUIRRELVM vm, SQInteger table_idx); virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx); + Path& get_path() { + return *path.get(); + } + private: std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */ std::auto_ptr path; -- 2.11.0