afegides shapes per a fonts

This commit is contained in:
2025-11-29 10:06:33 +01:00
parent 89302a2ee3
commit 983f42814f
69 changed files with 530 additions and 258 deletions

View File

@@ -51,6 +51,7 @@ set(APP_SOURCES
source/game/entities/nau.cpp
source/game/entities/bala.cpp
source/game/entities/enemic.cpp
source/utils/text_renderer.cpp
)
# Configuración de SDL3

View File

@@ -1,25 +0,0 @@
# char_0.shp - Dígito 0
# Display de 7 segmentos: a,b,c,e,f,g (sin d)
# Dimensiones: 10×20 (escalable)
name: char_0
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento b (vertical izquierda superior)
line: 0,1 0,9
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento e (vertical izquierda inferior)
line: 0,11 0,19
# Segmento f (vertical derecha inferior)
line: 10,11 10,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,13 +0,0 @@
# char_1.shp - Dígito 1
# Display de 7 segmentos: c,f
# Dimensiones: 10×20 (escalable)
name: char_1
scale: 1.0
center: 5, 10
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento f (vertical derecha inferior)
line: 10,11 10,19

View File

@@ -1,22 +0,0 @@
# char_2.shp - Dígito 2
# Display de 7 segmentos: a,c,d,e,g
# Dimensiones: 10×20 (escalable)
name: char_2
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento e (vertical izquierda inferior)
line: 0,11 0,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,22 +0,0 @@
# char_3.shp - Dígito 3
# Display de 7 segmentos: a,c,d,f,g
# Dimensiones: 10×20 (escalable)
name: char_3
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento f (vertical derecha inferior)
line: 10,11 10,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,19 +0,0 @@
# char_4.shp - Dígito 4
# Display de 7 segmentos: b,c,d,f
# Dimensiones: 10×20 (escalable)
name: char_4
scale: 1.0
center: 5, 10
# Segmento b (vertical izquierda superior)
line: 0,1 0,9
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento f (vertical derecha inferior)
line: 10,11 10,19

View File

@@ -1,22 +0,0 @@
# char_5.shp - Dígito 5
# Display de 7 segmentos: a,b,d,f,g
# Dimensiones: 10×20 (escalable)
name: char_5
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento b (vertical izquierda superior)
line: 0,1 0,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento f (vertical derecha inferior)
line: 10,11 10,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,25 +0,0 @@
# char_6.shp - Dígito 6
# Display de 7 segmentos: a,b,d,e,f,g
# Dimensiones: 10×20 (escalable)
name: char_6
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento b (vertical izquierda superior)
line: 0,1 0,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento e (vertical izquierda inferior)
line: 0,11 0,19
# Segmento f (vertical derecha inferior)
line: 10,11 10,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,16 +0,0 @@
# char_7.shp - Dígito 7
# Display de 7 segmentos: a,c,f
# Dimensiones: 10×20 (escalable)
name: char_7
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento f (vertical derecha inferior)
line: 10,11 10,19

View File

@@ -1,28 +0,0 @@
# char_8.shp - Dígito 8
# Display de 7 segmentos: a,b,c,d,e,f,g (todos)
# Dimensiones: 10×20 (escalable)
name: char_8
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento b (vertical izquierda superior)
line: 0,1 0,9
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento e (vertical izquierda inferior)
line: 0,11 0,19
# Segmento f (vertical derecha inferior)
line: 10,11 10,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,25 +0,0 @@
# char_9.shp - Dígito 9
# Display de 7 segmentos: a,b,c,d,f,g
# Dimensiones: 10×20 (escalable)
name: char_9
scale: 1.0
center: 5, 10
# Segmento a (horizontal superior)
line: 1,0 9,0
# Segmento b (vertical izquierda superior)
line: 0,1 0,9
# Segmento c (vertical derecha superior)
line: 10,1 10,9
# Segmento d (horizontal medio)
line: 1,10 9,10
# Segmento f (vertical derecha inferior)
line: 10,11 10,19
# Segmento g (horizontal inferior)
line: 1,20 9,20

View File

@@ -1,12 +0,0 @@
# char_colon.shp - Símbolo : (dos puntos)
# Dimensiones: 10×20 (escalable)
name: char_colon
scale: 1.0
center: 5, 10
# Punto superior (Y=6)
line: 4,6 6,6
# Punto inferior (Y=14)
line: 4,14 6,14

View File

@@ -1,9 +0,0 @@
# char_comma.shp - Símbolo , (coma)
# Dimensiones: 10×20 (escalable)
name: char_comma
scale: 1.0
center: 5, 10
# Coma en esquina inferior derecha (con cola hacia abajo)
polyline: 9,18 10,20

