63 lines
2.2 KiB
C++
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 Punt* 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]] Punt 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 Punt& 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);
|
|
};
|