57 lines
1.8 KiB
C++
57 lines
1.8 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 <memory>
|
|
|
|
#include "core/graphics/shape.hpp"
|
|
#include "core/types.hpp"
|
|
#include "game/constants.hpp"
|
|
|
|
class Nau {
|
|
public:
|
|
Nau()
|
|
: renderer_(nullptr) {}
|
|
Nau(SDL_Renderer* renderer);
|
|
|
|
void inicialitzar(const Punt* spawn_point = nullptr);
|
|
void processar_input(float delta_time);
|
|
void actualitzar(float delta_time);
|
|
void dibuixar() const;
|
|
|
|
// Getters (API pública sense canvis)
|
|
const Punt& get_centre() const { return centre_; }
|
|
float get_angle() const { return angle_; }
|
|
bool esta_viva() const { return !esta_tocada_; }
|
|
const std::shared_ptr<Graphics::Shape>& get_forma() const { return forma_; }
|
|
float get_brightness() const { return brightness_; }
|
|
Punt get_velocitat_vector() const {
|
|
return {
|
|
velocitat_ * std::cos(angle_ - Constants::PI / 2.0f),
|
|
velocitat_ * std::sin(angle_ - Constants::PI / 2.0f)
|
|
};
|
|
}
|
|
|
|
// Col·lisions (Fase 10)
|
|
void marcar_tocada() { esta_tocada_ = true; }
|
|
|
|
private:
|
|
SDL_Renderer* renderer_;
|
|
|
|
// [NUEVO] Forma vectorial (compartida, només 1 instància de Nau però preparat
|
|
// per reutilització)
|
|
std::shared_ptr<Graphics::Shape> forma_;
|
|
|
|
// [NUEVO] Estat de la instància (separat de la geometria)
|
|
Punt centre_;
|
|
float angle_; // Angle d'orientació
|
|
float velocitat_; // Velocitat (px/s)
|
|
bool esta_tocada_;
|
|
float brightness_; // Factor de brillantor (0.0-1.0)
|
|
|
|
void aplicar_fisica(float delta_time);
|
|
};
|