From: Marek Moeckel Date: Sat, 16 Jul 2005 10:30:07 +0000 (+0000) Subject: added some comments and the framework for platforms that travel back and forth on... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=a15b670f9fb343da5a2398880cfacf2655aefdec;p=supertux.git added some comments and the framework for platforms that travel back and forth on a path instead of circular. Due to my bad knowledge of C++ this doesn't work yet. SVN-Revision: 2722 --- diff --git a/data/levels/test/platform.stl b/data/levels/test/platform.stl index 8e33a772f..dbf6197c5 100644 --- a/data/levels/test/platform.stl +++ b/data/levels/test/platform.stl @@ -128,8 +128,8 @@ (image "arctis.jpg") (speed 0.500000) ) - (path (name "path1") (speed 100) (x 0) (y 0) (x 0) (y -100) (x 100) (y -100) (x 100) (y 0)) - (path (name "path2") (speed 100) (x 0) (y 0) (x 0) (y 100) (x 100) (y 100) (x 100) (y 0)) + (path (name "path1") (circular #t) (speed 100) (x 0) (y 0) (x 0) (y -100) (x 100) (y -100) (x 100) (y 0)) + (path (name "path2") (circular #t) (speed 100) (x 0) (y 0) (x 0) (y 100) (x 100) (y 100) (x 100) (y 0)) (platform (use_path "path1") (x 200) (y 850) (type "block1")) (platform (use_path "path1") (x 232) (y 850) (type "block2")) (platform (use_path "path2") (x 264) (y 650) (type "block2")) diff --git a/src/object/path.cpp b/src/object/path.cpp index 8fa5a1625..4296315a4 100644 --- a/src/object/path.cpp +++ b/src/object/path.cpp @@ -1,4 +1,4 @@ -// $Id:$ +// $Id$ // // SuperTux // Copyright (C) 2005 Philipp @@ -33,6 +33,7 @@ Path::Path(const lisp::Lisp& reader) { + forward = true; float x,y; lisp::ListIterator iter(&reader); @@ -42,6 +43,12 @@ Path::Path(const lisp::Lisp& reader) assert(token == "name"); iter.value()->get(name); + circular = true; + assert (iter.next()); + token = iter.item(); + assert(token == "circular"); + iter.value()->get(circular); + pixels_per_second = DEFAULT_PIXELS_PER_SECOND; assert (iter.next()); token = iter.item(); @@ -87,7 +94,7 @@ Path::update(float elapsed_time) void Path::draw(DrawingContext& context) { - // NOOP ;-) + // TODO: Add a visible flag, draw the path if true } const Vector& @@ -110,9 +117,21 @@ Path::calc_next_velocity() { Vector distance; - ++next_target; - if (next_target == points.end()) { - next_target = points.begin(); + if (circular) { + ++next_target; + if (next_target == points.end()) { + next_target = points.begin(); + } + } + else if (forward) { + ++next_target; + if (next_target == points.end()) { + forward = false; + } + } + else { + //FIXME: Implement going backwards on the list + // I have no f***ing idea how this is done in C++ } distance = *next_target - pos; diff --git a/src/object/path.hpp b/src/object/path.hpp index 3671ec0e0..97f21abe3 100644 --- a/src/object/path.hpp +++ b/src/object/path.hpp @@ -1,4 +1,4 @@ -// $Id:$ +// $Id$ // // SuperTux // Copyright (C) 2005 Philipp @@ -54,13 +54,16 @@ public: static Path* GetByName(const std::string& name); private: - std::string name; - float pixels_per_second; - PathPoints points; - PathPointIter next_target; - Vector pos; - Vector velocity; - Vector last_movement; + std::string name; + float pixels_per_second; + PathPoints points; + PathPointIter next_target; + Vector pos; + Vector velocity; + Vector last_movement; + + bool circular; + bool forward; void calc_next_velocity(); diff --git a/src/object/platform.cpp b/src/object/platform.cpp index 6bc64f4ba..b3c0dc52d 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -44,6 +44,9 @@ Platform::Platform(const lisp::Lisp& reader) flags |= FLAG_SOLID; 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 - path->GetStart(); } @@ -53,6 +56,9 @@ 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& other, const CollisionHit& hit) { @@ -66,6 +72,7 @@ Platform::collision(GameObject& other, const CollisionHit& hit) 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; } return FORCE_MOVE; }