Files
orni-attack/source/game/entities/nau.hpp
T
JailDesigner cd38101f99 Fase 1a: Punt -> Vec2 amb operadors moderns
Primera sub-fase del naming sweep. Punt era un struct sense
operacions, conservat per compatibilitat amb el Pascal original.
Substituit per Vec2, un aggregate amb operadors aritmetics, dot,
length, normalized i length_squared (camelBack: lengthSquared)
seguint les regles del .clang-tidy del projecte.

Canvis:
- core/types.hpp reescrit: nou struct Vec2 amb +=,-=,*=,/=,
  unary -, ==, dot, length, lengthSquared, normalized
- Operadors fora de la classe: +, -, *, / (amb float per ambdues
  bandes), - unari, ==
- Vec2 segueix sent aggregate (sense constructors definits):
  els 'designated initializers' del codi existent funcionen igual:
  Vec2{.x = ..., .y = ...}
- Sed global sobre 35 fitxers: tots els 'Punt' -> 'Vec2'

Net: 35 fitxers tocats, +180 / -114. Compila i enllaça.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 11:33:27 +02:00

63 lines
2.2 KiB
C++

// nau.hpp - Classe per a la nave del jugador
// © 1999 Visente i Sergi (versió Pascal)
// © 2025 Port a C++20 amb SDL3
#pragma once
#include <SDL3/SDL.h>
#include <cmath>
#include <cstdint>
#include "core/defaults.hpp"
#include "core/entities/entitat.hpp"
#include "core/types.hpp"
#include "game/constants.hpp"
class Nau : public Entities::Entitat {
public:
Nau()
: Entitat(nullptr) {}
Nau(SDL_Renderer* renderer, const char* shape_file = "ship.shp");
void inicialitzar() override { inicialitzar(nullptr, false); }
void inicialitzar(const Vec2* spawn_point, bool activar_invulnerabilitat = false);
void processar_input(float delta_time, uint8_t player_id);
void actualitzar(float delta_time) override;
void dibuixar() const override;
// Override: Interfície d'Entitat
[[nodiscard]] bool esta_actiu() const override { return !esta_tocada_; }
// Override: Interfície de col·lisió
[[nodiscard]] float get_collision_radius() const override {
return Defaults::Entities::SHIP_RADIUS;
}
[[nodiscard]] bool es_collidable() const override {
return !esta_tocada_ && invulnerable_timer_ <= 0.0F;
}
// Getters (API pública sense canvis)
[[nodiscard]] bool esta_viva() const { return !esta_tocada_; }
[[nodiscard]] bool esta_tocada() const { return esta_tocada_; }
[[nodiscard]] bool es_invulnerable() const { return invulnerable_timer_ > 0.0F; }
[[nodiscard]] Vec2 get_velocitat_vector() const {
return {
.x = velocitat_ * std::cos(angle_ - (Constants::PI / 2.0F)),
.y = velocitat_ * std::sin(angle_ - (Constants::PI / 2.0F))};
}
// Setters
void set_centre(const Vec2& nou_centre) { centre_ = nou_centre; }
// Col·lisions (Fase 10)
void marcar_tocada() { esta_tocada_ = true; }
private:
// Membres específics de Nau (heretats: renderer_, forma_, centre_, angle_, brightness_)
float velocitat_; // Velocitat (px/s)
bool esta_tocada_;
float invulnerable_timer_; // 0.0f = vulnerable, >0.0f = invulnerable
void aplicar_fisica(float delta_time);
};