From 3c238651c8c98ca9948ea24017ac5c0d388e8b95 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Mon, 12 Dec 2022 09:04:00 +0000 Subject: [PATCH] make use of board object --- demo/demo/hexboard/board.cpp | 17 ++++++++++------- include/fggl/grid/hexgrid.hpp | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/demo/demo/hexboard/board.cpp b/demo/demo/hexboard/board.cpp index 4c8c1c5..1748265 100644 --- a/demo/demo/hexboard/board.cpp +++ b/demo/demo/hexboard/board.cpp @@ -52,9 +52,9 @@ namespace demo::hexboard { void Scene::render(fggl::gfx::Graphics &gfx) { // if the board is not set, abort - /*if ( m_board == nullptr ){ + if ( m_board == nullptr ){ return; - }*/ + } // draw the grid // FIXME don't hard-code the screen size @@ -72,12 +72,15 @@ namespace demo::hexboard { auto rowBasis = hexPos; for(auto i=0; i<gridHeight; ++i) { for (auto j=0; j<gridWidth; ++j) { - auto pos = hexToScreen(hexPos, hexRadius, offset); - auto hex = fggl::gfx::make_shape(pos, hexRadius, 6); - paint.stroke(hex); - pos.x += hexRadius; - hexPos = hexPos.neighbour( fggl::grid::HexDirPointy::RIGHT ); + if ( m_board->isValidPos(hexPos) ) { + auto pos = hexToScreen(hexPos, hexRadius, offset); + auto hexShape = fggl::gfx::make_shape(pos, hexRadius, 6); + paint.stroke(hexShape); + } + + // next hexagon + hexPos = hexPos.neighbour(fggl::grid::HexDirPointy::RIGHT); } rowBasis = i % 2 == 0 ? rowBasis.neighbour(fggl::grid::HexDirPointy::BOTTOM_RIGHT) : rowBasis.neighbour(fggl::grid::HexDirPointy::BOTTOM_LEFT); diff --git a/include/fggl/grid/hexgrid.hpp b/include/fggl/grid/hexgrid.hpp index 31a36fa..ae948db 100644 --- a/include/fggl/grid/hexgrid.hpp +++ b/include/fggl/grid/hexgrid.hpp @@ -24,7 +24,10 @@ namespace fggl::grid { class HexGrid { - + public: + inline bool isValidPos(const IntHex& pos) { + return true; + } }; } // namespace fggl::grid -- GitLab