From 12eca6eff537006bb8ca7316c151558b5e9fcb01 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Fri, 7 May 2004 23:09:53 +0000 Subject: [PATCH] Added horizontal auto scrolling! Hope you like it ;) SVN-Revision: 1032 --- src/level.cpp | 5 +++++ src/level.h | 1 + src/player.cpp | 13 ++++++++++++- src/world.cpp | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/level.cpp b/src/level.cpp index 3df8c8946..8fcfeabd7 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -237,6 +237,7 @@ Level::init_defaults() time_left = 100; gravity = 10.; back_scrolling = false; + hor_autoscroll_speed = 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); + hor_autoscroll_speed = 0; + reader.read_float("hor_autoscroll_speed", &hor_autoscroll_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," (hor_autoscroll_speed %2.1f)\n", hor_autoscroll_speed); fprintf(fi," (gravity %2.1f)\n", gravity); fprintf(fi," (background-tm "); diff --git a/src/level.h b/src/level.h index 49bd17700..ad04af453 100644 --- a/src/level.h +++ b/src/level.h @@ -90,6 +90,7 @@ class Level int start_pos_y; float gravity; bool back_scrolling; + float hor_autoscroll_speed; std::vector badguy_data; diff --git a/src/player.cpp b/src/player.cpp index 617b48d83..179b533f0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -27,6 +27,8 @@ #include "sprite.h" #include "screen.h" +#define AUTOSCROLL_DEAD_INTERVAL 300 + Surface* tux_life; Sprite* smalltux_gameover; @@ -721,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; @@ -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) + 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 // diff --git a/src/world.cpp b/src/world.cpp index fdb1fda8e..80bfe7b78 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -318,6 +318,12 @@ World::action(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) -- 2.11.0