View File

@@ -1,9 +0,0 @@
# char_dot.shp - Símbolo . (punto)
# Dimensiones: 10×20 (escalable)
name: char_dot
scale: 1.0
center: 5, 10
# Punto en esquina inferior derecha
line: 9,19 10,20

View File

@@ -1,9 +0,0 @@
# char_minus.shp - Símbolo - (menos/guión)
# Dimensiones: 10×20 (escalable)
name: char_minus
scale: 1.0
center: 5, 10
# Línea horizontal en el medio
line: 2,10 8,10

View File

@@ -0,0 +1,10 @@
# char_0.shp - Dígito 0
# Dimensiones: 20×40 (blocky display)
# Rectángulo cerrado (polyline continua, NO 6 líneas separadas)
name: char_0
scale: 1.0
center: 10, 20
# Rectángulo cerrado
polyline: 2,10 18,10 18,30 2,30 2,10

View File

@@ -0,0 +1,10 @@
# char_1.shp - Dígito 1
# Dimensiones: 20×40 (blocky display)
# Línea vertical simple centrada
name: char_1
scale: 1.0
center: 10, 20
# Línea vertical central
line: 10,10 10,30

View File

@@ -0,0 +1,10 @@
# char_2.shp - Dígito 2
# Dimensiones: 20×40 (blocky display)
# Forma de "2" con curva simulada (polyline continua)
name: char_2
scale: 1.0
center: 10, 20
# Trazo continuo en forma de S achatada
polyline: 2,10 18,10 18,20 2,20 2,30 18,30

View File

@@ -0,0 +1,11 @@
# char_3.shp - Dígito 3
# Dimensiones: 20×40 (blocky display)
# Forma de "3" con dos curvas (polylines)
name: char_3
scale: 1.0
center: 10, 20
# Trazo continuo (barra superior + lateral derecho + barra media + lateral derecho + barra inferior)
polyline: 2,10 18,10 18,20 14,20
polyline: 14,20 18,20 18,30 2,30

View File

@@ -0,0 +1,12 @@
# char_4.shp - Dígito 4
# Dimensiones: 20×40 (blocky display)
# Forma de "4" con líneas continuas
name: char_4
scale: 1.0
center: 10, 20
# Trazo principal (vertical izquierda + horizontal + vertical derecha superior)
polyline: 2,10 2,20 18,20
# Vertical derecha completa (cruza la horizontal)
line: 18,10 18,30

View File

@@ -0,0 +1,10 @@
# char_5.shp - Dígito 5
# Dimensiones: 20×40 (blocky display)
# Forma de "5" con curva (polyline continua)
name: char_5
scale: 1.0
center: 10, 20
# Trazo continuo en forma de S invertida
polyline: 18,10 2,10 2,20 18,20 18,30 2,30

View File

@@ -0,0 +1,10 @@
# char_6.shp - Dígito 6
# Dimensiones: 20×40 (blocky display)
# Forma de "6" con espiral (polyline continua)
name: char_6
scale: 1.0
center: 10, 20
# Trazo continuo: barra superior + lateral izquierdo + barra media + lateral derecho inferior + barra inferior + cierre
polyline: 18,10 2,10 2,30 18,30 18,20 2,20

View File

@@ -0,0 +1,10 @@
# char_7.shp - Dígito 7
# Dimensiones: 20×40 (blocky display)
# Línea horizontal superior + diagonal hacia abajo-derecha
name: char_7
scale: 1.0
center: 10, 20
# Barra superior + diagonal
polyline: 2,10 18,10 18,30

View File

@@ -0,0 +1,12 @@
# char_8.shp - Dígito 8
# Dimensiones: 20×40 (blocky display)
# Dos rectángulos apilados (polylines continuas)
name: char_8
scale: 1.0
center: 10, 20
# Rectángulo superior
polyline: 2,10 18,10 18,20 2,20 2,10
# Rectángulo inferior (comparte borde con el superior)
polyline: 2,20 18,20 18,30 2,30 2,20

View File

@@ -0,0 +1,10 @@
# char_9.shp - Dígito 9
# Dimensiones: 20×40 (blocky display)
# Forma de "9" con espiral (polyline continua)
name: char_9
scale: 1.0
center: 10, 20
# Trazo continuo: lateral derecho completo + barra superior + lateral izquierdo superior + barra media
polyline: 18,30 18,10 2,10 2,20 18,20

View File

