if(badguy) {
transform_badguy(height, badguy);
}
+ Platform* platform = dynamic_cast<Platform*> (object);
+ if(platform) {
+ transform_platform(height, *platform);
+ }
MovingObject* mobject = dynamic_cast<MovingObject*> (object);
if(mobject) {
transform_moving_object(height, mobject);
object->set_pos(pos);
}
+void
+FlipLevelTransformer::transform_platform(float height, Platform& platform)
+{
+ Path& path = platform.get_path();
+ for (std::vector<Path::Node>::iterator i = path.nodes.begin(); i != path.nodes.end(); i++) {
+ Vector& pos = i->position;
+ pos.y = height - pos.y - platform.get_bbox().get_height();
+ }
+}
#define __FLIP_LEVEL_TRANSFORMER_H__
#include "level_transformer.hpp"
+#include "object/platform.hpp"
+#include "object/path.hpp"
class TileMap;
class BadGuy;
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
if(player->is_dying())
return;
- translation += autoscroll_walker->advance(elapsed_time);
+ translation = autoscroll_walker->advance(elapsed_time);
keep_in_bounds(translation);
shake();
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<Node> nodes;
+
private:
friend class PathWalker;
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<Node> nodes;
-
WalkMode mode;
};
: 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;
}
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);
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
*/
int stop_at_node_nr;
- Vector last_pos;
-
/**
* the position between the current node and the next node as fraction
* between 0 and 1
void
Platform::update(float elapsed_time)
{
- movement = walker->advance(elapsed_time);
+ movement = walker->advance(elapsed_time) - get_pos();
speed = movement / elapsed_time;
}
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> path;