Newer
Older
/*
* 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 27/08/22.
//
#ifndef FGGL_DEMO_INCLUDE_GRID_HPP
#define FGGL_DEMO_INCLUDE_GRID_HPP
#include <memory>
#include "fggl/scenes/game.hpp"
#include "fggl/entity/gridworld/zone.hpp"
#include "fggl/animation/animator.hpp"
#include "fggl/gui/gui.hpp"
namespace demo {
constexpr int GRID_SIZE = 255;
using DemoGrid = fggl::entity::grid::Area2D<GRID_SIZE, GRID_SIZE>;
struct LevelRules {
fggl::math::vec2i startingPos;
uint32_t startingDirection;
uint32_t startingPower;
};
struct CellPos {
fggl::math::vec2i pos;
uint8_t direction;
fggl::math::vec2f drawOffset{0.0F, 0.0F};
float rotationOffset{0.0F};
struct Program {
std::vector<std::function<void(void)>> m_instructions;
uint32_t m_currInstruction;
bool playing = false;
};
struct RobotState {
uint32_t power = 64;
};
class GridScene : public fggl::scenes::GameBase {
public:
explicit GridScene(fggl::App& app);
void activate() override;
void deactivate() override;
void render(fggl::gfx::Graphics& gfx) override;
private:
fggl::entity::grid::TileSet m_tiles;
fggl::animation::FrameAnimator m_animator;
std::unique_ptr<DemoGrid> m_grid;
fggl::entity::EntityID m_player = fggl::entity::INVALID;
Program m_program;
inline void forward() {
auto& cell = m_grid->entities().get<CellPos>(m_player);
fggl::math::vec2i moveDir{0,0};
if ( cell.direction == 0) {
moveDir.y = 1;
} else if (cell.direction == 1) {
moveDir.x = 1;
} else if (cell.direction == 2) {
moveDir.y = -1;
} else if (cell.direction == 3) {
moveDir.x = -1;
}
cell.pos += moveDir;
}
inline void rotate(bool clockwise) {
auto& cell = m_grid->entities().get<CellPos>(m_player);
int direction = clockwise ? +1 : -1;
cell.direction = (cell.direction + 4 + direction) % 4;
}
};
}
#endif //FGGL_DEMO_INCLUDE_GRID_HPP