migrant a SDL3
This commit is contained in:
94
source/joc_asteroides.hpp
Normal file
94
source/joc_asteroides.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// joc_asteroides.hpp - Lògica principal del joc
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
#ifndef JOC_ASTEROIDES_HPP
|
||||
#define JOC_ASTEROIDES_HPP
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
// Espai de noms per a les constants del joc
|
||||
namespace Constants {
|
||||
constexpr int MARGE_DALT = 20;
|
||||
constexpr int MARGE_BAIX = 460;
|
||||
constexpr int MARGE_ESQ = 20;
|
||||
constexpr int MARGE_DRET = 620;
|
||||
constexpr int MAX_IPUNTS = 30;
|
||||
constexpr int MAX_ORNIS = 15;
|
||||
constexpr int VELOCITAT = 2;
|
||||
constexpr int VELOCITAT_MAX = 6;
|
||||
constexpr int MAX_BALES = 3;
|
||||
constexpr float PI = 3.14159265359f;
|
||||
}
|
||||
|
||||
// Estructures de dades (coordenades polars i cartesianes)
|
||||
struct IPunt {
|
||||
float r;
|
||||
float angle;
|
||||
};
|
||||
|
||||
struct Punt {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct Triangle {
|
||||
IPunt p1, p2, p3;
|
||||
Punt centre;
|
||||
float angle;
|
||||
float velocitat;
|
||||
};
|
||||
|
||||
struct Poligon {
|
||||
std::array<IPunt, Constants::MAX_IPUNTS> ipuntx;
|
||||
Punt centre;
|
||||
float angle;
|
||||
float velocitat;
|
||||
uint8_t n;
|
||||
float drotacio;
|
||||
float rotacio;
|
||||
bool esta;
|
||||
};
|
||||
|
||||
// Classe principal del joc
|
||||
class JocAsteroides {
|
||||
public:
|
||||
JocAsteroides(SDL_Renderer* renderer);
|
||||
~JocAsteroides() = default;
|
||||
|
||||
void inicialitzar();
|
||||
void actualitzar(float delta_time);
|
||||
void dibuixar();
|
||||
void processar_input(const SDL_Event& event);
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// Estat del joc
|
||||
Triangle nau_;
|
||||
std::array<Poligon, Constants::MAX_ORNIS> orni_;
|
||||
std::array<Poligon, Constants::MAX_BALES> bales_;
|
||||
Poligon chatarra_cosmica_;
|
||||
uint16_t itocado_;
|
||||
|
||||
// Funcions utilitàries (geometria)
|
||||
void crear_poligon_regular(Poligon& pol, uint8_t n, float r);
|
||||
float modul(const Punt& p) const;
|
||||
void diferencia(const Punt& o, const Punt& d, Punt& p) const;
|
||||
int distancia(const Punt& o, const Punt& d) const;
|
||||
float angle_punt(const Punt& p) const;
|
||||
|
||||
// Funcions de dibuix
|
||||
bool linea(int x1, int y1, int x2, int y2, bool dibuixar);
|
||||
void rota_tri(const Triangle& tri, float angul, float velocitat, bool dibuixar);
|
||||
void rota_pol(const Poligon& pol, float angul, bool dibuixar);
|
||||
|
||||
// Moviment
|
||||
void mou_orni(Poligon& orni);
|
||||
void mou_bales(Poligon& bala);
|
||||
void tocado();
|
||||
};
|
||||
|
||||
#endif // JOC_ASTEROIDES_HPP
|
||||
Reference in New Issue
Block a user