From 52342ac7548dd7e1facbe9946ab38f56541d14c5 Mon Sep 17 00:00:00 2001 From: Joseph Walton-Rivers <joseph@walton-rivers.uk> Date: Sat, 10 Dec 2022 15:28:30 +0000 Subject: [PATCH] start of 2D game stuff --- demo/CMakeLists.txt | 1 + demo/demo/hexboard/board.cpp | 54 +++++++++++++++++++++++++++++++++ demo/demo/main.cpp | 6 ++-- demo/include/hexboard/board.hpp | 34 +++++++++++++++++++++ demo/include/hexboard/scene.hpp | 45 +++++++++++++++++++++++++++ include/fggl/gfx/paint.hpp | 2 +- include/fggl/grid/hexgrid.hpp | 32 +++++++++++++++++++ 7 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 demo/demo/hexboard/board.cpp create mode 100644 demo/include/hexboard/board.hpp create mode 100644 demo/include/hexboard/scene.hpp create mode 100644 include/fggl/grid/hexgrid.hpp diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 3309c22..c8acffb 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 0000000..40bf199 --- /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 4e736d2..7960f63 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 0000000..b4aa55e --- /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 0000000..0ded844 --- /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 c0a1eff..6ffaad3 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 0000000..31a36fa --- /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 -- GitLab