From: Christoph Sommer Date: Tue, 23 May 2006 20:24:04 +0000 (+0000) Subject: Forced Camera to always have Tux in the middle 5/6 of the screen, no matter how fast... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8d7b9c4a30cf4769a5904a421a8930efae6a9cc0;p=supertux.git Forced Camera to always have Tux in the middle 5/6 of the screen, no matter how fast Tux moved SVN-Revision: 3571 --- diff --git a/src/object/camera.cpp b/src/object/camera.cpp index d10476915..6289b9e9f 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -237,6 +237,10 @@ Camera::update_scroll_normal(float elapsed_time) // finally scroll with calculated speed translation.y -= speed_y * elapsed_time; + + // make sure to always keep the player inside the middle 1/6 of the screen + translation.y = std::min(player->get_bbox().p1.y - SCREEN_HEIGHT*1/6, translation.y); + translation.y = std::max(player->get_bbox().p2.y - SCREEN_HEIGHT*5/6, translation.y); } /****** Horizontal scrolling part *******/ @@ -281,6 +285,10 @@ Camera::update_scroll_normal(float elapsed_time) // apply scrolling translation.x -= speed_x * elapsed_time; + // make sure to always keep the player inside the middle 4/6 of the screen + translation.x = std::min(player->get_bbox().p1.x - SCREEN_WIDTH*1/6, translation.x); + translation.x = std::max(player->get_bbox().p2.x - SCREEN_WIDTH*5/6, translation.x); + keep_in_bounds(translation); shake(); }