r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
HUD.hpp
Go to the documentation of this file.
1///
2/// @file HUD.hpp
3/// @brief Heads-Up Display (HUD) system for R-Type multiplayer game
4/// @details This system manages the on-screen UI elements including score display,
5/// player statistics, and other game information overlays. It provides
6/// real-time visual feedback to the player during gameplay.
7/// @namespace gme
8/// @author R-Type Team
9/// @date 2025
10///
11
12#pragma once
13
16#include "Utils/Common.hpp"
17
18namespace gme
19{
20
21 ///
22 /// @class HUDSystem
23 /// @brief System responsible for rendering and updating the game's Heads-Up Display
24 /// @details This ECS system manages all HUD elements including:
25 /// - Score display with digit sprites
26 /// - Background elements for UI components
27 /// - Real-time score updates
28 ///
29 /// The HUD is created at initialization and updated each frame to reflect
30 /// the current game state. It uses sprite-based rendering for visual elements.
31 ///
32 /// @namespace gme
33 ///
34 class HUDSystem final : public ecs::ASystem
35 {
36 public:
37 ///
38 /// @brief Constructor - initializes the HUD system and creates initial UI elements
39 /// @param renderer Shared pointer to the renderer for drawing UI elements
40 /// @param registry Reference to the ECS registry for entity management
41 /// @details Automatically creates the score HUD at position (10, 10) upon construction
42 ///
43 explicit HUDSystem(const std::shared_ptr<eng::IRenderer> &renderer, ecs::Registry &registry)
44 : m_renderer(renderer), m_registry(registry)
45 {
46 createScoreHUD(m_registry, 10.0F, 10.0F);
47 }
48
49 ///
50 /// @brief Destructor
51 ///
52 ~HUDSystem() override = default;
53
54 ///
55 /// @brief Deleted copy constructor (non-copyable)
56 ///
57 HUDSystem(const HUDSystem &) = delete;
58
59 ///
60 /// @brief Deleted copy assignment operator (non-copyable)
61 ///
62 HUDSystem &operator=(const HUDSystem &) = delete;
63
64 ///
65 /// @brief Deleted move constructor (non-movable)
66 ///
67 HUDSystem(HUDSystem &&) = delete;
68
69 ///
70 /// @brief Deleted move assignment operator (non-movable)
71 ///
73
74 ///
75 /// @brief Update the HUD system (called each frame)
76 /// @param registry ECS registry containing all entities and components
77 /// @param dt Delta time (unused in current implementation)
78 /// @details Updates score display and other HUD elements based on current game state
79 ///
80 void update(ecs::Registry &registry, float /* dt */) override;
81
82 private:
83 ///
84 /// @brief Create the score display HUD elements
85 /// @param registry ECS registry for creating entities
86 /// @param x X-coordinate for the score display position
87 /// @param y Y-coordinate for the score display position
88 /// @details Creates background and digit entities for the score display.
89 /// Initializes the visual representation of the player's score.
90 ///
91 void createScoreHUD(ecs::Registry &registry, float x, float y);
92
93 ///
94 /// @brief Update the displayed score value
95 /// @param registry ECS registry containing score entities
96 /// @param newScore New score value to display
97 /// @details Updates the sprite indices of digit entities to reflect the new score.
98 /// Handles score formatting and digit separation.
99 ///
100 void updateScore(ecs::Registry &registry, int newScore) const;
101
102 const std::shared_ptr<eng::IRenderer> &m_renderer; ///< Renderer for drawing HUD elements
103 ecs::Registry &m_registry; ///< ECS registry reference
104 ecs::Entity m_scoreBgEntity{}; ///< Entity for score background sprite
105 std::vector<ecs::Entity> m_scoreDigitEntities; ///< Entities for individual score digits
106 }; // class HUDSystem
107
108} // namespace gme
This file contains the IRenderer class declaration.
This file contains the interface for systems.
Abstract class for system.
Definition ISystems.hpp:34
Class for managing entities and their components.
Definition Registry.hpp:25
System responsible for rendering and updating the game's Heads-Up Display.
Definition HUD.hpp:17
void update(ecs::Registry &registry, float) override
Update the HUD system (called each frame)
Definition HUD.cpp:64
ecs::Registry & m_registry
ECS registry reference.
Definition HUD.hpp:103
void updateScore(ecs::Registry &registry, int newScore) const
Update the displayed score value.
Definition HUD.cpp:29
std::vector< ecs::Entity > m_scoreDigitEntities
Entities for individual score digits.
Definition HUD.hpp:105
HUDSystem & operator=(HUDSystem &&)=delete
Deleted move assignment operator (non-movable)
HUDSystem(HUDSystem &&)=delete
Deleted move constructor (non-movable)
HUDSystem & operator=(const HUDSystem &)=delete
Deleted copy assignment operator (non-copyable)
const std::shared_ptr< eng::IRenderer > & m_renderer
Renderer for drawing HUD elements.
Definition HUD.hpp:102
ecs::Entity m_scoreBgEntity
Entity for score background sprite.
Definition HUD.hpp:104
HUDSystem(const HUDSystem &)=delete
Deleted copy constructor (non-copyable)
~HUDSystem() override=default
Destructor.
void createScoreHUD(ecs::Registry &registry, float x, float y)
Create the score display HUD elements.
Definition HUD.cpp:7
HUDSystem(const std::shared_ptr< eng::IRenderer > &renderer, ecs::Registry &registry)
Constructor - initializes the HUD system and creates initial UI elements.
Definition HUD.hpp:43
This file contains common definitions and constants.
std::uint32_t Entity
Definition Entity.hpp:13