diff --git a/include/Camera.hpp b/include/Camera.hpp index 56a21029..181bee61 100644 --- a/include/Camera.hpp +++ b/include/Camera.hpp @@ -14,7 +14,6 @@ constexpr float FOV_LOWER_LIMIT = 1.F; class CameraClass { public: CameraClass() { setPosition(glm::vec2(0, 0)); } - CameraClass(glm::vec2 position) { setPosition(position); } ~CameraClass() {} static float getCameraZoom() { return m_Zoom; } @@ -24,7 +23,7 @@ class CameraClass { static glm::vec2 getPosition() { return m_Position; } - void setPosition(glm::vec2 position) { m_Position = position; } + void setPosition(glm::vec2 position); static glm::mat4x4 getProjectionMatrix() { @@ -47,7 +46,7 @@ class CameraClass { float getZoomingSpeed() { return m_ZoomingSpeed; } void changeFOV(float offset); - void Start(); + void Start(glm::vec2 minPosition, glm::vec2 maxPosition); void Update(); void UpdateWhenCursorAtBoarder(); void UpdateWhenCursorScroll(); @@ -60,6 +59,8 @@ class CameraClass { static float m_Fov; static glm::vec2 s_boarderMaximum; static glm::vec2 s_boarderMinimum; + glm::vec2 m_minPosition; + glm::vec2 m_maxPosition; }; #endif // PRACTICALTOOLSFORSIMPLEDESIGN_CAMERA_HPP diff --git a/include/Cursor.hpp b/include/Cursor.hpp index 26231e98..fe79ca4c 100644 --- a/include/Cursor.hpp +++ b/include/Cursor.hpp @@ -15,7 +15,7 @@ class CursorClass { DrawOverlays::OverlayShapes::R_CROSS); } ~CursorClass() {} - void Start(std::shared_ptr map) { m_Map = map; } + void Start() {} void Update(std::shared_ptr tile) { if (m_showWalkable) { @@ -63,16 +63,6 @@ class CursorClass { } } - std::vector getCursorSelectionRegionInCell() { - std::vector region = { - - MapUtil::GlobalCoordToCellCoord( - glm::vec2(start_pos.x, start_pos.y)), - MapUtil::GlobalCoordToCellCoord(glm::vec2(end_pos.x, end_pos.y))}; - - return region; - } - void setShowWalkable(bool value) { m_showWalkable = value; } void setShowBuildable(bool value) { m_showBuildable = value; } diff --git a/include/Mechanics/GameObjectManager.hpp b/include/Mechanics/GameObjectManager.hpp index 3af52270..9b65f21f 100644 --- a/include/Mechanics/GameObjectManager.hpp +++ b/include/Mechanics/GameObjectManager.hpp @@ -101,14 +101,6 @@ class GameObjectManager { } } - static bool ifObjectClicked(glm::vec2 objpos, glm::vec2 objsize, - glm::vec2 mousestart, glm::vec2 mouseend) { - mousestart = MapUtil::GlobalCoordToCellCoord(mousestart); - mouseend = MapUtil::GlobalCoordToCellCoord(mouseend); - objpos = MapUtil::GlobalCoordToCellCoord(objpos); - return (mousestart == objpos); - } - void Append(std::shared_ptr newstruct) { m_BuiltStructure.push_back(newstruct); m_Map->AppendSelectableObjectByCellPosition( diff --git a/include/Scene/DefaultScene.hpp b/include/Scene/DefaultScene.hpp index 8124f492..ee9e0f8a 100644 --- a/include/Scene/DefaultScene.hpp +++ b/include/Scene/DefaultScene.hpp @@ -4,12 +4,13 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_DEFAULTSCENE_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_DEFAULTSCENE_HPP - #include "Cursor.hpp" #include "Scene.hpp" #include "Unit/Avatar.hpp" #include "Unit/Hunter.hpp" #include "Unit/Runner.hpp" +#include + class DefaultScene : public Scene { public: diff --git a/include/Scene/Scene.hpp b/include/Scene/Scene.hpp index d7ff9354..5d1a41fa 100644 --- a/include/Scene/Scene.hpp +++ b/include/Scene/Scene.hpp @@ -45,12 +45,9 @@ class Scene { */ virtual void Update() = 0; - CameraClass getCamera() { return m_SceneCamera; }; - protected: - CameraClass m_SceneCamera; std::shared_ptr m_Map = std::make_shared(); - + CameraClass m_SceneCamera; std::shared_ptr m_GameObjectManager = std::make_shared(); Util::Renderer m_Renderer; diff --git a/src/Camera.cpp b/src/Camera.cpp index 047c1726..fb1f81b5 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -8,13 +8,25 @@ glm::vec2 CameraClass::m_Position(glm::vec2(0, 0)); float CameraClass::m_Zoom = 1.F; float CameraClass::m_Fov = FOV_UPPER_LIMIT; -void CameraClass::Start() {} +void CameraClass::Start(glm::vec2 minPosition, glm::vec2 maxPosition) { + m_minPosition = minPosition; + m_maxPosition = maxPosition; +} void CameraClass::Update() { UpdateWhenCursorAtBoarder(); UpdateWhenCursorScroll(); } +void CameraClass::setPosition(glm::vec2 position) { + if (position.x >= m_minPosition.x && position.x <= m_maxPosition.x) { + m_Position.x = position.x; + } + if (position.y >= m_minPosition.y && position.y <= m_maxPosition.y) { + m_Position.y = position.y; + } +} + void CameraClass::UpdateWhenCursorAtBoarder() { // TODO: where to put is cursor at boarder?? int cursorAtBoarder = Core::Context::IsCurosrAtBoarder(); diff --git a/src/Scene/DefaultScene.cpp b/src/Scene/DefaultScene.cpp index c27d0f76..ff2abe4b 100644 --- a/src/Scene/DefaultScene.cpp +++ b/src/Scene/DefaultScene.cpp @@ -22,6 +22,8 @@ void DefaultScene::Start() { // m_Cursor.Start(m_Map); m_UI.Start(m_Map, m_Player, m_GameObjectManager); m_Player->setTotalCurrency(5000); + m_SceneCamera.Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)), + MapUtil::CellCoordToGlobal(glm::vec2(100, 100))); // m_hunter->setCurrentCell({20,10}); // m_runner->setCurrentCell({10,10}); diff --git a/src/Scene/MapScene.cpp b/src/Scene/MapScene.cpp index ee15134b..bd95cad8 100644 --- a/src/Scene/MapScene.cpp +++ b/src/Scene/MapScene.cpp @@ -5,10 +5,11 @@ #include "DrawOverlays.hpp" #include void MapScene::Start() { - // m_Map->Init(204, 161); m_Map->Init( MapBinReader::readBin("../assets/map/green-belt/map.bin", 98, 98), 98, 98); + m_SceneCamera.Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)), + MapUtil::CellCoordToGlobal(glm::vec2(98, 98))); } void MapScene::Update() {