Skip to content

Commit 5d9f24c

Browse files
author
Semphris
committed
Allow peeking with multiplayer camera
1 parent 6db02ec commit 5d9f24c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/object/camera.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static const float PEEK_ARRIVE_RATIO = 0.03f;
4242
*/
4343
static const float HORIZONTAL_MARGIN = 196.f; // 6 tiles
4444
static const float VERTICAL_MARGIN = 196.f; // 6 tiles
45+
static const float PEEK_ADD_HORIZONTAL_MARGIN = 320.f; // 10 tiles
46+
static const float PEEK_ADD_VERTICAL_MARGIN = 320.f; // 10 tiles
4547

4648
/* 0 = no movement, 1 = no smooth adaptation */
4749
static const float MULTIPLAYER_CAM_WEIGHT = 0.1f;
@@ -725,10 +727,25 @@ Camera::update_scroll_normal_multiplayer(float dt_sec)
725727
if (p->is_dead() || p->is_dying())
726728
continue;
727729

728-
x1 = std::min(x1, p->get_bbox().get_left() - HORIZONTAL_MARGIN);
729-
x2 = std::max(x2, p->get_bbox().get_right() + HORIZONTAL_MARGIN);
730-
y1 = std::min(y1, p->get_bbox().get_top() - VERTICAL_MARGIN);
731-
y2 = std::max(y2, p->get_bbox().get_bottom() + VERTICAL_MARGIN);
730+
float lft = p->get_bbox().get_left() - HORIZONTAL_MARGIN;
731+
float rgt = p->get_bbox().get_right() + HORIZONTAL_MARGIN;
732+
float top = p->get_bbox().get_top() - VERTICAL_MARGIN;
733+
float btm = p->get_bbox().get_bottom() + VERTICAL_MARGIN;
734+
735+
if (p->peeking_direction_x() == Direction::LEFT)
736+
lft -= PEEK_ADD_HORIZONTAL_MARGIN;
737+
else if (p->peeking_direction_x() == Direction::RIGHT)
738+
rgt += PEEK_ADD_HORIZONTAL_MARGIN;
739+
740+
if (p->peeking_direction_y() == Direction::UP)
741+
top -= PEEK_ADD_VERTICAL_MARGIN;
742+
else if (p->peeking_direction_y() == Direction::DOWN)
743+
btm += PEEK_ADD_VERTICAL_MARGIN;
744+
745+
x1 = std::min(x1, lft);
746+
x2 = std::max(x2, rgt);
747+
y1 = std::min(y1, top);
748+
y2 = std::max(y2, btm);
732749
}
733750

734751
// Might happens if all players are dead

0 commit comments

Comments
 (0)