first very unfinished and unpolished version of the intro
[supertux.git] / src / object / path.cpp
index 8fa5a16..251afd0 100644 (file)
@@ -1,4 +1,4 @@
-//  $Id:$
+//  $Id$
 // 
 //  SuperTux
 //  Copyright (C) 2005 Philipp <balinor@pnxs.de>
@@ -33,7 +33,8 @@
 
 Path::Path(const lisp::Lisp& reader)
 {
-  float x,y;
+  forward = true;
+  float x = 0, y = 0;
 
   lisp::ListIterator iter(&reader);
 
@@ -42,6 +43,14 @@ Path::Path(const lisp::Lisp& reader)
   assert(token == "name");
   iter.value()->get(name);
 
+  circular = true;
+  assert (iter.next());
+  token = iter.item();
+  if (token == "circular") {
+    iter.value()->get(circular);
+    iter.next();
+  }
+
   pixels_per_second = DEFAULT_PIXELS_PER_SECOND;
   assert (iter.next());
   token = iter.item();
@@ -85,9 +94,9 @@ Path::update(float elapsed_time)
 }
 
 void
-Path::draw(DrawingContext& context)
+Path::draw(DrawingContext& )
 {
-  // NOOP ;-)
+   // TODO: Add a visible flag, draw the path if true
 }
 
 const Vector&
@@ -110,9 +119,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;