@@ -0,0 +1,11 @@
# char_A.shp - Letra A
# Dimensiones: 20×40 (blocky display)
name: char_A
scale: 1.0
center: 10, 20
# Forma triangular (dos diagonales hacia arriba)
polyline: 2,30 10,10 18,30
# Barra horizontal media
line: 5,22 15,22

View File

@@ -0,0 +1,11 @@
# char_B.shp - Letra B
# Dimensiones: 20×40 (blocky display)
name: char_B
scale: 1.0
center: 10, 20
# Rectángulo superior
polyline: 2,10 14,10 14,20 2,20 2,10
# Rectángulo inferior (más ancho)
polyline: 2,20 16,20 16,30 2,30 2,20

View File

@@ -0,0 +1,9 @@
# char_C.shp - Letra C
# Dimensiones: 20×40 (blocky display)
name: char_C
scale: 1.0
center: 10, 20
# Curva simulada (semicírculo abierto a la derecha)
polyline: 18,12 14,10 6,10 2,14 2,26 6,30 14,30 18,28

View File

@@ -0,0 +1,9 @@
# char_D.shp - Letra D
# Dimensiones: 20×40 (blocky display)
name: char_D
scale: 1.0
center: 10, 20
# Vertical izquierda + curva derecha simulada
polyline: 2,10 14,10 18,14 18,26 14,30 2,30 2,10

View File

@@ -0,0 +1,10 @@
# char_E.shp - Letra E
# Dimensiones: 20×40 (blocky display)
name: char_E
scale: 1.0
center: 10, 20
# Forma de E (vertical izquierda + 3 horizontales)
polyline: 18,10 2,10 2,30 18,30
line: 2,20 14,20

View File

@@ -0,0 +1,10 @@
# char_F.shp - Letra F
# Dimensiones: 20×40 (blocky display)
name: char_F
scale: 1.0
center: 10, 20
# Vertical izquierda + barra superior + barra media
polyline: 2,30 2,10 18,10
line: 2,20 14,20

View File

@@ -0,0 +1,9 @@
# char_G.shp - Letra G
# Dimensiones: 20×40 (blocky display)
name: char_G
scale: 1.0
center: 10, 20
# Como C pero con barra horizontal hacia adentro
polyline: 18,12 14,10 6,10 2,14 2,26 6,30 14,30 18,28 18,20 12,20

View File

@@ -0,0 +1,13 @@
# char_H.shp - Letra H
# Dimensiones: 20×40 (blocky display)
name: char_H
scale: 1.0
center: 10, 20
# Vertical izquierda
line: 2,10 2,30
# Vertical derecha
line: 18,10 18,30
# Barra media
line: 2,20 18,20

View File

@@ -0,0 +1,9 @@
# char_I.shp - Letra I
# Dimensiones: 20×40 (blocky display)
name: char_I
scale: 1.0
center: 10, 20
# Línea vertical central
line: 10,10 10,30

View File

@@ -0,0 +1,9 @@
# char_J.shp - Letra J
# Dimensiones: 20×40 (blocky display)
name: char_J
scale: 1.0
center: 10, 20
# Vertical derecha con curva abajo-izquierda
polyline: 18,10 18,26 14,30 6,30 2,26

View File

@@ -0,0 +1,13 @@
# char_K.shp - Letra K
# Dimensiones: 20×40 (blocky display)
name: char_K
scale: 1.0
center: 10, 20
# Vertical izquierda
line: 2,10 2,30
# Diagonal superior
line: 18,10 2,20
# Diagonal inferior
line: 2,20 18,30

View File

@@ -0,0 +1,9 @@
# char_L.shp - Letra L
# Dimensiones: 20×40 (blocky display)
name: char_L
scale: 1.0
center: 10, 20
# Forma de L (vertical izquierda + horizontal abajo)
polyline: 2,10 2,30 18,30

View File

@@ -0,0 +1,9 @@
# char_M.shp - Letra M
# Dimensiones: 20×40 (blocky display)
name: char_M
scale: 1.0
center: 10, 20
# Forma de M con pico en el medio
polyline: 2,30 2,10 10,20 18,10 18,30

View File

@@ -0,0 +1,9 @@
# char_N.shp - Letra N
# Dimensiones: 20×40 (blocky display)
name: char_N
scale: 1.0
center: 10, 20
# Vertical izquierda + diagonal + vertical derecha
polyline: 2,30 2,10 18,30 18,10

View File

@@ -0,0 +1,9 @@
# char_O.shp - Letra O
# Dimensiones: 20×40 (blocky display)
name: char_O
scale: 1.0
center: 10, 20
# Rectángulo cerrado
polyline: 2,10 18,10 18,30 2,30 2,10

