summary refs log tree commit diff stats
path: root/src/camera_system.cpp
blob: 4709d01a7e50139868f0097d44f2c0c534904d6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "camera_system.h"
#include "sprite.h"
#include "game.h"
#include "map.h"

void CameraSystem::tick(double dt) {
  if (!locked_) {
    const Sprite& follow = game_.getSprite(followingSprite_);
    const Map& map = game_.getMap();
    vec2i mapBounds = map.getMapSize() * map.getTileSize();

    pos_ = follow.loc - (fov_ / 2);

    if (pos_.x() < 0) {
      pos_.x() = 0;
    }
    if (pos_.y() < 0) {
      pos_.y() = 0;
    }
    if (pos_.x() + fov_.w() >= mapBounds.w()) {
      pos_.x() = mapBounds.w() - fov_.w() - 1;
    }
    if (pos_.y() + fov_.h() >= mapBounds.h()) {
      pos_.y() = mapBounds.h() - fov_.h() - 1;
    }
  }
}