Experiments with Kirby(1)-style-camera
authorChristoph Sommer <mail@christoph-sommer.de>
Sun, 21 Jan 2007 14:35:00 +0000 (14:35 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sun, 21 Jan 2007 14:35:00 +0000 (14:35 +0000)
SVN-Revision: 4618

data/locale/messages.pot
src/object/camera.cpp
src/object/camera.hpp

index 466ad9b..32cd532 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 ""
 
index 41fc561..c3023df 100644 (file)
 #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;
 
index 73e6d3c..e02c306 100644 (file)
@@ -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);