Make Tux run automatically. As before, if he is carrying something Tux
[supertux.git] / src / object / camera.cpp
index ef22b8f..41fc561 100644 (file)
 #include "path.hpp"
 #include "path_walker.hpp"
 
-Camera::Camera(Sector* newsector)
-  : sector(newsector), do_backscrolling(true), scrollchange(NONE)
+Camera::Camera(Sector* newsector, std::string name)
+  : mode(NORMAL), sector(newsector), do_backscrolling(true),
+    scrollchange(NONE)
 {
-  mode = NORMAL;
+  this->name = name;
 }
 
 Camera::~Camera()
@@ -52,14 +53,16 @@ Camera::~Camera()
 void
 Camera::expose(HSQUIRRELVM vm, SQInteger table_idx)
 {
+  if(name.empty()) return;
   Scripting::Camera* interface = new Scripting::Camera(this);
-  expose_object(vm, table_idx, interface, "Camera", true);
+  expose_object(vm, table_idx, interface, name, true);
 }
 
 void
 Camera::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
 {
-  Scripting::unexpose_object(vm, table_idx, "Camera");
+  if(name.empty()) return;
+  Scripting::unexpose_object(vm, table_idx, name);
 }
 
 const Vector&
@@ -250,8 +253,19 @@ Camera::update_scroll_normal(float elapsed_time)
   // when suddenly changing directions while scrolling into the other direction.
   // abort scrolling, since tux might be going left/right at a relatively small
   // part of the map (like when jumping upwards)
-  if((player->dir == ::LEFT && scrollchange == RIGHT)
-      || (player->dir == ::RIGHT && scrollchange == LEFT))
+  
+
+  // Find out direction in which the player walks: We want to try and show a 
+  // bit more of what's in front of the player and less of what's behind
+  LeftRightScrollChange walkDirection;  
+  if (player->physic.get_velocity_x() < -EPSILON) walkDirection = LEFT;
+  else if (player->physic.get_velocity_x() > EPSILON) walkDirection = RIGHT;
+  else if (player->dir == ::LEFT) walkDirection = LEFT;
+  else walkDirection = RIGHT;
+
+
+  if((walkDirection == LEFT && scrollchange == RIGHT)
+      || (walkDirection == RIGHT && scrollchange == LEFT))
     scrollchange = NONE;
   // when in left 1/3rd of screen scroll left
   if(player->get_bbox().get_middle().x < translation.x + SCREEN_WIDTH/3 - 16