View File

@@ -0,0 +1,11 @@
# char_P.shp - Letra P
# Dimensiones: 20×40 (blocky display)
name: char_P
scale: 1.0
center: 10, 20
# Vertical izquierda completa
line: 2,10 2,30
# Rectángulo superior cerrado
polyline: 2,10 14,10 14,20 2,20

View File

@@ -0,0 +1,11 @@
# char_Q.shp - Letra Q
# Dimensiones: 20×40 (blocky display)
name: char_Q
scale: 1.0
center: 10, 20
# Rectángulo cerrado (como O)
polyline: 2,10 18,10 18,30 2,30 2,10
# Diagonal inferior derecha (cola de la Q)
line: 12,24 18,30

View File

@@ -0,0 +1,13 @@
# char_R.shp - Letra R
# Dimensiones: 20×40 (blocky display)
name: char_R
scale: 1.0
center: 10, 20
# Vertical izquierda completa
line: 2,10 2,30
# Rectángulo superior cerrado
polyline: 2,10 14,10 14,20 2,20
# Diagonal inferior derecha
line: 8,20 18,30

View File

@@ -0,0 +1,9 @@
# char_S.shp - Letra S
# Dimensiones: 20×40 (blocky display)
name: char_S
scale: 1.0
center: 10, 20
# Forma de S con curvas simuladas
polyline: 18,12 14,10 6,10 2,14 2,18 6,20 14,20 18,22 18,26 14,30 6,30 2,28

View File

@@ -0,0 +1,11 @@
# char_T.shp - Letra T
# Dimensiones: 20×40 (blocky display)
name: char_T
scale: 1.0
center: 10, 20
# Barra horizontal superior
line: 2,10 18,10
# Línea vertical central
line: 10,10 10,30

View File

@@ -0,0 +1,9 @@
# char_U.shp - Letra U
# Dimensiones: 20×40 (blocky display)
name: char_U
scale: 1.0
center: 10, 20
# Forma de U (dos verticales + curva abajo)
polyline: 2,10 2,26 6,30 14,30 18,26 18,10

View File

@@ -0,0 +1,9 @@
# char_V.shp - Letra V
# Dimensiones: 20×40 (blocky display)
name: char_V
scale: 1.0
center: 10, 20
# Forma de V (dos diagonales hacia abajo)
polyline: 2,10 10,30 18,10

View File

@@ -0,0 +1,9 @@
# char_W.shp - Letra W
# Dimensiones: 20×40 (blocky display)
name: char_W
scale: 1.0
center: 10, 20
# Forma de W (doble V)
polyline: 2,10 5,30 10,20 15,30 18,10

View File

@@ -0,0 +1,11 @@
# char_X.shp - Letra X
# Dimensiones: 20×40 (blocky display)
name: char_X
scale: 1.0
center: 10, 20
# Diagonal \
line: 2,10 18,30
# Diagonal /
line: 18,10 2,30

View File

@@ -0,0 +1,12 @@
# char_Y.shp - Letra Y
# Dimensiones: 20×40 (blocky display)
name: char_Y
scale: 1.0
center: 10, 20
# Dos diagonales superiores que se juntan
polyline: 2,10 10,20
polyline: 18,10 10,20
# Línea vertical inferior
line: 10,20 10,30

View File

@@ -0,0 +1,9 @@
# char_Z.shp - Letra Z
# Dimensiones: 20×40 (blocky display)
name: char_Z
scale: 1.0
center: 10, 20
# Barra superior + diagonal + barra inferior
polyline: 2,10 18,10 2,30 18,30

View File

@@ -0,0 +1,11 @@
# char_colon.shp - Símbolo : (dos puntos)
# Dimensiones: 20×40 (blocky display)
name: char_colon
scale: 1.0
center: 10, 20
# Punto superior
polyline: 8,14 12,14 12,17 8,17 8,14
# Punto inferior
polyline: 8,23 12,23 12,26 8,26 8,23

View File

@@ -0,0 +1,9 @@
# char_comma.shp - Símbolo , (coma)
# Dimensiones: 20×40 (blocky display)
name: char_comma
scale: 1.0
center: 10, 20
# Dot + tail hacia abajo-izquierda
polyline: 10,28 10,32 8,34

View File

@@ -0,0 +1,9 @@
# char_dot.shp - Símbolo . (punto)
# Dimensiones: 20×40 (blocky display)
name: char_dot
scale: 1.0
center: 10, 20
# Cuadrado pequeño centrado abajo
polyline: 8,28 12,28 12,32 8,32 8,28

View File

