summary refs log tree commit diff stats
path: root/src/game.cpp
blob: 42dbd64956a4d5956bad48de383a237756e21a8b (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
28
29
30
#include "game.h"

int Game::addSprite(Sprite sprite) {
  int id = sprites_.size();
  sprites_.push_back(std::move(sprite));
  spriteIds_.push_back(id);
  return id;
}

void Game::tick() {
  if (!cameraLocked_) {
    const Sprite& follow = getSprite(followingSprite_);
    vec2i mapBounds = map_->getMapSize() * map_->getTileSize();

    cameraPos_ = follow.loc() - (cameraFov_ / 2);

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