Fixed creating level-subset again.
[supertux.git] / src / player.cpp
index 4010551..179b533 100644 (file)
@@ -27,6 +27,8 @@
 #include "sprite.h"
 #include "screen.h"
 
+#define AUTOSCROLL_DEAD_INTERVAL 300
+
 Surface* tux_life;
 
 Sprite* smalltux_gameover;
@@ -78,6 +80,7 @@ Player::init()
   base.ym = 0;
   previous_base = old_base = base;
   dir = RIGHT;
+  old_dir = dir;
   duck = false;
 
   dying   = DYING_NOT;
@@ -295,9 +298,11 @@ Player::handle_horizontal_input()
 
   float dirsign = 0;
   if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
+      old_dir = dir;
       dir = LEFT;
       dirsign = -1;
   } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
+      old_dir = dir;
       dir = RIGHT;
       dirsign = 1;
   }
@@ -718,7 +723,7 @@ Player::is_dying()
 
 bool Player::is_dead()
 {
-  if(base.y > screen->h)
+  if(base.y > screen->h || base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL)  // last condition can happen in auto-scrolling
     return true;
   else
     return false;
@@ -751,6 +756,15 @@ Player::check_bounds()
 
   if(base.x < scroll_x)  // can happen if back scrolling is disabled
     base.x = scroll_x;
+
+  if(base.x == scroll_x)
+    if(issolid(base.x, base.y) || issolid(base.x, base.y+32))
+      kill(KILL);
+
+  if(base.x + base.width > scroll_x + screen->w)
+    base.x = scroll_x + screen->w - base.width;
+
+    
 }
 
 // EOF //