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:
@@ -2,6 +2,8 @@
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Effects {
|
||||
@@ -31,7 +33,8 @@ struct Debris {
|
||||
float factor_shrink; // Factor de reducció per segon (0.0-1.0)
|
||||
|
||||
// Rendering
|
||||
float brightness; // Factor de brightness (0.0-1.0, heretat de l'objecte original)
|
||||
float brightness; // Factor de brightness (0.0-1.0, heretat de l'objecte original)
|
||||
SDL_Color color{}; // Color heredado del padre. alpha==0 → usa global oscilador
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
|
||||
@@ -53,7 +53,8 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& velocitat_objecte,
|
||||
float velocitat_angular,
|
||||
float factor_herencia_visual,
|
||||
const std::string& sound) {
|
||||
const std::string& sound,
|
||||
SDL_Color color) {
|
||||
if (!shape || !shape->isValid()) {
|
||||
return;
|
||||
}
|
||||
@@ -195,8 +196,9 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->temps_max = Defaults::Physics::Debris::TEMPS_VIDA;
|
||||
debris->factor_shrink = Defaults::Physics::Debris::SHRINK_RATE;
|
||||
|
||||
// 8. Heredar brightness
|
||||
// 8. Heredar brightness y color del padre
|
||||
debris->brightness = brightness;
|
||||
debris->color = color;
|
||||
|
||||
// 9. Activar
|
||||
debris->active = true;
|
||||
@@ -308,13 +310,13 @@ void DebrisManager::draw() const {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Dibuixar segment de línia con brightness heretat
|
||||
// Dibujar segmento con brightness y color heredados del padre.
|
||||
Rendering::linea(renderer_,
|
||||
static_cast<int>(debris.p1.x),
|
||||
static_cast<int>(debris.p1.y),
|
||||
static_cast<int>(debris.p2.x),
|
||||
static_cast<int>(debris.p2.y),
|
||||
debris.brightness);
|
||||
debris.brightness, 0.0F, debris.color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ class DebrisManager {
|
||||
const Vec2& velocitat_objecte = {.x = 0.0F, .y = 0.0F},
|
||||
float velocitat_angular = 0.0F,
|
||||
float factor_herencia_visual = 0.0F,
|
||||
const std::string& sound = Defaults::Sound::EXPLOSION);
|
||||
const std::string& sound = Defaults::Sound::EXPLOSION,
|
||||
SDL_Color color = {0, 0, 0, 0}); // alpha==0 → fragmentos usan oscilador global
|
||||
|
||||
// Actualitzar todos los fragments active
|
||||
void update(float delta_time);
|
||||
|
||||
@@ -137,6 +137,7 @@ void Bullet::desactivar() {
|
||||
void Bullet::draw() const {
|
||||
if (esta_ && shape_) {
|
||||
// Les bales roten segons l'angle de trayectòria (estático tras disparo)
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_);
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, Defaults::Palette::BULLET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,14 @@ void Enemy::draw() const {
|
||||
return;
|
||||
}
|
||||
const float SCALE = computeCurrentScale();
|
||||
Rendering::render_shape(renderer_, shape_, center_, rotacio_, SCALE, 1.0F, brightness_);
|
||||
SDL_Color color{};
|
||||
switch (type_) {
|
||||
case EnemyType::PENTAGON: color = Defaults::Palette::PENTAGON; break;
|
||||
case EnemyType::QUADRAT: color = Defaults::Palette::QUADRAT; break;
|
||||
case EnemyType::MOLINILLO: color = Defaults::Palette::MOLINILLO; break;
|
||||
}
|
||||
Rendering::render_shape(renderer_, shape_, center_, rotacio_, SCALE, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, color);
|
||||
}
|
||||
|
||||
void Enemy::destruir() {
|
||||
|
||||
@@ -160,5 +160,6 @@ void Ship::draw() const {
|
||||
const float VISUAL_PUSH = SPEED / 33.33F;
|
||||
const float SCALE = 1.0F + (VISUAL_PUSH / 12.0F);
|
||||
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, SCALE, 1.0F, brightness_);
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, SCALE, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, Defaults::Palette::SHIP);
|
||||
}
|
||||
|
||||
@@ -753,7 +753,8 @@ void GameScene::tocado(uint8_t player_id) {
|
||||
vel_nau_80, // Heredar 80% velocity
|
||||
0.0F, // Nave: trayectorias rectas (sin drotacio)
|
||||
0.0F, // Sin herencia visual (rotación aleatoria)
|
||||
Defaults::Sound::EXPLOSION2 // Sonido alternativo para la explosión
|
||||
Defaults::Sound::EXPLOSION2, // Sonido alternativo para la explosión
|
||||
Defaults::Palette::SHIP // Debris hereda color de la nave
|
||||
);
|
||||
|
||||
// Start death timer (non-zero to avoid re-triggering)
|
||||
|
||||
@@ -41,7 +41,13 @@ void detectBulletEnemy(Context& ctx) {
|
||||
ctx.score_per_player[owner_id] += points;
|
||||
ctx.floating_score_manager.crear(points, POS_ENEMIC);
|
||||
|
||||
// 2. Destruir enemy + crear explosión
|
||||
// 2. Destruir enemy + crear explosión (debris hereda color del enemy)
|
||||
SDL_Color enemy_color{};
|
||||
switch (enemy.getType()) {
|
||||
case EnemyType::PENTAGON: enemy_color = Defaults::Palette::PENTAGON; break;
|
||||
case EnemyType::QUADRAT: enemy_color = Defaults::Palette::QUADRAT; break;
|
||||
case EnemyType::MOLINILLO: enemy_color = Defaults::Palette::MOLINILLO; break;
|
||||
}
|
||||
enemy.destruir();
|
||||
Vec2 vel_enemic = enemy.getVelocityVector();
|
||||
ctx.debris_manager.explode(
|
||||
@@ -53,7 +59,9 @@ void detectBulletEnemy(Context& ctx) {
|
||||
enemy.getBrightness(),
|
||||
vel_enemic,
|
||||
enemy.getRotationDelta(),
|
||||
0.0F // sin herencia visual
|
||||
0.0F, // sin herencia visual
|
||||
Defaults::Sound::EXPLOSION,
|
||||
enemy_color
|
||||
);
|
||||
|
||||
// 3. Desactivar bullet (solo destruye 1 enemy)
|
||||
|
||||
Reference in New Issue
Block a user