Skip to content
Snippets Groups Projects
Commit 26080389 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

don't bother loading 3D stuff for 2D scenes

parent 5b549d1e
No related branches found
No related tags found
No related merge requests found
......@@ -90,14 +90,15 @@ namespace demo {
auto player = manager.create();
auto& cellPos = manager.add<CellPos>(player);
cellPos.pos = {5,5};
cellPos.direction = 1;
}
}
GridScene::GridScene(fggl::App &app) : Game(app), m_tiles(), m_grid(nullptr) {
GridScene::GridScene(fggl::App &app) : GameBase(app), m_tiles(), m_grid(nullptr) {
}
void GridScene::activate() {
Game::activate();
GameBase::activate();
fggl::debug::log(fggl::debug::Level::info, "GridScene::activate()");
......@@ -164,16 +165,18 @@ namespace demo {
// convert grid pos to world pos
fggl::math::vec2f drawPos = cellPos.pos;
drawPos *= DRAW_SIZE;
drawPos += cellPos.drawOffset;
auto shape = fggl::gfx::make_shape(drawPos, DRAW_HALF, 3);
fggl::gfx::ShapeOpts opts;
opts.angleOffset = (float)cellPos.direction * fggl::math::HALF_PI + cellPos.rotationOffset;
auto shape = fggl::gfx::make_shape(drawPos, DRAW_HALF, 3, NAVAJO_WHITE, opts);
paint.fill(shape);
}
}
//float progress = 0.0f;
void GridScene::render(fggl::gfx::Graphics &gfx) {
Game::render(gfx);
fggl::gfx::Paint paint;
render_grid(paint, *m_grid);
render_objects(paint, *m_grid);
......
......@@ -35,9 +35,13 @@ namespace demo {
struct CellPos {
fggl::math::vec2i pos;
uint8_t direction;
fggl::math::vec2f drawOffset{0.0F, 0.0F};
float rotationOffset{0.0F};
};
class GridScene : public fggl::scenes::Game {
class GridScene : public fggl::scenes::GameBase {
public:
explicit GridScene(fggl::App& app);
void activate() override;
......
......@@ -24,6 +24,20 @@
namespace fggl::scenes {
GameBase::GameBase(fggl::App& app) : AppState(app) {
m_input = app.service<input::Input>();
}
void GameBase::update() {
// detect the user quitting
if (m_input != nullptr) {
bool escapePressed = m_input->keyboard.pressed(glfwGetKeyScancode(GLFW_KEY_ESCAPE));
if (escapePressed) {
m_owner.change_state(m_previous);
}
}
}
Game::Game(fggl::App &app) : AppState(app) {
m_input = app.service<input::Input>();
}
......
......@@ -25,6 +25,25 @@
namespace fggl::scenes {
class GameBase : public fggl::AppState {
public:
explicit GameBase(fggl::App &app);
void update() override;
void render(fggl::gfx::Graphics &gfx) override = 0;
protected:
inline auto input() -> input::Input & {
return *m_input;
}
private:
input::Input *m_input;
std::string m_previous = "menu";
};
class Game : public fggl::AppState {
public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment