versió preliminar de text en pantalla

This commit is contained in:
2025-12-01 22:29:34 +01:00
parent 983f42814f
commit 5210448ac9
5 changed files with 30 additions and 91 deletions

View File

@@ -133,6 +133,9 @@ void EscenaJoc::dibuixar() {
for (const auto &bala : bales_) {
bala.dibuixar();
}
// Dibuixar marcador
dibuixar_marcador();
}
void EscenaJoc::processar_input(const SDL_Event &event) {
@@ -182,3 +185,29 @@ void EscenaJoc::dibuixar_marges() const {
Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2, true); // Left
Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2, true); // Right
}
void EscenaJoc::dibuixar_marcador() {
// Text estàtic (hardcoded)
const std::string text = "SCORE: 00000 LIFE: 3 LEVEL: 01";
// Escala ajustada per cabre en 640px d'amplada
// Zona marcador: width = 640 px, height = 64 px
// Text: 34 caràcters → necessitem ~487 px amb escala 1.2
// Altura caràcter: 20 * 1.2 = 24 px (37.5% de 64px)
const float escala = 1.2f;
const float spacing = 2.0f;
// Calcular amplada total del text
float text_width = text_.get_text_width(text, escala, spacing);
// Centrat horitzontal
float x = (Defaults::Zones::SCOREBOARD.w - text_width) / 2.0f;
// Centrat vertical
// Altura del caràcter escalat: 20 * 1.2 = 24 px
// Marge superior: (64 - 24) / 2 = 20 px
float y = Defaults::Zones::SCOREBOARD.y + 20.0f;
// Renderitzar
text_.render(text, {x, y}, escala, spacing);
}