Fase 8a+b: paleta semantica de color por entidad

Cada entity declara su color de linea via parametro opcional. Cuando
alpha==0 el pipeline cae al color global del oscilador (compatibilidad
con el comportamiento anterior).

Defaults::Palette (defaults.hpp):
- SHIP        = blanco neutro
- BULLET      = verde laser
- PENTAGON    = azul "esquivador"
- QUADRAT     = rojo "tank"
- MOLINILLO   = magenta agresivo

Pipeline:
- linea(): parametro SDL_Color color (default {0,0,0,0}). En .cpp,
  fuente del color = color.a>0 ? color : g_current_line_color.
- render_shape(): parametro SDL_Color color que propaga a cada linea
  del shape.
- Debris: campo color en la struct; explode() recibe SDL_Color color
  y lo guarda en cada fragment; draw() lo pasa a linea().

Aplicacion:
- Ship::draw -> Palette::SHIP.
- Bullet::draw -> Palette::BULLET.
- Enemy::draw -> Palette::{PENTAGON,QUADRAT,MOLINILLO} segun type_.
- CollisionSystem detectBulletEnemy: debris hereda color del enemy.
- GameScene::tocado: debris hereda Palette::SHIP.

Smoke test xvfb OK.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-20 08:04:56 +02:00
parent 5c9f6e6613
commit 6d7060ceb5
13 changed files with 73 additions and 41 deletions
+11
View File
@@ -107,6 +107,17 @@ constexpr float ENEMY_RADIUS = 20.0F;
constexpr float BULLET_RADIUS = 3.0F;
} // namespace Entities
// Paleta semántica por tipo de entidad. Si una entity declara color, lo
// pasa al pipeline con alpha=255 (sentinela "color válido"); si no, se
// usa el color global del oscilador (g_current_line_color).
namespace Palette {
constexpr SDL_Color SHIP = {.r = 255, .g = 255, .b = 255, .a = 255}; // Blanco neutro
constexpr SDL_Color BULLET = {.r = 120, .g = 255, .b = 140, .a = 255}; // Verde laser
constexpr SDL_Color PENTAGON = {.r = 120, .g = 170, .b = 255, .a = 255}; // Azul "esquivador"
constexpr SDL_Color QUADRAT = {.r = 255, .g = 110, .b = 110, .a = 255}; // Rojo "tank"
constexpr SDL_Color MOLINILLO = {.r = 255, .g = 130, .b = 255, .a = 255}; // Magenta agresivo
} // namespace Palette
// Ship (nave del player)
namespace Ship {
// Invulnerabilidad post-respawn
+7 -5
View File
@@ -16,7 +16,8 @@ float g_current_line_thickness = 1.5F;
void linea(Renderer* renderer,
int x1, int y1, int x2, int y2,
float brightness,
float thickness) {
float thickness,
SDL_Color color) {
if (renderer == nullptr) {
return;
}
@@ -28,10 +29,11 @@ void linea(Renderer* renderer,
const float FX2 = static_cast<float>(x2);
const float FY2 = static_cast<float>(y2);
// Color: aplicar brightness al color oscilatorio global. Convertir 0..255 → 0..1.
const float R = (static_cast<float>(g_current_line_color.r) * brightness) / 255.0F;
const float G = (static_cast<float>(g_current_line_color.g) * brightness) / 255.0F;
const float B = (static_cast<float>(g_current_line_color.b) * brightness) / 255.0F;
// color.alpha==0 → usar global del oscilador. alpha>0 → color directo.
const SDL_Color SOURCE = (color.a > 0) ? color : g_current_line_color;
const float R = (static_cast<float>(SOURCE.r) * brightness) / 255.0F;
const float G = (static_cast<float>(SOURCE.g) * brightness) / 255.0F;
const float B = (static_cast<float>(SOURCE.b) * brightness) / 255.0F;
const float W = (thickness > 0.0F) ? thickness : g_current_line_thickness;
+4 -1
View File
@@ -18,10 +18,13 @@ namespace Rendering {
// Dibuja una línea entre dos puntos en coordenadas lógicas (1280×720).
// brightness: factor de brillo (0.0..1.0, default 1.0 = brillo máximo).
// thickness: grosor en píxeles lógicos. Si <= 0 usa g_current_line_thickness.
// color: si alpha==0, se usa el color global del oscilador; si alpha>0 se
// usa este color directo (paleta semántica por entidad).
void linea(Renderer* renderer,
int x1, int y1, int x2, int y2,
float brightness = 1.0F,
float thickness = 0.0F);
float thickness = 0.0F,
SDL_Color color = {0, 0, 0, 0});
// Color global de las líneas (lo actualiza ColorOscillator vía SDLManager).
void setLineColor(SDL_Color color);
+13 -22
View File
@@ -79,40 +79,31 @@ void render_shape(Rendering::Renderer* renderer,
float scale,
float progress,
float brightness,
const Rotation3D* rotation_3d) {
// Verificar que la shape es vàlida
const Rotation3D* rotation_3d,
SDL_Color color) {
if (!shape || !shape->isValid()) {
return;
}
// Si progress < 1.0, no draw (tot o res)
if (progress < 1.0F) {
return;
}
// Obtenir el centro de la shape para transformacions
const Vec2& shape_centre = shape->getCenter();
const Vec2& SHAPE_CENTRE = shape->getCenter();
// Iterar sobre todas las primitives
for (const auto& primitive : shape->get_primitives()) {
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
// POLYLINE: connectar points consecutius
// POLYLINE: conectar puntos consecutivos.
for (size_t i = 0; i < primitive.points.size() - 1; i++) {
Vec2 p1 = transform_point(primitive.points[i], shape_centre, position, angle, scale, rotation_3d);
Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, position, angle, scale, rotation_3d);
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
// LINE: exactament 2 points
if (primitive.points.size() >= 2) {
Vec2 p1 = transform_point(primitive.points[0], shape_centre, position, angle, scale, rotation_3d);
Vec2 p2 = transform_point(primitive.points[1], shape_centre, position, angle, scale, rotation_3d);
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
const Vec2 P1 = transform_point(primitive.points[i], SHAPE_CENTRE, position, angle, scale, rotation_3d);
const Vec2 P2 = transform_point(primitive.points[i + 1], SHAPE_CENTRE, position, angle, scale, rotation_3d);
linea(renderer, static_cast<int>(P1.x), static_cast<int>(P1.y),
static_cast<int>(P2.x), static_cast<int>(P2.y), brightness, 0.0F, color);
}
} else if (primitive.points.size() >= 2) { // LINE
const Vec2 P1 = transform_point(primitive.points[0], SHAPE_CENTRE, position, angle, scale, rotation_3d);
const Vec2 P2 = transform_point(primitive.points[1], SHAPE_CENTRE, position, angle, scale, rotation_3d);
linea(renderer, static_cast<int>(P1.x), static_cast<int>(P1.y),
static_cast<int>(P2.x), static_cast<int>(P2.y), brightness, 0.0F, color);
}
}
}
+2 -1
View File
@@ -49,6 +49,7 @@ void render_shape(Rendering::Renderer* renderer,
float scale = 1.0F,
float progress = 1.0F,
float brightness = 1.0F,
const Rotation3D* rotation_3d = nullptr);
const Rotation3D* rotation_3d = nullptr,
SDL_Color color = {0, 0, 0, 0}); // alpha==0 → usa global oscilador
} // namespace Rendering