r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
Beam.hpp
Go to the documentation of this file.
1///
2/// @file Systems.hpp
3/// @brief This file contains the system definitions
4/// @namespace cli
5///
6
7#pragma once
8
10#include "ECS/Component.hpp"
11#include "ECS/Registry.hpp"
13
14namespace cli
15{
16
17 class BeamSystem final : public eng::ASystem
18 {
19 public:
20 explicit BeamSystem(eng::IRenderer &renderer) : m_renderer(renderer) {}
21 ~BeamSystem() override = default;
22
23 BeamSystem(const BeamSystem &) = delete;
24 BeamSystem &operator=(const BeamSystem &) = delete;
25 BeamSystem(BeamSystem &&) = delete;
27
28 void update(ecs::Registry &registry, float /* dt */) override
29 {
30 // Chercher seulement le joueur avec BeamCharge
31 for (auto &[entity, beamCharge] : registry.getAll<ecs::BeamCharge>())
32 {
33 const auto *player = registry.getComponent<ecs::Player>(entity);
34 if (!player)
35 continue; // Seulement pour le joueur
36
37 const auto *transform = registry.getComponent<ecs::Transform>(entity);
38 if (!transform)
39 continue;
40
41 // Position de la barre au-dessus du joueur
42 float barX =
44 float barY = transform->y - GameConfig::Beam::BAR_HEIGHT - 10.0f; // 10 pixels au-dessus
45
46 // Dessiner la barre de fond avec des points (plus petite et plus fine)
47 for (int x = 0; x < static_cast<int>(GameConfig::Beam::BAR_WIDTH); x += 3)
48 {
49 for (int y = 0; y < static_cast<int>(GameConfig::Beam::BAR_HEIGHT); y += 3)
50 {
51 m_renderer.drawPoint(barX + x, barY + y, {.r = 30, .g = 30, .b = 30, .a = 200});
52 }
53 }
54
55 // Dessiner la barre de chargement
56 float chargeRatio = beamCharge.current_charge / beamCharge.max_charge;
57 float chargeWidth = GameConfig::Beam::BAR_WIDTH * chargeRatio;
58
59 // Dessiner le seuil de 50% (ligne verticale)
60 float thresholdX = barX + GameConfig::Beam::BAR_WIDTH * 0.5f;
61 for (int y = 0; y < static_cast<int>(GameConfig::Beam::BAR_HEIGHT); y += 2)
62 {
64 thresholdX, barY + y,
65 {.r = 255, .g = 255, .b = 255, .a = 150}); // Ligne blanche semi-transparente
66 }
67
68 if (chargeWidth > 0)
69 {
70 for (int x = 0; x < static_cast<int>(chargeWidth); x += 3)
71 {
72 for (int y = 0; y < static_cast<int>(GameConfig::Beam::BAR_HEIGHT); y += 3)
73 {
74 // Couleur qui change selon le niveau de charge
75 eng::Color chargeColor;
76 if (chargeRatio < 0.5f)
77 {
78 chargeColor = {
79 .r = 255, .g = 100, .b = 0, .a = 255}; // Orange (en dessous du seuil)
80 }
81 else if (chargeRatio < 0.8f)
82 {
83 chargeColor = {.r = 255, .g = 200, .b = 0, .a = 255}; // Jaune
84 }
85 else
86 {
87 chargeColor = {.r = 0, .g = 255, .b = 0, .a = 255}; // Vert
88 }
89
90 m_renderer.drawPoint(barX + x, barY + y, chargeColor);
91 }
92 }
93 }
94 }
95 }
96
97 private:
99 }; // class BeamSystem
100
101} // namespace cli
This file contains the component definitions.
Configuration constants for the game.
This file contains the IRenderer class declaration.
This file contains the Registry class declaration.
eng::IRenderer & m_renderer
Definition Beam.hpp:98
~BeamSystem() override=default
BeamSystem(eng::IRenderer &renderer)
Definition Beam.hpp:20
void update(ecs::Registry &registry, float) override
Definition Beam.hpp:28
BeamSystem(const BeamSystem &)=delete
BeamSystem & operator=(const BeamSystem &)=delete
BeamSystem(BeamSystem &&)=delete
BeamSystem & operator=(BeamSystem &&)=delete
Class for managing entities and their components.
Definition Registry.hpp:25
std::unordered_map< Entity, T > & getAll()
Definition Registry.hpp:77
T * getComponent(Entity e)
Definition Registry.hpp:71
Interface for the renderer.
virtual void drawPoint(float x, float y, Color color)=0
constexpr float BAR_WIDTH
constexpr float BAR_HEIGHT
constexpr float SPRITE_WIDTH
unsigned char r
Definition IRenderer.hpp:17