Score Manager
First User Interface
The score manager component is responsible for maintaining the player's score, which is represented as an integer. Additionally, it handles the rendering of this score as centered text at the top of the game window. As the initial UI element in the game, its implementation will require some attention.
#pragma once
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Text.hpp>
#include <cstdint>
#include "engine/node.h"
namespace game {
class ScoreManager : public ng::Node {
public:
explicit ScoreManager(ng::App* app);
void AddScore(int32_t score);
protected:
void Update() override;
void Draw(sf::RenderTarget& target) override;
private:
void UpdateUI();
sf::Text score_text_;
int32_t score_ = 0;
};
} // namespace gameThe Player is responsible for increasing the score managed by the ScoreManager whenever it collides with specific designated objects in the game world.
Last updated