fa7da4ca58
El runtime de rendering pasa a SDL3 GPU. SDL_Renderer eliminado por completo del proyecto: SDLManager posee un GpuFrameRenderer y todo el resto del codigo habla con un Rendering::Renderer* opaco (alias del GpuFrameRenderer). Cambios principales: - core/rendering/render_context.hpp: alias central `using Rendering::Renderer = GPU::GpuFrameRenderer;` — punto unico de indireccion entre el juego y el backend de dibujo. - core/rendering/sdl_manager.hpp/cpp: deja de tener SDL_Renderer*; contiene un Rendering::Renderer gpu_renderer_. iniciar() ahora hace GpuDevice::init + pipeline; clear() llama beginFrame; present() llama endFrame. Letterbox se aplica via setViewport tras cada begin del render pass. toggleVSync() usa SDL_SetGPUSwapchainParameters. - core/rendering/line_renderer.hpp/cpp: la firma cambia a `linea(Renderer*, x1,y1,x2,y2, brightness, thickness)`. La implementacion deja de usar SDL_RenderLine: empuja la linea como quad extrudido al batch del GpuFrameRenderer. Se anade un grosor global configurable via setLineThickness (default 1.5 px). Ya no se aplica transform_x/y porque el shader hace logical->NDC y el viewport hace el letterbox. - gpu_frame_renderer: anade setViewport (aplicable mid-frame), setVSync (PRESENTMODE_VSYNC/IMMEDIATE) y applyViewport interno que re-aplica el viewport tras reabrir el render pass en flushBatch. - Sed sweep masivo en 19 archivos: SDL_Renderer* -> Rendering::Renderer* en headers y .cpp de entities, effects, graphics y title. Los archivos solo propagan el puntero — solo line_renderer consume sus metodos. SDL_Renderer queda eliminado del proyecto. Smoke test xvfb: backend Vulkan detectado, binario arranca, carga todos los shapes/audio/title, TitleScene inicializa, termina limpio con "Adeu!". stderr vacio. Validacion visual pendiente en hardware real (xvfb VMware sin 3D no muestra el swapchain Vulkan). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
4.7 KiB
C++
121 lines
4.7 KiB
C++
// enemy.hpp - Clase para enemigos (ORNIs)
|
|
// © 1999 Visente i Sergi (versión Pascal)
|
|
// © 2025 Port a C++20 con SDL3
|
|
|
|
#pragma once
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cstdint>
|
|
|
|
#include "core/defaults.hpp"
|
|
#include "core/entities/entity.hpp"
|
|
#include "core/types.hpp"
|
|
|
|
// Tipo de enemy
|
|
enum class EnemyType : uint8_t {
|
|
PENTAGON = 0, // Pentágono esquivador (zigzag)
|
|
QUADRAT = 1, // Cuadrado perseguidor (tracks ship)
|
|
MOLINILLO = 2 // Molinillo agresivo (rápido, girando)
|
|
};
|
|
|
|
// Estado de animación (palpitación + rotación acelerada)
|
|
struct EnemyAnimation {
|
|
// Palpitación (efecto respiración)
|
|
bool palpitacio_activa = false;
|
|
float palpitacio_fase = 0.0F;
|
|
float palpitacio_frequencia = 2.0F;
|
|
float palpitacio_amplitud = 0.15F;
|
|
float palpitacio_temps_restant = 0.0F;
|
|
|
|
// Aceleración de rotación visual (modulación a largo plazo)
|
|
float drotacio_base = 0.0F;
|
|
float drotacio_objetivo = 0.0F;
|
|
float drotacio_t = 0.0F;
|
|
float drotacio_duracio = 0.0F;
|
|
};
|
|
|
|
class Enemy : public Entities::Entity {
|
|
public:
|
|
Enemy()
|
|
: Entity(nullptr) {}
|
|
Enemy(Rendering::Renderer* renderer);
|
|
|
|
void init() override { init(EnemyType::PENTAGON, nullptr); }
|
|
void init(EnemyType type, const Vec2* ship_pos = nullptr);
|
|
void update(float delta_time) override;
|
|
void postUpdate(float delta_time) override;
|
|
void draw() const override;
|
|
|
|
// Override: Interfaz de Entity
|
|
[[nodiscard]] auto isActive() const -> bool override { return esta_; }
|
|
|
|
// Override: Interfaz de colisión
|
|
[[nodiscard]] auto getCollisionRadius() const -> float override {
|
|
return Defaults::Entities::ENEMY_RADIUS;
|
|
}
|
|
[[nodiscard]] auto isCollidable() const -> bool override {
|
|
return esta_ && timer_invulnerabilitat_ <= 0.0F;
|
|
}
|
|
|
|
// Marcar destruido (desactiva el cuerpo físicamente: radius=0)
|
|
void destruir();
|
|
|
|
// Getters
|
|
[[nodiscard]] auto getRotationDelta() const -> float { return drotacio_; }
|
|
[[nodiscard]] auto getVelocityVector() const -> Vec2 { return body_.velocity; }
|
|
|
|
// Set ship position reference for tracking behavior
|
|
void setShipPosition(const Vec2* ship_pos) { ship_position_ = ship_pos; }
|
|
|
|
// Stage system API (base stats)
|
|
[[nodiscard]] auto getBaseVelocity() const -> float;
|
|
[[nodiscard]] auto getBaseRotation() const -> float;
|
|
[[nodiscard]] auto getType() const -> EnemyType { return type_; }
|
|
|
|
// Setters para multiplicadores de dificultad (stage system).
|
|
// Establecen la velocidad escalar deseada manteniendo la dirección
|
|
// actual del body_.velocity.
|
|
void setVelocity(float speed);
|
|
void setRotation(float rot) {
|
|
drotacio_ = rot;
|
|
animacio_.drotacio_base = rot;
|
|
}
|
|
void setTrackingStrength(float strength);
|
|
|
|
// Invulnerabilidad
|
|
[[nodiscard]] auto isInvulnerable() const -> bool { return timer_invulnerabilitat_ > 0.0F; }
|
|
[[nodiscard]] auto getInvulnerabilityTime() const -> float { return timer_invulnerabilitat_; }
|
|
|
|
private:
|
|
// Miembros específicos (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
|
float drotacio_; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
|
float rotacio_; // Rotación visual acumulada (no afecta movimiento)
|
|
bool esta_;
|
|
|
|
EnemyType type_;
|
|
EnemyAnimation animacio_;
|
|
|
|
// Comportamiento type-specific
|
|
float tracking_timer_; // Quadrat: tiempo desde último update de dirección
|
|
const Vec2* ship_position_; // Puntero a posición de la nave (para tracking)
|
|
float tracking_strength_; // Quadrat: intensidad de tracking (0.0-1.5), default 0.5
|
|
float direction_change_timer_; // Pentagon: tiempo para próximo cambio de dirección
|
|
|
|
// Invulnerabilidad post-spawn
|
|
float timer_invulnerabilitat_;
|
|
|
|
// Métodos privados
|
|
void updateAnimation(float delta_time);
|
|
void updatePalpitation(float delta_time);
|
|
void updateRotationAcceleration(float delta_time);
|
|
void behaviorPentagon(float delta_time);
|
|
void behaviorQuadrat(float delta_time);
|
|
void behaviorMolinillo(float delta_time);
|
|
[[nodiscard]] auto computeCurrentScale() const -> float;
|
|
auto attemptSafeSpawn(const Vec2& ship_pos, float& out_x, float& out_y) -> bool;
|
|
|
|
// Helper: setear body_.velocity desde un ángulo y magnitud.
|
|
// angle_movement=0 apunta hacia arriba (eje Y negativo SDL).
|
|
void setVelocityFromAngle(float angle_movement, float speed);
|
|
};
|