Fase 0: eliminar tot el codi llegacy (polars + primitives + bool dibuixar)

Aplicada la directiva "res llegacy" abans d'arrencar la migracio a fisica
vectorial + SDL3 GPU. Cada bossa de cruft que arrossegava el port de Pascal
queda eliminada.

Borrats (huerfanos):
- source/core/rendering/primitives.hpp/.cpp (modul/diferencia/angle_punt/
  crear_poligon_regular)
- source/core/rendering/polygon_renderer.hpp/.cpp (rota_tri/rota_pol)
- core::types::Triangle, Poligon, IPunt
- Defaults::Entities::MAX_IPUNTS i alias a constants.hpp
- EscenaJoc::chatarra_cosmica_ (mai usat)
- Bresenham comentat dins de Rendering::linea()

Simplificat (parametre 'dibuixar' llegacy que sempre era true):
- Rendering::linea(...): treta la signatura bool dibuixar, retorn void
- Rendering::render_shape(...): treta la signatura bool dibuixar
- 11 callsites de linea() actualitzats (escena_joc, debris_manager)
- 12 callsites de render_shape() actualitzats

Modernitzats:
- 5 fitxers .shp netejats de comentaris polar->cartesia historics
- types.hpp queda nomes amb Punt (l'unica coordenada del joc)
- debris_manager.hpp afegit include explicit de defaults.hpp

Net: 452 linies eliminades, 56 afegides. Compila i enllaca correctament.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-19 11:10:42 +02:00
parent cb7b99cab3
commit 6cf990bc1d
28 changed files with 55 additions and 451 deletions
+1 -17
View File
@@ -1,23 +1,7 @@
# bullet.shp - Projectil (petit pentàgon) # bullet.shp - Projectil (octàgon, radi=3)
# © 1999 Visente i Sergi (versió Pascal)
# © 2025 Port a C++20 amb SDL3
name: bullet name: bullet
scale: 1.0 scale: 1.0
center: 0, 0 center: 0, 0
# Cercle (octàgon regular radi=3)
# 8 punts equidistants (45° entre ells) per aproximar un cercle
# Començant a angle=-90° (amunt), rotant sentit horari
#
# Conversió polar→cartesià (radi=3, SDL: Y creix cap avall):
# angle=-90°: (0.00, -3.00)
# angle=-45°: (2.12, -2.12)
# angle=0°: (3.00, 0.00)
# angle=45°: (2.12, 2.12)
# angle=90°: (0.00, 3.00)
# angle=135°: (-2.12, 2.12)
# angle=180°: (-3.00, 0.00)
# angle=225°: (-2.12, -2.12)
polyline: 0,-3 2.12,-2.12 3,0 2.12,2.12 0,3 -2.12,2.12 -3,0 -2.12,-2.12 0,-3 polyline: 0,-3 2.12,-2.12 3,0 2.12,2.12 0,3 -2.12,2.12 -3,0 -2.12,-2.12 0,-3
+1 -15
View File
@@ -1,21 +1,7 @@
# enemy_pentagon.shp - ORNI enemic (pentàgon regular) # enemy_pentagon.shp - ORNI enemic (pentàgon regular, radi=20)
# © 1999 Visente i Sergi (versió Pascal)
# © 2025 Port a C++20 amb SDL3
name: enemy_pentagon name: enemy_pentagon
scale: 1.0 scale: 1.0
center: 0, 0 center: 0, 0
# Pentàgon regular radi=20
# 5 punts equidistants al voltant d'un cercle (72° entre ells)
# Començant a angle=-90° (amunt), rotant sentit antihorari
#
# Angles: -90°, -18°, 54°, 126°, 198°
# Conversió polar→cartesià (SDL: Y creix cap avall):
# angle=-90°: (0.00, -20.00)
# angle=-18°: (19.02, -6.18)
# angle=54°: (11.76, 16.18)
# angle=126°: (-11.76, 16.18)
# angle=198°: (-19.02, -6.18)
polyline: 0,-20 19.02,-6.18 11.76,16.18 -11.76,16.18 -19.02,-6.18 0,-20 polyline: 0,-20 19.02,-6.18 11.76,16.18 -11.76,16.18 -19.02,-6.18 0,-20
+1 -13
View File
@@ -1,19 +1,7 @@
# enemy_square.shp - ORNI enemic (quadrat regular) # enemy_square.shp - ORNI enemic (quadrat regular, radi=20)
# © 2025 Port a C++20 amb SDL3
name: enemy_square name: enemy_square
scale: 1.0 scale: 1.0
center: 0, 0 center: 0, 0
# Quadrat regular radi=20 (circumscrit)
# 4 punts equidistants al voltant d'un cercle (90° entre ells)
# Començant a angle=-90° (amunt), rotant sentit horari
#
# Angles: -90°, 0°, 90°, 180°
# Conversió polar→cartesià (SDL: Y creix cap avall):
# angle=-90°: (0.00, -20.00)
# angle=0°: (20.00, 0.00)
# angle=90°: (0.00, 20.00)
# angle=180°: (-20.00, 0.00)
polyline: 0,-20 20,0 0,20 -20,0 0,-20 polyline: 0,-20 20,0 0,20 -20,0 0,-20
+2 -18
View File
@@ -1,24 +1,8 @@
# ship.shp - Nau del jugador 1 (triangle amb base còncava - punta de fletxa) # ship.shp - Nau del jugador 1
# © 1999 Visente i Sergi (versió Pascal) # Triangle amb base còncava (punta de fletxa)
# © 2025 Port a C++20 amb SDL3
name: ship name: ship
scale: 1.0 scale: 1.0
center: 0, 0 center: 0, 0
# Triangle amb base còncava tipus "punta de fletxa"
# Punts originals (polar):
# p1: r=12, angle=270° (3π/2) → punta amunt
# p2: r=12, angle=45° (π/4) → base dreta-darrere
# p3: r=12, angle=135° (3π/4) → base esquerra-darrere
#
# MODIFICACIÓ: afegit p4 al mig de la base, desplaçat cap al centre
# p4: (0, 4) → punt central de la base, cap endins
#
# Conversió polar→cartesià (angle-90° perquè origen visual és amunt):
# p1: (0, -12) → punta
# p2: (8.49, 8.49) → base dreta
# p4: (0, 4) → base centre (cap endins)
# p3: (-8.49, 8.49) → base esquerra
polyline: 0,-12 8.49,8.49 0,4 -8.49,8.49 0,-12 polyline: 0,-12 8.49,8.49 0,4 -8.49,8.49 0,-12
+3 -22
View File
@@ -1,30 +1,11 @@
# ship2.shp - Nau del jugador 2 (triangle amb circulito central) # ship2.shp - Nau del jugador 2
# © 1999 Visente i Sergi (versió Pascal) # Triangle amb cercle central (distintiu visual)
# © 2025 Port a C++20 amb SDL3
name: ship2 name: ship2
scale: 1.0 scale: 1.0
center: 0, 0 center: 0, 0
# Triangle amb base còncava tipus "punta de fletxa"
# (Mateix que ship.shp)
# Punts originals (polar):
# p1: r=12, angle=270° (3π/2) → punta amunt
# p2: r=12, angle=45° (π/4) → base dreta-darrere
# p3: r=12, angle=135° (3π/4) → base esquerra-darrere
#
# MODIFICACIÓ: afegit p4 al mig de la base, desplaçat cap al centre
# p4: (0, 4) → punt central de la base, cap endins
#
# Conversió polar→cartesià (angle-90° perquè origen visual és amunt):
# p1: (0, -12) → punta
# p2: (8.49, 8.49) → base dreta
# p4: (0, 4) → base centre (cap endins)
# p3: (-8.49, 8.49) → base esquerra
#polyline: 0,-12 8.49,8.49 0,4 -8.49,8.49 0,-12
polyline: 0,-12 8.49,8.49 -8.49,8.49 0,-12 polyline: 0,-12 8.49,8.49 -8.49,8.49 0,-12
# Circulito central (octàgon r=2.5) # Octàgon central (radi=2.5)
# Distintiu visual del jugador 2
polyline: 0,-2.5 1.77,-1.77 2.5,0 1.77,1.77 0,2.5 -1.77,1.77 -2.5,0 -1.77,-1.77 0,-2.5 polyline: 0,-2.5 1.77,-1.77 2.5,0 1.77,1.77 0,2.5 -1.77,1.77 -2.5,0 -1.77,-1.77 0,-2.5
-1
View File
@@ -101,7 +101,6 @@ constexpr float SCOREBOARD_PADDING_H = 0.0F; // Game::WIDTH * 0.015f;
namespace Entities { namespace Entities {
constexpr int MAX_ORNIS = 15; constexpr int MAX_ORNIS = 15;
constexpr int MAX_BALES = 3; constexpr int MAX_BALES = 3;
constexpr int MAX_IPUNTS = 30;
constexpr float SHIP_RADIUS = 12.0F; constexpr float SHIP_RADIUS = 12.0F;
constexpr float ENEMY_RADIUS = 20.0F; constexpr float ENEMY_RADIUS = 20.0F;
-1
View File
@@ -162,7 +162,6 @@ void Starfield::dibuixar() {
estrella.posicio, estrella.posicio,
0.0F, // angle (les estrelles no giren) 0.0F, // angle (les estrelles no giren)
escala, // escala dinàmica escala, // escala dinàmica
true, // dibuixar
1.0F, // progress (sempre visible) 1.0F, // progress (sempre visible)
brightness // brightness dinàmica brightness // brightness dinàmica
); );
+1 -1
View File
@@ -224,7 +224,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
// Ajustar X e Y para que posicio represente esquina superior izquierda // Ajustar X e Y para que posicio represente esquina superior izquierda
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura) // (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
Punt char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)}; Punt char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, true, 1.0F, brightness); Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness);
// Avanzar posición // Avanzar posición
current_x += char_width_scaled + spacing_scaled; current_x += char_width_scaled + spacing_scaled;
+19 -83
View File
@@ -4,99 +4,35 @@
#include "core/rendering/line_renderer.hpp" #include "core/rendering/line_renderer.hpp"
#include <cmath>
#include "core/rendering/coordinate_transform.hpp" #include "core/rendering/coordinate_transform.hpp"
namespace Rendering { namespace Rendering {
// [NUEVO] Color global compartit (actualitzat per ColorOscillator via // Color global compartit (actualitzat per ColorOscillator via SDLManager)
// SDLManager) SDL_Color g_current_line_color = {255, 255, 255, 255};
SDL_Color g_current_line_color = {255, 255, 255, 255}; // Blanc inicial
bool linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, bool dibuixar, float brightness) { void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness) {
// Algorisme de Bresenham per dibuixar línies if (renderer == nullptr) {
// Basat en el codi Pascal original return;
// Helper function: retorna el signe d'un nombre
auto sign = [](int x) -> int {
if (x < 0) {
return -1;
}
if (x > 0) {
return 1;
}
return 0;
};
// Variables per a l'algorisme (no utilitzades fins Fase 10 - detecció de
// col·lisions) int x = x1, y = y1; int xs = x2 - x1; int ys = y2 - y1; int
// xm = sign(xs); int ym = sign(ys); xs = std::abs(xs); ys = std::abs(ys);
// Suprimir warning de variable no usada
(void)sign;
// Detecció de col·lisió (TODO per Fase 10)
// El codi Pascal original llegia pixels del framebuffer bit-packed
// i comptava col·lisions. Per ara, usem SDL_RenderDrawLine i retornem false.
bool colisio = false;
// Dibuixar amb SDL3 (més eficient que Bresenham píxel a píxel)
if (dibuixar && (renderer != nullptr)) {
// Transformar coordenades lògiques (640x480) a físiques (resolució real)
float scale = g_current_scale_factor;
int px1 = transform_x(x1, scale);
int py1 = transform_y(y1, scale);
int px2 = transform_x(x2, scale);
int py2 = transform_y(y2, scale);
// Aplicar brightness al color oscil·lat global
SDL_Color color_final;
color_final.r = static_cast<uint8_t>(g_current_line_color.r * brightness);
color_final.g = static_cast<uint8_t>(g_current_line_color.g * brightness);
color_final.b = static_cast<uint8_t>(g_current_line_color.b * brightness);
color_final.a = 255;
SDL_SetRenderDrawColor(renderer, color_final.r, color_final.g, color_final.b, 255);
// Renderitzar amb coordenades físiques
SDL_RenderLine(renderer, static_cast<float>(px1), static_cast<float>(py1), static_cast<float>(px2), static_cast<float>(py2));
} }
// Algorisme de Bresenham original (conservat per a futura detecció de // Transformar coordenades lògiques (640x480) a físiques (resolució real)
// col·lisió) const float SCALE = g_current_scale_factor;
/* const int PX1 = transform_x(x1, SCALE);
if (xs > ys) { const int PY1 = transform_y(y1, SCALE);
// Línia plana (<45 graus) const int PX2 = transform_x(x2, SCALE);
int count = -(xs / 2); const int PY2 = transform_y(y2, SCALE);
while (x != x2) {
count = count + ys;
x = x + xm;
if (count > 0) {
y = y + ym;
count = count - xs;
}
// Aquí aniria la detecció de col·lisió píxel a píxel
}
} else {
// Línia pronunciada (>=45 graus)
int count = -(ys / 2);
while (y != y2) {
count = count + xs;
y = y + ym;
if (count > 0) {
x = x + xm;
count = count - ys;
}
// Aquí aniria la detecció de col·lisió píxel a píxel
}
}
*/
return colisio; // Aplicar brightness al color oscil·lat global
const auto R = static_cast<uint8_t>(g_current_line_color.r * brightness);
const auto G = static_cast<uint8_t>(g_current_line_color.g * brightness);
const auto B = static_cast<uint8_t>(g_current_line_color.b * brightness);
SDL_SetRenderDrawColor(renderer, R, G, B, 255);
SDL_RenderLine(renderer, static_cast<float>(PX1), static_cast<float>(PY1),
static_cast<float>(PX2), static_cast<float>(PY2));
} }
// [NUEVO] Establir el color global de les línies
void setLineColor(SDL_Color color) { g_current_line_color = color; } void setLineColor(SDL_Color color) { g_current_line_color = color; }
} // namespace Rendering } // namespace Rendering
+6 -5
View File
@@ -6,11 +6,12 @@
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
namespace Rendering { namespace Rendering {
// Algorisme de Bresenham per dibuixar línies
// Retorna true si hi ha col·lisió (per Fase 10)
// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
bool linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, bool dibuixar, float brightness = 1.0F);
// [NUEVO] Establir el color global de les línies (oscil·lació) // Dibuixa una línia entre dos punts en coordenades lògiques (640x480).
// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor).
void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness = 1.0F);
// Estableix el color global de les línies (utilitzat per ColorOscillator).
void setLineColor(SDL_Color color); void setLineColor(SDL_Color color);
} // namespace Rendering } // namespace Rendering
@@ -1,86 +0,0 @@
// polygon_renderer.cpp - Implementació de renderitzat de polígons
// © 1999 Visente i Sergi (versió Pascal)
// © 2025 Port a C++20 amb SDL3
//
// ==============================================================================
// DEPRECATED: Use core/rendering/shape_renderer.cpp instead
// ==============================================================================
#include "core/rendering/polygon_renderer.hpp"
#include <array>
#include <cmath>
#include "core/defaults.hpp"
#include "core/rendering/line_renderer.hpp"
namespace Rendering {
void rota_tri(SDL_Renderer* renderer, const Triangle& tri, float angul, float velocitat, bool dibuixar) {
// Rotar i dibuixar triangle (nau)
// Conversió de coordenades polars a cartesianes amb rotació
// Basat en el codi Pascal original: lines 271-284
// Convertir cada punt polar a cartesià
// x = (r + velocitat) * cos(angle_punt + angle_nau) + centre.x
// y = (r + velocitat) * sin(angle_punt + angle_nau) + centre.y
int x1 = static_cast<int>(std::round((tri.p1.r + velocitat) *
std::cos(tri.p1.angle + angul))) +
tri.centre.x;
int y1 = static_cast<int>(std::round((tri.p1.r + velocitat) *
std::sin(tri.p1.angle + angul))) +
tri.centre.y;
int x2 = static_cast<int>(std::round((tri.p2.r + velocitat) *
std::cos(tri.p2.angle + angul))) +
tri.centre.x;
int y2 = static_cast<int>(std::round((tri.p2.r + velocitat) *
std::sin(tri.p2.angle + angul))) +
tri.centre.y;
int x3 = static_cast<int>(std::round((tri.p3.r + velocitat) *
std::cos(tri.p3.angle + angul))) +
tri.centre.x;
int y3 = static_cast<int>(std::round((tri.p3.r + velocitat) *
std::sin(tri.p3.angle + angul))) +
tri.centre.y;
// Dibuixar les 3 línies que formen el triangle
linea(renderer, x1, y1, x2, y2, dibuixar);
linea(renderer, x1, y1, x3, y3, dibuixar);
linea(renderer, x3, y3, x2, y2, dibuixar);
}
void rota_pol(SDL_Renderer* renderer, const Poligon& pol, float angul, bool dibuixar) {
// Rotar i dibuixar polígon (enemics i bales)
// Conversió de coordenades polars a cartesianes amb rotació
// Basat en el codi Pascal original: lines 286-296
// Array temporal per emmagatzemar punts convertits a cartesianes
std::array<Punt, Defaults::Entities::MAX_IPUNTS> xy;
// Convertir cada punt polar a cartesià
for (uint8_t i = 0; i < pol.n; i++) {
xy[i].x = static_cast<int>(std::round(
pol.ipuntx[i].r * std::cos(pol.ipuntx[i].angle + angul))) +
pol.centre.x;
xy[i].y = static_cast<int>(std::round(
pol.ipuntx[i].r * std::sin(pol.ipuntx[i].angle + angul))) +
pol.centre.y;
}
// Dibuixar línies entre punts consecutius
for (uint8_t i = 0; i < pol.n - 1; i++) {
linea(renderer, xy[i].x, xy[i].y, xy[i + 1].x, xy[i + 1].y, dibuixar);
}
// Tancar el polígon (últim punt → primer punt)
linea(renderer, xy[pol.n - 1].x, xy[pol.n - 1].y, xy[0].x, xy[0].y, dibuixar);
}
} // namespace Rendering
@@ -1,22 +0,0 @@
// polygon_renderer.hpp - Renderitzat de polígons polars
// © 1999 Visente i Sergi (versió Pascal)
// © 2025 Port a C++20 amb SDL3
//
// ==============================================================================
// DEPRECATED: Use core/rendering/shape_renderer.hpp instead
// ==============================================================================
// This file is kept temporarily for chatarra_cosmica_ (Phase 10: explosions)
// TODO Phase 10: Replace with particle system or remove completely
#pragma once
#include <SDL3/SDL.h>
#include "core/types.hpp"
namespace Rendering {
// Rotar i dibuixar triangle (nau)
void rota_tri(SDL_Renderer* renderer, const Triangle& tri, float angul, float velocitat, bool dibuixar);
// Rotar i dibuixar polígon (enemics i bales)
void rota_pol(SDL_Renderer* renderer, const Poligon& pol, float angul, bool dibuixar);
} // namespace Rendering
-66
View File
@@ -1,66 +0,0 @@
// primitives.cpp - Implementació de funcions geomètriques
// © 1999 Visente i Sergi (versió Pascal)
// © 2025 Port a C++20 amb SDL3
//
// ==============================================================================
// DEPRECATED: Use Shape system instead (.shp files + ShapeLoader)
// ==============================================================================
#include "primitives.hpp"
#include <cmath>
#include "core/defaults.hpp"
float modul(const Punt& p) {
// Càlcul de la magnitud d'un vector: sqrt(x² + y²)
return std::sqrt((p.x * p.x) + (p.y * p.y));
}
void diferencia(const Punt& o, const Punt& d, Punt& p) {
// Resta de vectors (origen - destí)
p.x = o.x - d.x;
p.y = o.y - d.y;
}
int distancia(const Punt& o, const Punt& d) {
// Distància entre dos punts
Punt p;
diferencia(o, d, p);
return static_cast<int>(std::round(modul(p)));
}
float angle_punt(const Punt& p) {
// Càlcul de l'angle d'un punt (arctan)
if (p.y != 0) {
return std::atan(p.x / p.y);
}
return 0.0F;
}
void crear_poligon_regular(Poligon& pol, uint8_t n, float r) {
// Crear un polígon regular amb n costats i radi r
// Distribueix els punts uniformement al voltant d'un cercle
float interval = 2.0F * Defaults::Math::PI / n;
float act = 0.0F;
for (uint8_t i = 0; i < n; i++) {
pol.ipuntx[i].r = r;
pol.ipuntx[i].angle = act;
act += interval;
}
// Inicialitzar propietats del polígon
pol.centre.x = 320.0F;
pol.centre.y = 200.0F;
pol.angle = 0.0F;
// Convertir velocitat de px/frame a px/s: 2 px/frame × 20 FPS = 40 px/s
pol.velocitat = Defaults::Physics::ENEMY_SPEED * 20.0F;
pol.n = n;
// Convertir rotació de rad/frame a rad/s: 0.0785 rad/frame × 20 FPS = 1.57
// rad/s (~90°/s)
pol.drotacio = 0.078539816F * 20.0F;
pol.rotacio = 0.0F;
pol.esta = true;
}
-32
View File
@@ -1,32 +0,0 @@
// primitives.hpp - Funcions geomètriques bàsiques
// © 1999 Visente i Sergi (versió Pascal)
// © 2025 Port a C++20 amb SDL3
//
// ==============================================================================
// DEPRECATED: Use Shape system instead (.shp files + ShapeLoader)
// ==============================================================================
// This file is kept temporarily for chatarra_cosmica_ (Phase 10: explosions)
// TODO Phase 10: Replace with particle system or remove completely
#pragma once
#include <cstdint>
#include "core/types.hpp"
// Funcions matemàtiques geomètriques pures (sense dependències d'estat)
// Càlcul de la magnitud d'un vector
float modul(const Punt& p);
// Diferència entre dos punts (vector origen - destí)
void diferencia(const Punt& o, const Punt& d, Punt& p);
// Distància entre dos punts
int distancia(const Punt& o, const Punt& d);
// Càlcul de l'angle d'un punt
float angle_punt(const Punt& p);
// Creació de polígons regulars
void crear_poligon_regular(Poligon& pol, uint8_t n, float r);
+4 -3
View File
@@ -77,7 +77,6 @@ void render_shape(SDL_Renderer* renderer,
const Punt& posicio, const Punt& posicio,
float angle, float angle,
float escala, float escala,
bool dibuixar,
float progress, float progress,
float brightness, float brightness,
const Rotation3D* rotation_3d) { const Rotation3D* rotation_3d) {
@@ -102,7 +101,8 @@ void render_shape(SDL_Renderer* renderer,
Punt p1 = transform_point(primitive.points[i], shape_centre, posicio, angle, escala, rotation_3d); Punt p1 = transform_point(primitive.points[i], shape_centre, posicio, angle, escala, rotation_3d);
Punt p2 = transform_point(primitive.points[i + 1], shape_centre, posicio, angle, escala, rotation_3d); Punt p2 = transform_point(primitive.points[i + 1], shape_centre, posicio, angle, escala, rotation_3d);
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y), static_cast<int>(p2.x), static_cast<int>(p2.y), dibuixar, brightness); linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
} }
} else { // PrimitiveType::LINE } else { // PrimitiveType::LINE
// LINE: exactament 2 punts // LINE: exactament 2 punts
@@ -110,7 +110,8 @@ void render_shape(SDL_Renderer* renderer,
Punt p1 = transform_point(primitive.points[0], shape_centre, posicio, angle, escala, rotation_3d); Punt p1 = transform_point(primitive.points[0], shape_centre, posicio, angle, escala, rotation_3d);
Punt p2 = transform_point(primitive.points[1], shape_centre, posicio, angle, escala, rotation_3d); Punt p2 = transform_point(primitive.points[1], shape_centre, posicio, angle, escala, rotation_3d);
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y), static_cast<int>(p2.x), static_cast<int>(p2.y), dibuixar, brightness); linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
} }
} }
} }
-2
View File
@@ -38,7 +38,6 @@ struct Rotation3D {
// - posicio: posició del centre en coordenades mundials // - posicio: posició del centre en coordenades mundials
// - angle: rotació en radians (0 = amunt, sentit horari) // - angle: rotació en radians (0 = amunt, sentit horari)
// - escala: factor d'escala (1.0 = mida original) // - escala: factor d'escala (1.0 = mida original)
// - dibuixar: flag per dibuixar (false per col·lisions futures)
// - progress: progrés de l'animació (0.0-1.0, default 1.0 = tot visible) // - progress: progrés de l'animació (0.0-1.0, default 1.0 = tot visible)
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor) // - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
void render_shape(SDL_Renderer* renderer, void render_shape(SDL_Renderer* renderer,
@@ -46,7 +45,6 @@ void render_shape(SDL_Renderer* renderer,
const Punt& posicio, const Punt& posicio,
float angle, float angle,
float escala = 1.0F, float escala = 1.0F,
bool dibuixar = true,
float progress = 1.0F, float progress = 1.0F,
float brightness = 1.0F, float brightness = 1.0F,
const Rotation3D* rotation_3d = nullptr); const Rotation3D* rotation_3d = nullptr);
+1 -38
View File
@@ -1,43 +1,6 @@
#pragma once #pragma once
#include <array> // Punt cartesià - ÚNICA estructura de coordenades del joc
#include <cstdint>
#include "core/defaults.hpp"
// Punt polar (coordenades polars)
struct IPunt {
float r; // Radi
float angle; // Angle en radians
};
// Punt cartesià
struct Punt { struct Punt {
float x, y; float x, y;
}; };
// ==============================================================================
// DEPRECATED: Legacy types (replaced by Shape system)
// ==============================================================================
// These types are kept temporarily for chatarra_cosmica_ (Phase 10: explosions)
// TODO Phase 10: Replace with particle system or remove completely
// Nau (triangle) - DEPRECATED: Now using Shape system (ship.shp)
struct Triangle {
IPunt p1, p2, p3;
Punt centre;
float angle;
float velocitat;
};
// Polígon (enemics i bales) - DEPRECATED: Now using Shape system (.shp files)
struct Poligon {
std::array<IPunt, Defaults::Entities::MAX_IPUNTS> ipuntx;
Punt centre;
float angle;
float velocitat;
uint8_t n;
float drotacio;
float rotacio;
bool esta;
};
+1 -2
View File
@@ -14,8 +14,7 @@ constexpr int MARGE_DALT = static_cast<int>(Defaults::Zones::PLAYAREA.y);
constexpr int MARGE_BAIX = constexpr int MARGE_BAIX =
static_cast<int>(Defaults::Zones::PLAYAREA.y + Defaults::Zones::PLAYAREA.h); static_cast<int>(Defaults::Zones::PLAYAREA.y + Defaults::Zones::PLAYAREA.h);
// Límits de polígons i objectes // Límits d'objectes
constexpr int MAX_IPUNTS = Defaults::Entities::MAX_IPUNTS;
constexpr int MAX_ORNIS = Defaults::Entities::MAX_ORNIS; constexpr int MAX_ORNIS = Defaults::Entities::MAX_ORNIS;
constexpr int MAX_BALES = Defaults::Entities::MAX_BALES; constexpr int MAX_BALES = Defaults::Entities::MAX_BALES;
-1
View File
@@ -314,7 +314,6 @@ void DebrisManager::dibuixar() const {
static_cast<int>(debris.p1.y), static_cast<int>(debris.p1.y),
static_cast<int>(debris.p2.x), static_cast<int>(debris.p2.x),
static_cast<int>(debris.p2.y), static_cast<int>(debris.p2.y),
true,
debris.brightness); debris.brightness);
} }
} }
+1
View File
@@ -7,6 +7,7 @@
#include <array> #include <array>
#include <memory> #include <memory>
#include "core/defaults.hpp"
#include "core/graphics/shape.hpp" #include "core/graphics/shape.hpp"
#include "core/types.hpp" #include "core/types.hpp"
#include "debris.hpp" #include "debris.hpp"
+1 -1
View File
@@ -87,7 +87,7 @@ void Bala::dibuixar() const {
if (esta_ && forma_) { if (esta_ && forma_) {
// [NUEVO] Usar render_shape en lloc de rota_pol // [NUEVO] Usar render_shape en lloc de rota_pol
// Les bales roten segons l'angle de trajectòria // Les bales roten segons l'angle de trajectòria
Rendering::render_shape(renderer_, forma_, centre_, angle_, 1.0F, true, 1.0F, brightness_); Rendering::render_shape(renderer_, forma_, centre_, angle_, 1.0F, 1.0F, brightness_);
} }
} }
+1 -1
View File
@@ -185,7 +185,7 @@ void Enemic::dibuixar() const {
float escala = calcular_escala_actual(); float escala = calcular_escala_actual();
// brightness_ is already updated in actualitzar() // brightness_ is already updated in actualitzar()
Rendering::render_shape(renderer_, forma_, centre_, rotacio_, escala, true, 1.0F, brightness_); Rendering::render_shape(renderer_, forma_, centre_, rotacio_, escala, 1.0F, brightness_);
} }
} }
+1 -1
View File
@@ -167,7 +167,7 @@ void Nau::dibuixar() const {
float velocitat_visual = velocitat_ / 33.33F; float velocitat_visual = velocitat_ / 33.33F;
float escala = 1.0F + (velocitat_visual / 12.0F); float escala = 1.0F + (velocitat_visual / 12.0F);
Rendering::render_shape(renderer_, forma_, centre_, angle_, escala, true, 1.0F, brightness_); Rendering::render_shape(renderer_, forma_, centre_, angle_, escala, 1.0F, brightness_);
} }
void Nau::aplicar_fisica(float delta_time) { void Nau::aplicar_fisica(float delta_time) {
+10 -10
View File
@@ -745,10 +745,10 @@ void EscenaJoc::dibuixar_marges() const {
int y2 = static_cast<int>(zona.y + zona.h); int y2 = static_cast<int>(zona.y + zona.h);
// 4 línies per formar el rectangle // 4 línies per formar el rectangle
Rendering::linea(sdl_.obte_renderer(), x1, y1, x2, y1, true); // Top Rendering::linea(sdl_.obte_renderer(), x1, y1, x2, y1); // Top
Rendering::linea(sdl_.obte_renderer(), x1, y2, x2, y2, true); // Bottom Rendering::linea(sdl_.obte_renderer(), x1, y2, x2, y2); // Bottom
Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2, true); // Left Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2); // Left
Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2, true); // Right Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2); // Right
} }
void EscenaJoc::dibuixar_marcador() { void EscenaJoc::dibuixar_marcador() {
@@ -794,11 +794,11 @@ void EscenaJoc::dibuixar_marges_animat(float progress) const {
// Línia esquerra: creix des del centre cap a l'esquerra // Línia esquerra: creix des del centre cap a l'esquerra
int x1_phase1 = static_cast<int>(cx - ((cx - x1) * phase1_progress)); int x1_phase1 = static_cast<int>(cx - ((cx - x1) * phase1_progress));
Rendering::linea(sdl_.obte_renderer(), cx, y1, x1_phase1, y1, true); Rendering::linea(sdl_.obte_renderer(), cx, y1, x1_phase1, y1);
// Línia dreta: creix des del centre cap a la dreta // Línia dreta: creix des del centre cap a la dreta
int x2_phase1 = static_cast<int>(cx + ((x2 - cx) * phase1_progress)); int x2_phase1 = static_cast<int>(cx + ((x2 - cx) * phase1_progress));
Rendering::linea(sdl_.obte_renderer(), cx, y1, x2_phase1, y1, true); Rendering::linea(sdl_.obte_renderer(), cx, y1, x2_phase1, y1);
} }
// --- FASE 2: Línies verticals laterals (33-66%) --- // --- FASE 2: Línies verticals laterals (33-66%) ---
@@ -807,10 +807,10 @@ void EscenaJoc::dibuixar_marges_animat(float progress) const {
// Línia esquerra: creix des de dalt cap a baix // Línia esquerra: creix des de dalt cap a baix
int y2_phase2 = static_cast<int>(y1 + ((y2 - y1) * phase2_progress)); int y2_phase2 = static_cast<int>(y1 + ((y2 - y1) * phase2_progress));
Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2_phase2, true); Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2_phase2);
// Línia dreta: creix des de dalt cap a baix // Línia dreta: creix des de dalt cap a baix
Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2_phase2, true); Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2_phase2);
} }
// --- FASE 3: Línies horitzontals inferiors (66-100%) --- // --- FASE 3: Línies horitzontals inferiors (66-100%) ---
@@ -819,11 +819,11 @@ void EscenaJoc::dibuixar_marges_animat(float progress) const {
// Línia esquerra: creix des de l'esquerra cap al centre // Línia esquerra: creix des de l'esquerra cap al centre
int x_left_phase3 = static_cast<int>(x1 + ((cx - x1) * phase3_progress)); int x_left_phase3 = static_cast<int>(x1 + ((cx - x1) * phase3_progress));
Rendering::linea(sdl_.obte_renderer(), x1, y2, x_left_phase3, y2, true); Rendering::linea(sdl_.obte_renderer(), x1, y2, x_left_phase3, y2);
// Línia dreta: creix des de la dreta cap al centre // Línia dreta: creix des de la dreta cap al centre
int x_right_phase3 = static_cast<int>(x2 - ((x2 - cx) * phase3_progress)); int x_right_phase3 = static_cast<int>(x2 - ((x2 - cx) * phase3_progress));
Rendering::linea(sdl_.obte_renderer(), x2, y2, x_right_phase3, y2, true); Rendering::linea(sdl_.obte_renderer(), x2, y2, x_right_phase3, y2);
} }
} }
+1 -3
View File
@@ -55,7 +55,6 @@ class EscenaJoc {
std::array<Nau, 2> naus_; // [0]=P1, [1]=P2 std::array<Nau, 2> naus_; // [0]=P1, [1]=P2
std::array<Enemic, Constants::MAX_ORNIS> orni_; std::array<Enemic, Constants::MAX_ORNIS> orni_;
std::array<Bala, Constants::MAX_BALES * 2> bales_; // 6 balas: P1=[0,1,2], P2=[3,4,5] std::array<Bala, Constants::MAX_BALES * 2> bales_; // 6 balas: P1=[0,1,2], P2=[3,4,5]
Poligon chatarra_cosmica_;
std::array<float, 2> itocado_per_jugador_; // Death timers per player (seconds) std::array<float, 2> itocado_per_jugador_; // Death timers per player (seconds)
// Lives and game over system // Lives and game over system
@@ -65,8 +64,7 @@ class EscenaJoc {
float continue_tick_timer_; // Timer for countdown tick (1.0s) float continue_tick_timer_; // Timer for countdown tick (1.0s)
int continues_usados_; // Continues used this game (0-3 max) int continues_usados_; // Continues used this game (0-3 max)
float game_over_timer_; // Final GAME OVER timer before title screen float game_over_timer_; // Final GAME OVER timer before title screen
// Punt punt_spawn_; // DEPRECATED: usar obtenir_punt_spawn(player_id) Punt punt_mort_; // Death position (for respawn)
Punt punt_mort_; // Death position (for respawn, legacy)
std::array<int, 2> puntuacio_per_jugador_; // [0]=P1, [1]=P2 std::array<int, 2> puntuacio_per_jugador_; // [0]=P1, [1]=P2
// Text vectorial // Text vectorial
-2
View File
@@ -379,7 +379,6 @@ void EscenaLogo::dibuixar() {
pos_actual, pos_actual,
0.0F, 0.0F,
escala_actual, escala_actual,
true,
1.0F); 1.0F);
} }
} }
@@ -403,7 +402,6 @@ void EscenaLogo::dibuixar() {
lletra.posicio, lletra.posicio,
0.0F, 0.0F,
ESCALA_FINAL, ESCALA_FINAL,
true,
1.0F); 1.0F);
} }
} }
-4
View File
@@ -593,7 +593,6 @@ void EscenaTitol::dibuixar() {
pos_shadow, pos_shadow,
0.0F, 0.0F,
Defaults::Title::Layout::LOGO_SCALE, Defaults::Title::Layout::LOGO_SCALE,
true,
1.0F, // progress = 1.0 (totalment visible) 1.0F, // progress = 1.0 (totalment visible)
SHADOW_BRIGHTNESS // brightness = 0.4 (brillantor reduïda) SHADOW_BRIGHTNESS // brightness = 0.4 (brillantor reduïda)
); );
@@ -611,7 +610,6 @@ void EscenaTitol::dibuixar() {
pos_shadow, pos_shadow,
0.0F, 0.0F,
Defaults::Title::Layout::LOGO_SCALE, Defaults::Title::Layout::LOGO_SCALE,
true,
1.0F, // progress = 1.0 (totalment visible) 1.0F, // progress = 1.0 (totalment visible)
SHADOW_BRIGHTNESS); SHADOW_BRIGHTNESS);
} }
@@ -627,7 +625,6 @@ void EscenaTitol::dibuixar() {
lletra.posicio, lletra.posicio,
0.0F, 0.0F,
Defaults::Title::Layout::LOGO_SCALE, Defaults::Title::Layout::LOGO_SCALE,
true,
1.0F // Brillantor completa 1.0F // Brillantor completa
); );
} }
@@ -640,7 +637,6 @@ void EscenaTitol::dibuixar() {
lletra.posicio, lletra.posicio,
0.0F, 0.0F,
Defaults::Title::Layout::LOGO_SCALE, Defaults::Title::Layout::LOGO_SCALE,
true,
1.0F // Brillantor completa 1.0F // Brillantor completa
); );
} }
-1
View File
@@ -67,7 +67,6 @@ void ShipAnimator::dibuixar() const {
nau.posicio_actual, nau.posicio_actual,
0.0F, // angle (rotació 2D no utilitzada) 0.0F, // angle (rotació 2D no utilitzada)
nau.escala_actual, nau.escala_actual,
true, // dibuixar
1.0F, // progress (sempre visible) 1.0F, // progress (sempre visible)
1.0F // brightness (brillantor màxima) 1.0F // brightness (brillantor màxima)
); );