From 9948ffafbf9cb897742b5010a4bb09ff735d51d1 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 31 Jan 2023 01:31:14 +0100 Subject: Added stub Grid and Camera --- kurator/CMakeLists.txt | 1 + kurator/src/Battle.cpp | 4 ++++ kurator/src/Battle.h | 2 ++ kurator/src/Camera.h | 17 +++++++++++++++++ kurator/src/Grid.cpp | 32 ++++++++++++++++++++++++++++++++ kurator/src/Grid.h | 17 +++++++++++++++++ 6 files changed, 73 insertions(+) create mode 100644 kurator/src/Camera.h create mode 100644 kurator/src/Grid.cpp create mode 100644 kurator/src/Grid.h diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index c547acd..283d84e 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -6,6 +6,7 @@ add_executable( src/Campaign.cpp src/colors.cpp src/ForceBalance.cpp + src/Grid.cpp src/main.cpp src/Pause.cpp src/PopupEmitter.cpp diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 8073585..74f40f8 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -19,8 +19,10 @@ #include #include +#include "Camera.h" #include "colors.h" #include "components.h" +#include "Grid.h" #include "Pause.h" #include "PopupEmitter.h" #include "Session.h" @@ -71,6 +73,7 @@ Battle::update(const float dt) { if (IsKeyPressed(KEY_ESCAPE)) return session->set(std::make_shared(session, session->current())); + camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); battle->update(dt * time_factor); auto& registry = battle->registry(); auto timers = registry.view(); @@ -125,6 +128,7 @@ Battle::draw() const const int hwidth = GetScreenWidth() / 2; const int hheight = GetScreenHeight() / 2; const double scale = std::min(hwidth/15000.0, hheight/15000.0); + Grid().draw(camera); auto& registry = battle->registry(); auto crosses = registry.view(); for (const auto& [entity, transform, cross] : crosses.each()) { diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h index 7a48e21..e7813d7 100644 --- a/kurator/src/Battle.h +++ b/kurator/src/Battle.h @@ -9,6 +9,7 @@ #include #include +#include "Camera.h" #include "ForceBalance.h" #include "Scene.h" #include "Session.h" @@ -34,6 +35,7 @@ public: private: std::shared_ptr session; std::unique_ptr battle; + Camera camera; ForceBalance balance; stats::EventLog log; float time_factor; diff --git a/kurator/src/Camera.h b/kurator/src/Camera.h new file mode 100644 index 0000000..b6ca7d1 --- /dev/null +++ b/kurator/src/Camera.h @@ -0,0 +1,17 @@ +#pragma once + +#include + + +namespace kurator +{ + + +struct Camera +{ + sim::Point offset = {}; + double scale = 1.0; +}; + + +} // namespace kurator diff --git a/kurator/src/Grid.cpp b/kurator/src/Grid.cpp new file mode 100644 index 0000000..53f7b47 --- /dev/null +++ b/kurator/src/Grid.cpp @@ -0,0 +1,32 @@ +#include "Grid.h" + +#include + +#include "Camera.h" + + +namespace kurator +{ + + +void +Grid::draw(const Camera& camera) const +{ + const int width = GetScreenWidth(); + const int height = GetScreenHeight(); + DrawLine( + width/2 - camera.offset.x*camera.scale, + 0, + width/2 - camera.offset.x*camera.scale, + height, + DARKGRAY); + DrawLine( + 0, + height/2 - camera.offset.y*camera.scale, + width, + height/2 - camera.offset.y*camera.scale, + DARKGRAY); +} + + +} // namespace kurator diff --git a/kurator/src/Grid.h b/kurator/src/Grid.h new file mode 100644 index 0000000..cf9a00d --- /dev/null +++ b/kurator/src/Grid.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Camera.h" + + +namespace kurator +{ + + +class Grid +{ +public: + void draw(const Camera& camera) const; +}; + + +} // namespace kurator -- cgit v1.1