Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions games/BelowTheSurface/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Camera
double y_border_top = 0;
double x_border_right;
double y_border_bottom;
bool first_update = true;
vector<shared_ptr<Player>> players;

public:
Expand Down Expand Up @@ -48,11 +49,28 @@ class Camera

point_2d mid_player = {mid_player_x, mid_player_y};

double sc_x = mid_player.x + - (screen_width() / 2);
double sc_y = mid_player.y + - (screen_height() / 2);

move_camera_to(sc_x, sc_y);
// Target position (Where the camera should be)
double sc_x = mid_player.x - (screen_width() / 2);
double sc_y = mid_player.y - (screen_height() / 2);

if (first_update)
{
move_camera_to(sc_x, sc_y);
first_update = false;
}
else
{
// Current position
double cam_x = camera_x();
double cam_y = camera_y();

// Next eased position
double smooth = 0.05;
cam_x += (sc_x - cam_x) * smooth;
cam_y += (sc_y - cam_y) * smooth;

move_camera_to(cam_x, cam_y);
}

if(camera_x() < x_border_left)
set_camera_x(x_border_left);
Expand Down