diff --git a/demo/demo/grid.cpp b/demo/demo/grid.cpp index f600861913cd0b5973f38f1dc33bfe92d29cc2ec..72aef7cefe411ededc3c8b65399d5c9d822bbe10 100644 --- a/demo/demo/grid.cpp +++ b/demo/demo/grid.cpp @@ -29,7 +29,25 @@ namespace demo { fggl::debug::log(fggl::debug::Level::info, "GridScene::activate()"); // create the grid world + fggl::entity::grid::FloorTile empty{fggl::entity::grid::FloorTile::IMPOSSIBLE, fggl::gfx::colours::BLACK}; + fggl::entity::grid::FloorTile ground{1, fggl::gfx::colours::GREEN}; + m_tiles.m_floors.push_back(empty); + m_tiles.m_floors.push_back(ground); + + fggl::entity::grid::WallTile noWall{}; + m_tiles.m_walls.push_back(noWall); + m_grid = std::make_unique<fggl::entity::grid::Area2D<255,255>>(m_tiles); + + // create a small area to use + for (int i=3; i<20; ++i) { + auto& walls = m_grid->wallAt(i, 3, true); + + for (int j=3; j<20; ++j) { + m_grid->setFloorAt(i, j, 1); + } + } + } void GridScene::deactivate() { @@ -44,12 +62,9 @@ namespace demo { for (int i=0; i <= 31; ++i) { for (int j=0; j <= 31; ++j) { auto& cell = grid.floorAt(i, j); + fggl::math::vec2 drawPos{i * DRAW_SIZE, j*DRAW_SIZE}; - float x = i * DRAW_SIZE; - float y = j * DRAW_SIZE; - auto colour = (i + j) % 2 == 0 ? fggl::gfx::colours::WHITE : fggl::gfx::colours::BLACK; - - fggl::gfx::Path2D tileGfx = fggl::gfx::make_rect({x,y}, {DRAW_HALF, DRAW_HALF}, colour); + fggl::gfx::Path2D tileGfx = fggl::gfx::make_rect(drawPos, {DRAW_HALF, DRAW_HALF}, cell.colour); paint.fill(tileGfx); } } @@ -68,6 +83,12 @@ namespace demo { paint.fill(hexTest); } + // draw with edges + for (int sides = 3; sides <= 25; ++sides) { + auto hexTest = fggl::gfx::make_shape(fggl::math::vec2{sides, 6} * DRAW_SIZE, DRAW_HALF, sides, {1.0F - (sides / 25.0F), 0.0f, sides / 25.0f}); + paint.stroke(hexTest); + } + // draw test arcs for (int sides = 0; sides < 12; ++sides) { float endAngle = progress * (M_PI * 2); @@ -79,6 +100,23 @@ namespace demo { paint.fill(hexTest); } + // draw sweep + for (int sides = 2; sides <= 25; ++sides){ + float angle = progress * (M_PI * 2); + float sliceSize = 1 / (float)sides * (M_PI * 2); + + float startAngle = angle; + float endAngle = startAngle + sliceSize; + + auto hexTest = fggl::gfx::make_arc(fggl::math::vec2{sides + 3, 8} * DRAW_SIZE, + DRAW_HALF, + startAngle, + endAngle, + fggl::gfx::colours::CYAN); + paint.fill(hexTest); + } + + progress += 0.01F; if ( progress > 1.0F) { progress = 0.0F; diff --git a/include/fggl/entity/gridworld/zone.hpp b/include/fggl/entity/gridworld/zone.hpp index 720b845bc119afc2f260ecabb74824a3ef82aef7..4315cae21c2d7726854ece4258ef692659501404 100644 --- a/include/fggl/entity/gridworld/zone.hpp +++ b/include/fggl/entity/gridworld/zone.hpp @@ -39,6 +39,10 @@ namespace fggl::entity::grid { return m_cells[getCellIndex(pos)]; } + inline void set(math::vec2i pos, T value) { + m_cells[getCellIndex(pos)] = value; + } + inline bool inBounds(math::vec2i pos) const { return 0 <= pos.x && pos.x <= size.x && 0 <= pos.y && pos.y <= size.y; @@ -58,10 +62,21 @@ namespace fggl::entity::grid { struct FloorTile { constexpr static uint8_t IMPOSSIBLE = 0; uint8_t moveCost = IMPOSSIBLE; + math::vec3 colour; + }; + + struct WallTile { + + }; + + struct WallState { + uint32_t wallNorth; + uint32_t wallWest; }; struct TileSet { std::vector<FloorTile> m_floors; + std::vector<WallTile> m_walls; }; /** @@ -76,7 +91,23 @@ namespace fggl::entity::grid { inline explicit Area2D(TileSet& tiles) : m_tiles(tiles) {} inline FloorTile& floorAt(uint32_t x, uint32_t y) { - return m_tiles.m_floors[ m_floors.at({x, y}) ]; + return m_tiles.m_floors.at( m_floors.at({x, y}) ); + } + + inline void setFloorAt(uint32_t x, uint32_t y, uint32_t floor) { + m_floors.set({x, y}, floor); + } + + inline WallTile& wallAt(uint32_t x, uint32_t y, bool north) { + if (north) { + return m_tiles.m_walls.at(m_walls.at({x, y}).wallNorth); + } else { + return m_tiles.m_walls.at(m_walls.at({x, y}).wallWest); + } + } + + inline void setWallAt(uint32_t x, uint32_t y, uint32_t wall) { + m_walls.set({x, y}, wall); } inline bool canMove(math::vec2i pos) const { @@ -99,7 +130,7 @@ namespace fggl::entity::grid { private: TileSet& m_tiles; Grid<uint32_t, width, height> m_floors; - Grid<uint32_t, width + 1, height + 1> m_walls; + Grid<WallState, width + 1, height + 1> m_walls; }; } // namespace fggl::entity::gridworld