@@ -0,0 +1,11 @@
# char_exclamation.shp - Símbolo ! (exclamación)
# Dimensiones: 20×40 (blocky display)
name: char_exclamation
scale: 1.0
center: 10, 20
# Línea vertical superior
line: 10,10 10,24
# Dot inferior
polyline: 8,28 12,28 12,32 8,32 8,28

View File

@@ -0,0 +1,9 @@
# char_minus.shp - Símbolo - (menos/guión)
# Dimensiones: 20×40 (blocky display)
name: char_minus
scale: 1.0
center: 10, 20
# Línea horizontal en el centro
line: 4,20 16,20

View File

@@ -0,0 +1,11 @@
# char_question.shp - Símbolo ? (interrogación)
# Dimensiones: 20×40 (blocky display)
name: char_question
scale: 1.0
center: 10, 20
# Curva superior + trazo hacia abajo
polyline: 2,12 10,10 18,12 18,18 10,20 10,24
# Dot inferior
polyline: 8,28 12,28 12,32 8,32 8,28

View File

@@ -0,0 +1,9 @@
# char_space.shp - Espacio (vacío)
# Dimensiones: 20×40 (blocky display)
# Sin geometría (espacio vacío intencional)
name: char_space
scale: 1.0
center: 10, 20
# No hay polylines ni lines (vacío intencionado)

View File

@@ -92,8 +92,8 @@ void EscenaLogo::inicialitzar_lletres() {
// Llista de fitxers .shp (A repetida per a les dues A's)
std::vector<std::string> fitxers = {
"letra_j.shp", "letra_a.shp", "letra_i.shp", "letra_l.shp",
"letra_g.shp", "letra_a.shp", "letra_m.shp", "letra_e.shp", "letra_s.shp"
"logo/letra_j.shp", "logo/letra_a.shp", "logo/letra_i.shp", "logo/letra_l.shp",
"logo/letra_g.shp", "logo/letra_a.shp", "logo/letra_m.shp", "logo/letra_e.shp", "logo/letra_s.shp"
};
// Pas 1: Carregar totes les formes i calcular amplades

View File

@@ -0,0 +1,60 @@
// text_renderer.cpp - Implementació del renderitzador de text
// © 2025 Port a C++20 amb SDL3
#include "text_renderer.hpp"
#include "../core/graphics/shape_loader.hpp"
#include "../core/rendering/shape_renderer.hpp"
#include <iostream>
namespace Utils {
void TextRenderer::render(SDL_Renderer* renderer,
const std::string& text,
int x, int y,
int spacing) {
int current_x = x;
for (char c : text) {
std::string filename = get_char_filename(c);
auto shape = Graphics::ShapeLoader::load("font/" + filename);
if (shape && shape->es_valida()) {
Punt pos = {current_x, y};
Rendering::render_shape(renderer, shape, pos, 0.0f, 1.0f, true, 1.0f);
}
current_x += spacing;
}
}
int TextRenderer::calculate_width(const std::string& text, int spacing) {
return static_cast<int>(text.length()) * spacing;
}
std::string TextRenderer::get_char_filename(char c) {
// Números 0-9
if (c >= '0' && c <= '9')
return std::string("char_") + c + ".shp";
// Letras A-Z (mayúsculas)
if (c >= 'A' && c <= 'Z')
return std::string("char_") + c + ".shp";
// Convertir minúsculas a mayúsculas
if (c >= 'a' && c <= 'z')
return std::string("char_") + char(c - 32) + ".shp";
// Caracteres especiales
switch (c) {
case ':': return "char_colon.shp";
case '.': return "char_dot.shp";
case '-': return "char_minus.shp";
case ',': return "char_comma.shp";
case '!': return "char_exclamation.shp";
case '?': return "char_question.shp";
case ' ': return "char_space.shp";
default: return "char_question.shp"; // Fallback
}
}
} // namespace Utils

View File

@@ -0,0 +1,30 @@
// text_renderer.hpp - Renderitzador de text amb formes .shp
// © 2025 Port a C++20 amb SDL3
#pragma once
#include <string>
#include "../core/types.hpp"
// Forward declarations
struct SDL_Renderer;
namespace Graphics { class Shape; }
namespace Utils {
class TextRenderer {
public:
// Renderitza un string en la posició especificada
static void render(SDL_Renderer* renderer,
const std::string& text,
int x, int y,
int spacing = 22);
// Calcula el ancho total de un string
static int calculate_width(const std::string& text, int spacing = 22);
private:
// Mapea un caràcter a su nombre de archivo .shp
static std::string get_char_filename(char c);
};
} // namespace Utils