Add gold gained effect on kill
This commit is contained in:
parent
2508658a75
commit
bfa0105ebf
BIN
assets/Jersey10-Regular.ttf
Normal file
BIN
assets/Jersey10-Regular.ttf
Normal file
Binary file not shown.
14
src/Game.cpp
14
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<GoldGainedHint>(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();
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ private:
|
||||
std::vector<Zombo> zombos;
|
||||
std::vector<std::unique_ptr<Effect>> effects;
|
||||
std::unique_ptr<Sprite> arrow_sprite, zombo_sprite, gold_sprite;
|
||||
Font *font;
|
||||
Font *small_font, *normal_font;
|
||||
|
||||
std::mutex game_mutex;
|
||||
unsigned int ticks = 0;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#include <format>
|
||||
#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)
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user