diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 3309c221a41bc91ee64a06bc2eaac0df330bf177..c8acffb26ab930a1f9e1b44118d69172b86c738f 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(demo demo/grid.cpp demo/robot/programmer.cpp demo/models/viewer.cpp + demo/hexboard/board.cpp ) target_include_directories(demo diff --git a/demo/demo/hexboard/board.cpp b/demo/demo/hexboard/board.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40bf199540fddd761861b3d18917f788a542b5a1 --- /dev/null +++ b/demo/demo/hexboard/board.cpp @@ -0,0 +1,54 @@ +/* + * This file is part of FGGL. + * + * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with FGGL. + * If not, see <https://www.gnu.org/licenses/>. + */ + +// +// Created by webpigeon on 10/12/22. +// + +#include "hexboard/scene.hpp" + +namespace demo::hexboard { + + Scene::Scene(fggl::App &app) : GameBase(app), m_board(nullptr) { + } + + void Scene::activate() { + m_board = std::make_unique<fggl::grid::HexGrid>(); + } + + void Scene::deactivate() { + m_board = nullptr; + } + + void Scene::update(float delta) { + GameBase::update(delta); + + // if the board is not set, abort + if ( m_board == nullptr ){ + return; + } + } + + void Scene::render(fggl::gfx::Graphics &gfx) { + // if the board is not set, abort + if ( m_board == nullptr ){ + return; + } + + // draw the grid + fggl::gfx::Paint paint; + gfx.draw2D(paint); + } + +} // namespace demo::hexboard \ No newline at end of file diff --git a/demo/demo/main.cpp b/demo/demo/main.cpp index 4e736d2f32dabc6e5341133c7f7ccccd2476d6eb..7960f63b65c42994c1bcc64d538468e03351e352 100644 --- a/demo/demo/main.cpp +++ b/demo/demo/main.cpp @@ -50,13 +50,14 @@ #include "topdown.hpp" #include "grid.hpp" #include "models/viewer.hpp" +#include "hexboard/scene.hpp" static void setup_menu(fggl::App& app) { auto *menu = app.addState<fggl::scenes::BasicMenu>("menu"); // add some menu items for the game states - const std::array labels = {"terrain", "rollball", "Top Down", "Grid World", "Viewer"}; - const std::array scenes = {"game", "rollball", "topdown", "gridworld", "viewer"}; + const std::array labels = {"terrain", "rollball", "Top Down", "Grid World", "Viewer", "gridworld"}; + const std::array scenes = {"game", "rollball", "topdown", "gridworld", "viewer", "hexboard"}; for (std::size_t i = 0; i < labels.size(); ++i) { std::string sceneName = scenes.at(i); @@ -131,6 +132,7 @@ int main(int argc, const char* argv[]) { app.addState<demo::TopDown>("topdown"); app.addState<demo::GridScene>("gridworld"); app.addState<demo::Viewer>("viewer"); + app.addState<demo::hexboard::Scene>("hexboard"); return app.run(argc, argv); } diff --git a/demo/include/hexboard/board.hpp b/demo/include/hexboard/board.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b4aa55eb549b897cc1429b6a5975eff577bba152 --- /dev/null +++ b/demo/include/hexboard/board.hpp @@ -0,0 +1,34 @@ +/* + * This file is part of FGGL. + * + * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with FGGL. + * If not, see <https://www.gnu.org/licenses/>. + */ + +// +// Created by webpigeon on 10/12/22. +// + +#ifndef FGGL_DEMO_INCLUDE_HEXBOARD_BOARD_HPP +#define FGGL_DEMO_INCLUDE_HEXBOARD_BOARD_HPP + +#include <cstdint> + +namespace demo::hexboard { + + constexpr uint64_t NO_SELECTION{0}; + + struct SelectionModel { + uint64_t m_hover = NO_SELECTION; + }; + +} // namespace demo::hexboard + +#endif //FGGL_DEMO_INCLUDE_HEXBOARD_BOARD_HPP diff --git a/demo/include/hexboard/scene.hpp b/demo/include/hexboard/scene.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0ded844c82ab02d80ce86b1dcef5f577a7c388e8 --- /dev/null +++ b/demo/include/hexboard/scene.hpp @@ -0,0 +1,45 @@ +/* + * This file is part of FGGL. + * + * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with FGGL. + * If not, see <https://www.gnu.org/licenses/>. + */ + +// +// Created by webpigeon on 10/12/22. +// + +#ifndef FGGL_DEMO_INCLUDE_HEXBOARD_SCENE_H +#define FGGL_DEMO_INCLUDE_HEXBOARD_SCENE_H + +#include <memory> + +#include "fggl/scenes/game.hpp" +#include "fggl/grid/hexgrid.hpp" + +namespace demo::hexboard { + + class Scene : public fggl::scenes::GameBase { + public: + explicit Scene(fggl::App& app); + + void activate() override; + void deactivate() override; + + void update(float delta) override; + void render(fggl::gfx::Graphics& gfx) override; + + private: + std::unique_ptr<fggl::grid::HexGrid> m_board; + }; + +} // namespace demo::hexboard + +#endif //FGGL_DEMO_INCLUDE_HEXBOARD_SCENE_H diff --git a/include/fggl/gfx/paint.hpp b/include/fggl/gfx/paint.hpp index c0a1effef3eaceba5740e153dca325a8bfdb661c..6ffaad3ce4e2b529c7afd28a18bb861059f5e6e4 100644 --- a/include/fggl/gfx/paint.hpp +++ b/include/fggl/gfx/paint.hpp @@ -225,7 +225,7 @@ namespace fggl::gfx { }; inline Path2D make_shape(math::vec2 center, float radius, int sides, math::vec3 colour = colours::WHITE, ShapeOpts opts = {}) { - float angle = (M_PI * 2.0F) / sides; + float angle = (math::PI * 2.0F) / sides; fggl::gfx::Path2D tileGfx(center); tileGfx.colour(colour); diff --git a/include/fggl/grid/hexgrid.hpp b/include/fggl/grid/hexgrid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..31a36facaa14b87adeefb948a0673139ea84a97d --- /dev/null +++ b/include/fggl/grid/hexgrid.hpp @@ -0,0 +1,32 @@ +/* + * This file is part of FGGL. + * + * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with FGGL. + * If not, see <https://www.gnu.org/licenses/>. + */ + +// +// Created by webpigeon on 10/12/22. +// + +#ifndef FGGL_GRID_HEXAGON_BOARD_HPP +#define FGGL_GRID_HEXAGON_BOARD_HPP + +#include "fggl/grid/hexagon.hpp" + +namespace fggl::grid { + + class HexGrid { + + }; + +} // namespace fggl::grid + +#endif //FGGL_GRID_HEXAGON_BOARD_HPP