From 24918837c3ff9026d228657d14852c9cf39a5644 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 3 Feb 2021 01:11:31 -0500 Subject: Added camera system --- src/camera_system.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/camera_system.cpp (limited to 'src/camera_system.cpp') diff --git a/src/camera_system.cpp b/src/camera_system.cpp new file mode 100644 index 0000000..abeba86 --- /dev/null +++ b/src/camera_system.cpp @@ -0,0 +1,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; + } + } +} -- cgit 1.4.1