Added horizontal auto scrolling!
authorRicardo Cruz <rick2@aeiou.pt>
Fri, 7 May 2004 23:09:53 +0000 (23:09 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Fri, 7 May 2004 23:09:53 +0000 (23:09 +0000)
Hope you like it ;)

SVN-Revision: 1032

src/level.cpp
src/level.h
src/player.cpp
src/world.cpp

index 3df8c89..8fcfeab 100644 (file)
@@ -237,6 +237,7 @@ Level::init_defaults()
   time_left  = 100;
   gravity    = 10.;
   back_scrolling = false;
   time_left  = 100;
   gravity    = 10.;
   back_scrolling = false;
+  hor_autoscroll_speed = 0;
   bkgd_speed = 2;
   bkgd_top.red   = 0;
   bkgd_top.green = 0;
   bkgd_speed = 2;
   bkgd_top.red   = 0;
   bkgd_top.green = 0;
@@ -316,6 +317,9 @@ Level::load(const std::string& filename)
       back_scrolling = false;
       reader.read_bool("back_scrolling",  &back_scrolling);
 
       back_scrolling = false;
       reader.read_bool("back_scrolling",  &back_scrolling);
 
+      hor_autoscroll_speed = 0;
+      reader.read_float("hor_autoscroll_speed",  &hor_autoscroll_speed);
+      
       bkgd_speed = 2;
       reader.read_int("bkgd_speed",  &bkgd_speed);
 
       bkgd_speed = 2;
       reader.read_int("bkgd_speed",  &bkgd_speed);
 
@@ -561,6 +565,7 @@ Level::save(const std::string& subset, int level)
     fprintf(fi,"  (back_scrolling #t)\n"); 
   else
     fprintf(fi,"  (back_scrolling #f)\n");
     fprintf(fi,"  (back_scrolling #t)\n"); 
   else
     fprintf(fi,"  (back_scrolling #f)\n");
+  fprintf(fi,"  (hor_autoscroll_speed %2.1f)\n", hor_autoscroll_speed);
   fprintf(fi,"  (gravity %2.1f)\n", gravity);
   fprintf(fi,"  (background-tm ");
 
   fprintf(fi,"  (gravity %2.1f)\n", gravity);
   fprintf(fi,"  (background-tm ");
 
index 49bd177..ad04af4 100644 (file)
@@ -90,6 +90,7 @@ class Level
   int start_pos_y;
   float gravity;
   bool back_scrolling;
   int start_pos_y;
   float gravity;
   bool back_scrolling;
+  float hor_autoscroll_speed;
 
   std::vector<BadGuyData> badguy_data;
 
 
   std::vector<BadGuyData> badguy_data;
 
index 617b48d..179b533 100644 (file)
@@ -27,6 +27,8 @@
 #include "sprite.h"
 #include "screen.h"
 
 #include "sprite.h"
 #include "screen.h"
 
+#define AUTOSCROLL_DEAD_INTERVAL 300
+
 Surface* tux_life;
 
 Sprite* smalltux_gameover;
 Surface* tux_life;
 
 Sprite* smalltux_gameover;
@@ -721,7 +723,7 @@ Player::is_dying()
 
 bool Player::is_dead()
 {
 
 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;
     return true;
   else
     return false;
@@ -754,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)  // 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 //
 }
 
 // EOF //
index fdb1fda..80bfe7b 100644 (file)
@@ -318,6 +318,12 @@ World::action(double frame_ratio)
 /* This functions takes cares of the scrolling */
 void World::scrolling(double frame_ratio)
 {
 /* This functions takes cares of the scrolling */
 void World::scrolling(double frame_ratio)
 {
+  if(level->hor_autoscroll_speed)
+    {
+    scroll_x += level->hor_autoscroll_speed * frame_ratio;
+    return;
+    }
+
   int tux_pos_x = (int)(tux.base.x + (tux.base.width/2));
 
   if (level->back_scrolling || debug_mode)
   int tux_pos_x = (int)(tux.base.x + (tux.base.width/2));
 
   if (level->back_scrolling || debug_mode)