From 2785cdfa77f456c673bb7ce346a3383e0d5fb92e Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 11 Apr 2004 23:06:29 +0000 Subject: [PATCH] - tweaked scroll behaviour a little bit - added collision rects in debug mode SVN-Revision: 497 --- src/badguy.cpp | 3 +++ src/player.cpp | 76 ++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/badguy.cpp b/src/badguy.cpp index b36e075dc..45a02a0ff 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -742,6 +742,9 @@ BadGuy::draw() texture_type* texture = (dir == LEFT) ? &texture_left[frame] : &texture_right[frame]; texture_draw(texture, base.x - scroll_x, base.y); + + if (debug_mode) + fillrect(base.x - scroll_x, base.y, 32, 32, 75,0,75, 150); } void diff --git a/src/player.cpp b/src/player.cpp index 5c58bddb0..3b70aeb70 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -722,7 +722,6 @@ Player::draw() else { /* Tux has coffee! */ - if (!duck) { if (!skidding_timer.started()) @@ -785,6 +784,9 @@ Player::draw() if(dying) text_drawf(&gold_text,"Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1); + + if (debug_mode) + fillrect(base.x - scroll_x, base.y, 32, 32, 75,75,75, 150); } void @@ -917,42 +919,54 @@ Player::keep_in_bounds() Level* plevel = World::current()->get_level(); /* Keep tux in bounds: */ - if (base.x< 0) - base.x= 0; - else if(base.x< scroll_x) - base.x= scroll_x; - else if (base.x< 160 + scroll_x && scroll_x > 0 && debug_mode) - { - scroll_x = base.x- 160; - /*base.x+= 160;*/ - - if(scroll_x < 0) - scroll_x = 0; - + if (base.x < 0) + { // Lock Tux to the size of the level, so that he doesn't fall of + // on the left side + base.x = 0; } - else if (base.x > screen->w / 2 + scroll_x - && scroll_x < ((World::current()->get_level()->width * 32) - screen->w)) - { - // FIXME: Scrolling needs to be handled by a seperate View - // class, doing it as a player huck is ugly - - // Scroll the screen in past center: - scroll_x = base.x - screen->w / 2; - - if (scroll_x > ((plevel->width * 32) - screen->w)) - scroll_x = ((plevel->width * 32) - screen->w); - } - else if (base.x> 608 + scroll_x) - { - /* ... unless there's no more to scroll! */ - - /*base.x= 608 + scroll_x;*/ + else if (base.x < scroll_x) + { + base.x = scroll_x; } /* Keep in-bounds, vertically: */ - if (base.y > screen->h) { kill(KILL); } + + int scroll_threshold = screen->w/2 - 80; + if (debug_mode) + { + scroll_x += screen->w/2; + // Backscrolling for debug mode + if (scroll_x < base.x - 80) + scroll_x = base.x - 80; + else if (scroll_x > base.x + 80) + scroll_x = base.x + 80; + scroll_x -= screen->w/2; + + if(scroll_x < 0) + scroll_x = 0; + } + else + { + if (base.x > scroll_threshold + scroll_x + && scroll_x < ((World::current()->get_level()->width * 32) - screen->w)) + { + // FIXME: Scrolling needs to be handled by a seperate View + // class, doing it as a player huck is ugly + + // Scroll the screen in past center: + scroll_x = base.x - scroll_threshold; + + // Lock the scrolling to the levelsize, so that we don't + // scroll over the right border + if (scroll_x > 32 * plevel->width - screen->w) + scroll_x = 32 * plevel->width - screen->w; + } + } } + +// EOF // + -- 2.11.0