Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/include/chomper/runtimes/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "chomper/runtime.hpp"
#include "chomper/world.hpp"
#include <klib/ptr.hpp>
#include <le2d/drawable/text.hpp>
#include <le2d/input/action.hpp>
#include <le2d/input/scoped_mapping.hpp>

Expand Down Expand Up @@ -39,5 +40,8 @@ class Game : public IRuntime, public klib::Pinned {

std::unique_ptr<Player> m_player{};
std::unique_ptr<World> m_world{};

le::drawable::Text m_countdownText{};
kvf::Seconds m_countdown{3};
};
} // namespace chomper::runtime
20 changes: 18 additions & 2 deletions lib/src/runtimes/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,35 @@
#include <array>

namespace chomper::runtime {
namespace {
constexpr auto countdownParams_v = le::drawable::Text::Params{
.height = le::TextHeight{60},
};
}
using ActionValue = le::input::action::Value;

Game::Game(gsl::not_null<Engine*> engine) : m_engine(engine), m_mapping(&engine->getInputRouter()) {
createPlayer();
m_world = std::make_unique<World>(m_engine);

m_countdownText.set_string(engine->getResources().getMainFont(), "3", countdownParams_v);
}

void Game::tick(kvf::Seconds const dt) {
m_player->tick(dt);

ImGui::SetNextWindowSize({300.0f, 300.0f}, ImGuiCond_Once);
if (ImGui::Begin("Debug Inspect")) {
debugInspectWindow();
}
ImGui::End();

if (m_countdown.count() > 0) {
m_countdown -= dt;
m_countdownText.set_string(m_engine->getResources().getMainFont(), std::format("{}", static_cast<int>(m_countdown.count() + 1)), countdownParams_v);
return;
}

m_player->tick(dt);

// On death
if (!m_player->getInfo().alive) {
m_engine->setNextRuntime<runtime::Entrypoint>();
Expand All @@ -29,6 +42,9 @@ void Game::tick(kvf::Seconds const dt) {
void Game::render(le::IRenderer& renderer) const {
m_world->draw(renderer);
m_player->draw(renderer);
if (m_countdown.count() > 0) {
m_countdownText.draw(renderer);
}
}

void Game::debugInspectWindow() {
Expand Down