some fixes for the text object
[supertux.git] / src / object / camera.cpp
index 8aa8d42..476ca41 100644 (file)
@@ -16,7 +16,6 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
 #include <config.h>
 
 #include <stdexcept>
 #include "camera.h"
 #include "player.h"
 #include "tilemap.h"
-#include "gameloop.h"
-#include "app/globals.h"
+#include "game_session.h"
 #include "sector.h"
+#include "main.h"
 #include "object_factory.h"
 
-using namespace SuperTux;
-
 Camera::Camera(Sector* newsector)
   : sector(newsector), do_backscrolling(true), scrollchange(NONE),
     auto_idx(0), auto_t(0)
@@ -133,9 +130,20 @@ Camera::reset(const Vector& tuxpos)
 {
   translation.x = tuxpos.x - SCREEN_WIDTH/3 * 2;
   translation.y = tuxpos.y - SCREEN_HEIGHT/2;
+  shakespeed = 0;
+  shaketimer.stop();
   keep_in_bounds();
 }
 
+void
+Camera::shake(float time, float x, float y)
+{
+  shaketimer.start(time);
+  shakedepth_x = x;
+  shakedepth_y = y;
+  shakespeed = M_PI/2 / time;
+}
+
 static const float EPSILON = .00001;
 static const float max_speed_y = 140;
 
@@ -166,6 +174,15 @@ Camera::keep_in_bounds()
 }
 
 void
+Camera::shake()
+{
+  if(shaketimer.started()) {
+    translation.x -= sin(shaketimer.get_timegone() * shakespeed) * shakedepth_x;
+    translation.y -= sin(shaketimer.get_timegone() * shakespeed) * shakedepth_y;
+  }
+}
+
+void
 Camera::scroll_normal(float elapsed_time)
 {
   assert(sector != 0);
@@ -253,6 +270,7 @@ Camera::scroll_normal(float elapsed_time)
   translation.x -= speed_x * elapsed_time;
 
   keep_in_bounds();
+  shake();
 }
 
 void
@@ -289,5 +307,6 @@ Camera::scroll_autoscroll(float elapsed_time)
   }
 
   keep_in_bounds();
+  shake();
 }