Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Score font #19

Merged
merged 13 commits into from
Oct 21, 2022
3 changes: 3 additions & 0 deletions assets/fonts/ThaleahFat.ttf
Git LFS file not shown
2 changes: 1 addition & 1 deletion assets/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"nodes": [
{
"type": "file",
"filename": "scenes/load.scene"
"filename": "scenes/game.scene"
},
{
"type": "model",
Expand Down
2 changes: 2 additions & 0 deletions src/engine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#include <core/scene.hpp>
#include <core/system.hpp>
#include <core/view.hpp>
#include <imgui.hpp>
#include <engine/plugin.hpp>
#include <plugin.hpp>
#include <resource/resource_loader.hpp>
#include <system/sdl_input_manager.hpp>
#include <vk/font_manager.hpp>
#include <vk/imgui_context.hpp>

// editor
Expand Down
34 changes: 32 additions & 2 deletions src/scenes/game.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
#include "scenes/game.hpp"
#include "game.hpp"

namespace lerppana::flappykarp::scenes
{}
{
void game::start()
{
if (!font_manager->fonts.contains("thaleah"))
{
font_manager->add_font(
"thaleah",
"fs1://fonts/ThaleahFat.ttf",
64);
}
}

void game::on_gui()
{
auto* font = font_manager->get_font("thaleah");
ImGui::SetWindowFontScale(1.0f);
ImGui::FontScope font_scope{font};

static auto width = 100.0f;
ImGui::SetCursorPos(ImVec2(ImGui::GetWindowWidth() / 2 - width / 2,0.f));

ImGui::GroupScope text_group;
ImGui::Text("%d", (uint32_t)score);
width = ImGui::GetItemRectSize().x;
}

void game::update(core::dt_t dt)
{
score += (dt.count()/1000.0f);
}
}
17 changes: 14 additions & 3 deletions src/scenes/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

namespace lerppana::flappykarp::scenes
{
struct game : core::scene
struct FLAPPYKARP_EXPORT game : core::scene
{
explicit game() :
core::scene("fs1://scenes/game.scene")
explicit game(std::shared_ptr<vk::font_manager> font_manager) :
engine::core::scene("fs1://scenes/game.scene"),
font_manager(std::move(font_manager))
{}

void start() final;

void update(core::dt_t dt) final;

void on_gui() final;
private:
std::shared_ptr<vk::font_manager> font_manager;

float score{};
};
}