From 5b4db2eb5bae4c658bd18fe5e610a8f3e40f4630 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Sun, 26 Feb 2023 12:54:38 +0000 Subject: [PATCH] extract magic numbers from hexboard into constants --- demo/demo/hexboard/board.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/demo/demo/hexboard/board.cpp b/demo/demo/hexboard/board.cpp index 4e39ba9..fafd6fd 100644 --- a/demo/demo/hexboard/board.cpp +++ b/demo/demo/hexboard/board.cpp @@ -19,31 +19,34 @@ #include "hexboard/scene.hpp" namespace demo::hexboard { + constexpr float SCROLL_SPEED = 0.01F; + constexpr float HEX_SIZE = 64.0F; + constexpr std::array<fggl::grid::IntHex, 4> ISLAND_CENTERS {{ + {2, 3}, + {6, 7}, + {9, 10}, + {6, 3} + }}; + Scene::Scene(fggl::App &app) : GameBase(app), m_board(nullptr), m_screen(1920.F, 1080.F) { } void Scene::activate() { m_board = std::make_unique<fggl::grid::HexGrid>(); - m_layout = std::make_unique<fggl::grid::Layout>( fggl::grid::Orientation::make_pointy(), 64.0F ); + m_layout = std::make_unique<fggl::grid::Layout>( fggl::grid::Orientation::make_pointy(), HEX_SIZE ); //m_layout->m_origin = { 1920.0F * -0.5F, 1080.0F * -0.5F}; m_selections = std::make_unique<SelectionModel>(); - fggl::grid::TerrainType grass{ + const fggl::grid::TerrainType grass{ .data = std::make_shared<fggl::grid::MaterialData>() }; grass.data->name = "grass"; grass.data->colour = {0.0F, 1.0F, 0.0}; - std::array<fggl::grid::IntHex, 4> islands {{ - {3, 3}, - {7, 7}, - {10, 10}, - {7, 3} - }}; - for (auto islandPoint : islands){ + for (auto islandPoint : ISLAND_CENTERS){ auto island = islandPoint.hexesInRange(2); for (auto &hex : island) { m_board->setTerrain(hex, grass); @@ -88,7 +91,7 @@ namespace demo::hexboard { } auto offset = screenPos - m_dragging.value(); - m_camera->teleportBy(offset * 0.01F); + m_camera->teleportBy(offset * SCROLL_SPEED); } else if ( input.mouse.released(fggl::input::MouseButton::RIGHT) ) { m_dragging = {}; } -- GitLab