// 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)
{
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;
}
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);
translation.x -= speed_x * elapsed_time;
keep_in_bounds();
+ shake();
}
void
}
keep_in_bounds();
+ shake();
}