diff --git a/assets/Jersey10-Regular.ttf b/assets/Jersey10-Regular.ttf new file mode 100644 index 0000000..42ac920 Binary files /dev/null and b/assets/Jersey10-Regular.ttf differ diff --git a/src/Game.cpp b/src/Game.cpp index 56a45b0..f6ea337 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -6,6 +6,7 @@ #include "Game.hpp" #include "Color.hpp" #include "effects/Particle.hpp" +#include "effects/GoldGainedHint.hpp" using namespace std::literals::chrono_literals; @@ -15,7 +16,8 @@ Game::Game() : renderer("Zombo Shooter", 800, 450), player(&renderer), map(&rend zombo_sprite = renderer.load_sprite("./assets/zombo.png", 40, 40); gold_sprite = renderer.load_sprite("./assets/gold.png", 30, 20); - font = renderer.load_font("./assets/Jersey20-Regular.ttf", 26); + small_font = renderer.load_font("./assets/Jersey10-Regular.ttf", 20); + normal_font = renderer.load_font("./assets/Jersey20-Regular.ttf", 26); } void Game::update(std::stop_token stop_token) @@ -75,8 +77,10 @@ void Game::update(std::stop_token stop_token) std::erase(arrows, arrow); if (zombo.hp == 0) { - std::erase(zombos, zombo); player.gold += 10; + effects.push_back(std::make_unique(zombo.x, zombo.y, 10, gold_sprite.get(), small_font)); + + std::erase(zombos, zombo); } } } @@ -120,9 +124,9 @@ void Game::draw() renderer.draw_sprite(*gold_sprite, renderer.screen_width - 50, 10); - int text_width = renderer.get_text_width(font, std::to_string(player.gold)); - renderer.draw_text(font, std::to_string(player.gold), renderer.screen_width - gold_sprite->width - text_width - 28, 10, rgb(0, 0, 0)); - renderer.draw_text(font, std::to_string(player.gold), renderer.screen_width - gold_sprite->width - text_width - 30, 8, rgb(255, 255, 255)); + int text_width = renderer.get_text_width(normal_font, std::to_string(player.gold)); + renderer.draw_text(normal_font, std::to_string(player.gold), renderer.screen_width - gold_sprite->width - text_width - 28, 10, rgb(0, 0, 0)); + renderer.draw_text(normal_font, std::to_string(player.gold), renderer.screen_width - gold_sprite->width - text_width - 30, 8, rgb(255, 255, 255)); renderer.flush(); } diff --git a/src/Game.hpp b/src/Game.hpp index 3dc7c3a..02b3451 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -20,7 +20,7 @@ private: std::vector zombos; std::vector> effects; std::unique_ptr arrow_sprite, zombo_sprite, gold_sprite; - Font *font; + Font *small_font, *normal_font; std::mutex game_mutex; unsigned int ticks = 0; diff --git a/src/effects/Effect.hpp b/src/effects/Effect.hpp index 3fe2414..403edf3 100644 --- a/src/effects/Effect.hpp +++ b/src/effects/Effect.hpp @@ -14,6 +14,8 @@ public: virtual void update() = 0; virtual void draw(const GameRenderer *renderer, double player_x, double player_y) const = 0; + + bool operator==(const Effect &other) const = default; }; #endif diff --git a/src/effects/GoldGainedHint.cpp b/src/effects/GoldGainedHint.cpp index 61c59db..0ea3baf 100644 --- a/src/effects/GoldGainedHint.cpp +++ b/src/effects/GoldGainedHint.cpp @@ -1,3 +1,4 @@ +#include #include "GoldGainedHint.hpp" GoldGainedHint::GoldGainedHint(double x, double y, int amount, const Sprite *gold_sprite, Font *font) @@ -8,10 +9,24 @@ GoldGainedHint::GoldGainedHint(double x, double y, int amount, const Sprite *gol void GoldGainedHint::update() { + ticks++; y--; } void GoldGainedHint::draw(const GameRenderer *renderer, double player_x, double player_y) const { + std::string text = std::format("+{}", amount); + int draw_x = (int)(x + renderer->screen_width / 2 - player_x); + int draw_y = (int)(y + renderer->screen_height / 2 - player_y); + int draw_width = gold_sprite->width + 5 + renderer->get_text_width(font, text); + + renderer->draw_sprite(*gold_sprite, draw_x - draw_width / 2, draw_y); + + renderer->draw_text( + font, text, + draw_x - draw_width / 2 + gold_sprite->width + 5, + draw_y - 2, + rgb(255, 255, 255) + ); }