summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-31 01:31:14 +0100
committerAki <please@ignore.pl>2023-01-31 01:31:14 +0100
commit9948ffafbf9cb897742b5010a4bb09ff735d51d1 (patch)
tree0c388581e08e62cc907c25cd10c7f1220528a21d
parent8f718662fcecd4fcf46057f01696ffa1373d4ac3 (diff)
downloadkurator-9948ffafbf9cb897742b5010a4bb09ff735d51d1.zip
kurator-9948ffafbf9cb897742b5010a4bb09ff735d51d1.tar.gz
kurator-9948ffafbf9cb897742b5010a4bb09ff735d51d1.tar.bz2
Added stub Grid and Camera
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp4
-rw-r--r--kurator/src/Battle.h2
-rw-r--r--kurator/src/Camera.h17
-rw-r--r--kurator/src/Grid.cpp32
-rw-r--r--kurator/src/Grid.h17
6 files changed, 73 insertions, 0 deletions
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 <kurator/universe/ShipType.h>
#include <kurator/universe/UniqueIdentifier.h>
+#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<Pause>(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<Timed>();
@@ -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<sim::Transform, Cross>();
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 <kurator/stats/EventLog.h>
#include <kurator/stats/events.h>
+#include "Camera.h"
#include "ForceBalance.h"
#include "Scene.h"
#include "Session.h"
@@ -34,6 +35,7 @@ public:
private:
std::shared_ptr<Session> session;
std::unique_ptr<sim::Battle> 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 <kurator/sim/Point.h>
+
+
+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 <raylib.h>
+
+#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