YAPOG  0.0.1
Yet Another Pokemon Online Game
CameraController.cpp
Go to the documentation of this file.
3 
4 namespace yap
5 {
7  : camera_ (camera)
8  , target_ (nullptr)
9  , bounds_ ()
10  {
11  }
12 
14  {
15  }
16 
18  {
19  target_ = ⌖
20  }
21 
23  {
25  }
26 
28  {
29  bounds_ = bounds;
30  }
31 
32  void CameraController::Update (const Time& dt)
33  {
34  HandleUpdate (dt);
35  }
36 
38  {
39  if (camera_.GetTopLeft ().x + offset.x < bounds_.left)
40  offset.x = bounds_.left - camera_.GetTopLeft ().x;
41 
42  if (camera_.GetBottomRight ().x + offset.x >
43  (bounds_.left + bounds_.width))
44  offset.x = bounds_.left + bounds_.width - camera_.GetBottomRight ().x;
45 
46  if (camera_.GetTopLeft ().y + offset.y < bounds_.top)
47  offset.y = bounds_.top - camera_.GetTopLeft ().y;
48 
49  if (camera_.GetBottomRight ().y + offset.y >
50  (bounds_.top + bounds_.height))
51  offset.y = bounds_.top + bounds_.height - camera_.GetBottomRight ().y;
52  }
53 
55  {
56  if (target_ == nullptr)
57  return;
58 
59  const Vector2& targetPoint = target_->GetCenter ();
60  Vector2 offset = targetPoint - camera_.GetCenter ();
61 
62  CheckBounds (offset);
63 
64  camera_.Move (offset);
65  }
66 } // namespace yap