From: Christoph Sommer Date: Sun, 21 Jan 2007 14:35:00 +0000 (+0000) Subject: Experiments with Kirby(1)-style-camera X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0176ce998a65364f4aaaeb5fdc5418798f6b83d9;p=supertux.git Experiments with Kirby(1)-style-camera SVN-Revision: 4618 --- diff --git a/data/locale/messages.pot b/data/locale/messages.pot index 466ad9b72..32cd532b0 100644 --- a/data/locale/messages.pot +++ b/data/locale/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-01-20 17:05+0100\n" +"POT-Creation-Date: 2007-01-21 15:32+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,7 +16,7 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: src/options_menu.cpp:49 src/game_session.cpp:104 src/title.cpp:275 +#: src/options_menu.cpp:49 src/game_session.cpp:104 src/title.cpp:276 #: src/worldmap/worldmap.cpp:152 msgid "Options" msgstr "" @@ -143,23 +143,23 @@ msgstr "" msgid "Time" msgstr "" -#: src/title.cpp:82 src/title.cpp:273 +#: src/title.cpp:82 src/title.cpp:274 msgid "Start Game" msgstr "" -#: src/title.cpp:117 src/title.cpp:274 +#: src/title.cpp:117 src/title.cpp:275 msgid "Contrib Levels" msgstr "" -#: src/title.cpp:276 +#: src/title.cpp:277 msgid "Credits" msgstr "" -#: src/title.cpp:277 +#: src/title.cpp:278 msgid "Quit" msgstr "" -#: src/title.cpp:316 +#: src/title.cpp:317 msgid "" "Copyright (c) 2006 SuperTux Devel Team\n" "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you " @@ -167,11 +167,11 @@ msgid "" "redistribute it under certain conditions; see the file COPYING for details.\n" msgstr "" -#: src/title.cpp:418 src/title.cpp:423 +#: src/title.cpp:419 src/title.cpp:424 msgid "Slot" msgstr "" -#: src/title.cpp:418 +#: src/title.cpp:419 msgid "Free" msgstr "" diff --git a/src/object/camera.cpp b/src/object/camera.cpp index 41fc561a7..c3023dfcb 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -39,6 +39,11 @@ #include "path.hpp" #include "path_walker.hpp" +namespace { + enum CameraStyle { CameraStyleYI, CameraStyleKD }; + const CameraStyle cameraStyle = CameraStyleKD; +} + Camera::Camera(Sector* newsector, std::string name) : mode(NORMAL), sector(newsector), do_backscrolling(true), scrollchange(NONE) @@ -120,8 +125,25 @@ Camera::write(lisp::Writer& writer) } void +Camera::reset_kd(const Vector& tuxpos) +{ + translation.x = tuxpos.x - (SCREEN_WIDTH * 0.5); + translation.y = tuxpos.y - (SCREEN_HEIGHT * 0.5); + + shakespeed = 0; + shaketimer.stop(); + keep_in_bounds(translation); +} + + +void Camera::reset(const Vector& tuxpos) { + if (cameraStyle == CameraStyleKD) { + reset_kd(tuxpos); + return; + } + translation.x = tuxpos.x - SCREEN_WIDTH/3 * 2; translation.y = tuxpos.y - SCREEN_HEIGHT/2; shakespeed = 0; @@ -198,8 +220,51 @@ Camera::shake() } void +Camera::update_scroll_normal_kd(float elapsed_time) +{ + // make sure some time has actually passed + if(elapsed_time < EPSILON) return; + + // make sure we have an active player + assert(sector != 0); + Player* player = sector->player; + Vector playerCenter = player->get_bbox().get_middle(); + + // If player is peeking, scroll in that direction + if (player->peeking_direction() == ::LEFT) { + translation.x -= elapsed_time * 128.0f; + } + else if (player->peeking_direction() == ::RIGHT) { + translation.x += elapsed_time * 128.0f; + } + + // keep player within a small box, centered on the screen (vertical part) + bool do_y_scrolling = true; + if (player->is_dying() || sector->get_height() == 19*32) do_y_scrolling = false; + if (do_y_scrolling) { + translation.y = std::min(player->get_bbox().p1.y - SCREEN_HEIGHT * (0.5f - 0.17f), translation.y); + translation.y = std::max(player->get_bbox().p2.y - SCREEN_HEIGHT * (0.5f + 0.17f), translation.y); + } + + // keep player within a small box, centered on the screen (horizontal part) + translation.x = std::min(player->get_bbox().p1.x - SCREEN_WIDTH * (0.5f - 0.1f), translation.x); + translation.x = std::max(player->get_bbox().p2.x - SCREEN_WIDTH * (0.5f + 0.1f), translation.x); + + // make sure camera doesn't point outside level borders + keep_in_bounds(translation); + + // handle shaking of camera (if applicable) + shake(); +} + +void Camera::update_scroll_normal(float elapsed_time) { + if (cameraStyle == CameraStyleKD) { + update_scroll_normal_kd(elapsed_time); + return; + } + assert(sector != 0); Player* player = sector->player; diff --git a/src/object/camera.hpp b/src/object/camera.hpp index 73e6d3c9e..e02c30696 100644 --- a/src/object/camera.hpp +++ b/src/object/camera.hpp @@ -52,6 +52,7 @@ public: /// reset camera postion virtual void reset(const Vector& tuxpos); + virtual void reset_kd(const Vector& tuxpos); /** return camera position */ const Vector& get_translation() const; @@ -88,6 +89,7 @@ public: private: void update_scroll_normal(float elapsed_time); + void update_scroll_normal_kd(float elapsed_time); void update_scroll_autoscroll(float elapsed_time); void update_scroll_to(float elapsed_time); void keep_in_bounds(Vector& vector);