layout de TITOL
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
|
||||
#include "core/audio/audio_cache.hpp"
|
||||
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
|
||||
// Inicialització de variables estàtiques
|
||||
std::unordered_map<std::string, JA_Sound_t*> AudioCache::sounds_;
|
||||
std::unordered_map<std::string, JA_Music_t*> AudioCache::musics_;
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace Zones {
|
||||
// Totes les zones definides com a percentatges de Game::WIDTH (640) i Game::HEIGHT (480)
|
||||
|
||||
// Percentatges d'alçada (divisió vertical)
|
||||
constexpr float SCOREBOARD_TOP_HEIGHT_PERCENT = 0.02f; // 10% superior
|
||||
constexpr float MAIN_PLAYAREA_HEIGHT_PERCENT = 0.88f; // 80% central
|
||||
constexpr float SCOREBOARD_BOTTOM_HEIGHT_PERCENT = 0.10f; // 10% inferior
|
||||
constexpr float SCOREBOARD_TOP_HEIGHT_PERCENT = 0.02f; // 10% superior
|
||||
constexpr float MAIN_PLAYAREA_HEIGHT_PERCENT = 0.88f; // 80% central
|
||||
constexpr float SCOREBOARD_BOTTOM_HEIGHT_PERCENT = 0.10f; // 10% inferior
|
||||
|
||||
// Padding horizontal per a PLAYAREA (dins de MAIN_PLAYAREA)
|
||||
constexpr float PLAYAREA_PADDING_HORIZONTAL_PERCENT = 0.015f; // 5% a cada costat
|
||||
constexpr float PLAYAREA_PADDING_HORIZONTAL_PERCENT = 0.015f; // 5% a cada costat
|
||||
|
||||
// --- CÀLCULS AUTOMÀTICS DE PÍXELS ---
|
||||
// Càlculs automàtics a partir dels percentatges
|
||||
@@ -56,42 +56,42 @@ constexpr float PLAYAREA_PADDING_H = Game::WIDTH * PLAYAREA_PADDING_HORIZONTAL_P
|
||||
// Marcador superior (reservat per a futur ús)
|
||||
// Ocupa: 10% superior (0-48px)
|
||||
constexpr SDL_FRect SCOREBOARD_TOP = {
|
||||
0.0f, // x = 0.0
|
||||
SCOREBOARD_TOP_Y, // y = 0.0
|
||||
static_cast<float>(Game::WIDTH), // w = 640.0
|
||||
SCOREBOARD_TOP_H // h = 48.0
|
||||
0.0f, // x = 0.0
|
||||
SCOREBOARD_TOP_Y, // y = 0.0
|
||||
static_cast<float>(Game::WIDTH), // w = 640.0
|
||||
SCOREBOARD_TOP_H // h = 48.0
|
||||
};
|
||||
|
||||
// Àrea de joc principal (contenidor del 80% central, sense padding)
|
||||
// Ocupa: 10-90% (48-432px), ample complet
|
||||
constexpr SDL_FRect MAIN_PLAYAREA = {
|
||||
0.0f, // x = 0.0
|
||||
MAIN_PLAYAREA_Y, // y = 48.0
|
||||
static_cast<float>(Game::WIDTH), // w = 640.0
|
||||
MAIN_PLAYAREA_H // h = 384.0
|
||||
0.0f, // x = 0.0
|
||||
MAIN_PLAYAREA_Y, // y = 48.0
|
||||
static_cast<float>(Game::WIDTH), // w = 640.0
|
||||
MAIN_PLAYAREA_H // h = 384.0
|
||||
};
|
||||
|
||||
// Zona de joc real (amb padding horizontal del 5%)
|
||||
// Ocupa: dins de MAIN_PLAYAREA, amb marges laterals
|
||||
// S'utilitza per a límits del joc, col·lisions, spawn
|
||||
constexpr SDL_FRect PLAYAREA = {
|
||||
PLAYAREA_PADDING_H, // x = 32.0
|
||||
MAIN_PLAYAREA_Y, // y = 48.0 (igual que MAIN_PLAYAREA)
|
||||
Game::WIDTH - 2.0f * PLAYAREA_PADDING_H, // w = 576.0
|
||||
MAIN_PLAYAREA_H // h = 384.0 (igual que MAIN_PLAYAREA)
|
||||
PLAYAREA_PADDING_H, // x = 32.0
|
||||
MAIN_PLAYAREA_Y, // y = 48.0 (igual que MAIN_PLAYAREA)
|
||||
Game::WIDTH - 2.0f * PLAYAREA_PADDING_H, // w = 576.0
|
||||
MAIN_PLAYAREA_H // h = 384.0 (igual que MAIN_PLAYAREA)
|
||||
};
|
||||
|
||||
// Marcador inferior (marcador actual)
|
||||
// Ocupa: 10% inferior (432-480px)
|
||||
constexpr SDL_FRect SCOREBOARD = {
|
||||
0.0f, // x = 0.0
|
||||
SCOREBOARD_BOTTOM_Y, // y = 432.0
|
||||
static_cast<float>(Game::WIDTH), // w = 640.0
|
||||
SCOREBOARD_BOTTOM_H // h = 48.0
|
||||
0.0f, // x = 0.0
|
||||
SCOREBOARD_BOTTOM_Y, // y = 432.0
|
||||
static_cast<float>(Game::WIDTH), // w = 640.0
|
||||
SCOREBOARD_BOTTOM_H // h = 48.0
|
||||
};
|
||||
|
||||
// Padding horizontal del marcador (per alinear zones esquerra/dreta amb PLAYAREA)
|
||||
constexpr float SCOREBOARD_PADDING_H = 0.0f;//Game::WIDTH * 0.015f;
|
||||
constexpr float SCOREBOARD_PADDING_H = 0.0f; // Game::WIDTH * 0.015f;
|
||||
} // namespace Zones
|
||||
|
||||
// Objetos del juego
|
||||
@@ -361,55 +361,112 @@ constexpr int MOLINILLO_SCORE = 200; // Molinillo (agressiu, 50 px/s)
|
||||
// Title scene ship animations (naus 3D flotants a l'escena de títol)
|
||||
namespace Title {
|
||||
namespace Ships {
|
||||
// Posicions clock (coordenades polars des del centre 320, 240)
|
||||
// ============================================================
|
||||
// PARÀMETRES BASE (ajustar aquí per experimentar)
|
||||
// ============================================================
|
||||
|
||||
// 1. Escala global de les naus
|
||||
constexpr float SHIP_BASE_SCALE = 2.5f; // Multiplicador (1.0 = mida original del .shp)
|
||||
|
||||
// 2. Altura vertical (cercanía al centro)
|
||||
// Ratio Y desde el centro de la pantalla (0.0 = centro, 1.0 = bottom de pantalla)
|
||||
constexpr float TARGET_Y_RATIO = 0.15625f;
|
||||
|
||||
// 3. Radio orbital (distancia radial desde centro en coordenadas polares)
|
||||
constexpr float CLOCK_RADIUS = 150.0f; // Distància des del centre
|
||||
|
||||
// 4. Ángulos de posición (clock positions en coordenadas polares)
|
||||
// En coordenades de pantalla: 0° = dreta, 90° = baix, 180° = esquerra, 270° = dalt
|
||||
constexpr float CLOCK_8_ANGLE = 150.0f * Math::PI / 180.0f; // 8 o'clock = bottom-left
|
||||
constexpr float CLOCK_4_ANGLE = 30.0f * Math::PI / 180.0f; // 4 o'clock = bottom-right
|
||||
constexpr float CLOCK_RADIUS = 150.0f; // Distància des del centre
|
||||
constexpr float CLOCK_8_ANGLE = 150.0f * Math::PI / 180.0f; // 8 o'clock (bottom-left)
|
||||
constexpr float CLOCK_4_ANGLE = 30.0f * Math::PI / 180.0f; // 4 o'clock (bottom-right)
|
||||
|
||||
// P1 (8 o'clock, bottom-left)
|
||||
// 150° → cos(150°)=-0.866, sin(150°)=0.5 → X = 320 - 130 = 190, Y = 240 + 75 = 315
|
||||
constexpr float P1_TARGET_X = 190.0f;
|
||||
constexpr float P1_TARGET_Y = 315.0f;
|
||||
// 5. Radio máximo de la forma de la nave (para calcular offset automáticamente)
|
||||
constexpr float SHIP_MAX_RADIUS = 30.0f; // Radi del cercle circumscrit a ship_p1.shp
|
||||
|
||||
// P2 (4 o'clock, bottom-right)
|
||||
// 30° → cos(30°)=0.866, sin(30°)=0.5 → X = 320 + 130 = 450, Y = 240 + 75 = 315
|
||||
constexpr float P2_TARGET_X = 450.0f;
|
||||
constexpr float P2_TARGET_Y = 315.0f;
|
||||
// 6. Margen de seguridad para offset de entrada
|
||||
constexpr float ENTRY_OFFSET_MARGIN = 227.5f; // Para offset total de ~340px (ajustado)
|
||||
|
||||
// Escala base de les naus (ajusta aquí per fer-les més grans o petites)
|
||||
constexpr float SHIP_BASE_SCALE = 2.5f; // Multiplicador global (1.0 = mida original)
|
||||
// ============================================================
|
||||
// VALORS DERIVATS (calculats automàticament - NO modificar)
|
||||
// ============================================================
|
||||
|
||||
// Escales d'animació (perspectiva ja incorporada a les formes .shp)
|
||||
constexpr float ENTRY_SCALE_START = 1.5f * SHIP_BASE_SCALE; // Més gran per veure millor
|
||||
constexpr float FLOATING_SCALE = 1.0f * SHIP_BASE_SCALE; // Mida normal (més grans)
|
||||
// Centre de la pantalla (punt de referència)
|
||||
constexpr float CENTER_X = Game::WIDTH / 2.0f; // 320.0f
|
||||
constexpr float CENTER_Y = Game::HEIGHT / 2.0f; // 240.0f
|
||||
|
||||
// Animacions
|
||||
constexpr float ENTRY_DURATION = 2.0f; // Entrada
|
||||
constexpr float ENTRY_OFFSET = 340.0f; // Offset fora de pantalla (considera radi màxim 30px * escala 3.75 + marge)
|
||||
constexpr float EXIT_DURATION = 1.0f; // Sortida (configurable)
|
||||
// Posicions target (calculades dinàmicament des dels paràmetres base)
|
||||
// Nota: std::cos/sin no són constexpr en C++20, però funcionen en runtime
|
||||
// Les funcions inline són optimitzades pel compilador (zero overhead)
|
||||
inline float P1_TARGET_X() {
|
||||
return CENTER_X + CLOCK_RADIUS * std::cos(CLOCK_8_ANGLE);
|
||||
}
|
||||
inline float P1_TARGET_Y() {
|
||||
return CENTER_Y + (Game::HEIGHT / 2.0f) * TARGET_Y_RATIO;
|
||||
}
|
||||
inline float P2_TARGET_X() {
|
||||
return CENTER_X + CLOCK_RADIUS * std::cos(CLOCK_4_ANGLE);
|
||||
}
|
||||
inline float P2_TARGET_Y() {
|
||||
return CENTER_Y + (Game::HEIGHT / 2.0f) * TARGET_Y_RATIO;
|
||||
}
|
||||
|
||||
// Escales d'animació (relatives a SHIP_BASE_SCALE)
|
||||
constexpr float ENTRY_SCALE_START = 1.5f * SHIP_BASE_SCALE; // Entrada: 50% més gran
|
||||
constexpr float FLOATING_SCALE = 1.0f * SHIP_BASE_SCALE; // Flotant: escala base
|
||||
|
||||
// Offset d'entrada (ajustat automàticament a l'escala)
|
||||
// Fórmula: (radi màxim de la nau * escala d'entrada) + marge
|
||||
constexpr float ENTRY_OFFSET = (SHIP_MAX_RADIUS * ENTRY_SCALE_START) + ENTRY_OFFSET_MARGIN;
|
||||
|
||||
// Punt de fuga (centre per a l'animació de sortida)
|
||||
constexpr float VANISHING_POINT_X = CENTER_X; // 320.0f
|
||||
constexpr float VANISHING_POINT_Y = CENTER_Y; // 240.0f
|
||||
|
||||
// ============================================================
|
||||
// ANIMACIONS (durades, oscil·lacions, delays)
|
||||
// ============================================================
|
||||
|
||||
// Durades d'animació
|
||||
constexpr float ENTRY_DURATION = 2.0f; // Entrada (segons)
|
||||
constexpr float EXIT_DURATION = 1.0f; // Sortida (segons)
|
||||
|
||||
// Flotació (oscil·lació reduïda i diferenciada per nau)
|
||||
constexpr float FLOAT_AMPLITUDE_X = 4.0f; // Era 6.0f
|
||||
constexpr float FLOAT_AMPLITUDE_Y = 2.5f; // Era 4.0f
|
||||
constexpr float FLOAT_AMPLITUDE_X = 4.0f; // Amplitud X (píxels)
|
||||
constexpr float FLOAT_AMPLITUDE_Y = 2.5f; // Amplitud Y (píxels)
|
||||
|
||||
// Freqüències base
|
||||
constexpr float FLOAT_FREQUENCY_X_BASE = 0.5f;
|
||||
constexpr float FLOAT_FREQUENCY_Y_BASE = 0.7f;
|
||||
constexpr float FLOAT_PHASE_OFFSET = 1.57f; // π/2 (90°)
|
||||
constexpr float FLOAT_FREQUENCY_X_BASE = 0.5f; // Hz
|
||||
constexpr float FLOAT_FREQUENCY_Y_BASE = 0.7f; // Hz
|
||||
constexpr float FLOAT_PHASE_OFFSET = 1.57f; // π/2 (90°)
|
||||
|
||||
// Delays d'entrada
|
||||
constexpr float P1_ENTRY_DELAY = 0.0f; // P1 entra immediatament
|
||||
constexpr float P2_ENTRY_DELAY = 0.5f; // P2 entra 0.5s després
|
||||
// Delays d'entrada (per a entrada escalonada)
|
||||
constexpr float P1_ENTRY_DELAY = 0.0f; // P1 entra immediatament
|
||||
constexpr float P2_ENTRY_DELAY = 0.5f; // P2 entra 0.5s després
|
||||
|
||||
// Multiplicadors de freqüència per a cada nau (variació sutil ±12%)
|
||||
constexpr float P1_FREQUENCY_MULTIPLIER = 0.88f; // 12% més lenta
|
||||
constexpr float P2_FREQUENCY_MULTIPLIER = 1.12f; // 12% més ràpida
|
||||
|
||||
// Punt de fuga
|
||||
constexpr float VANISHING_POINT_X = Game::WIDTH / 2.0f; // 320.0f
|
||||
constexpr float VANISHING_POINT_Y = Game::HEIGHT / 2.0f; // 240.0f
|
||||
} // namespace Ships
|
||||
|
||||
namespace Layout {
|
||||
// Posicions verticals (anclatges des del TOP de pantalla lògica, 0.0-1.0)
|
||||
constexpr float LOGO_POS = 0.20f; // Logo "ORNI"
|
||||
constexpr float PRESS_START_POS = 0.73f; // "PRESS START TO PLAY"
|
||||
constexpr float COPYRIGHT1_POS = 0.87f; // Primera línia copyright
|
||||
|
||||
// Separacions relatives (proporció respecte Game::HEIGHT = 480px)
|
||||
constexpr float LOGO_LINE_SPACING = 0.02f; // Entre "ORNI" i "ATTACK!" (10px)
|
||||
constexpr float COPYRIGHT_LINE_SPACING = 0.0f; // Entre línies copyright (5px)
|
||||
|
||||
// Factors d'escala
|
||||
constexpr float LOGO_SCALE = 0.6f; // Escala "ORNI ATTACK!"
|
||||
constexpr float PRESS_START_SCALE = 1.0f; // Escala "PRESS START TO PLAY"
|
||||
constexpr float COPYRIGHT_SCALE = 0.5f; // Escala copyright
|
||||
|
||||
// Espaiat entre caràcters (usat per VectorText)
|
||||
constexpr float TEXT_SPACING = 2.0f;
|
||||
} // namespace Layout
|
||||
} // namespace Title
|
||||
|
||||
// Floating score numbers (números flotants de puntuació)
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include "core/graphics/shape_loader.hpp"
|
||||
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
// Inicialització de variables estàtiques
|
||||
|
||||
@@ -106,7 +106,7 @@ float Starfield::calcular_brightness(const Estrella& estrella) const {
|
||||
// distancia_centre: 0.0 (centre, llunyanes) → 1.0 (vora, properes)
|
||||
float brightness_base = Defaults::Brightness::STARFIELD_MIN +
|
||||
(Defaults::Brightness::STARFIELD_MAX - Defaults::Brightness::STARFIELD_MIN) *
|
||||
estrella.distancia_centre;
|
||||
estrella.distancia_centre;
|
||||
|
||||
// Aplicar multiplicador i limitar a 1.0
|
||||
return std::min(1.0f, brightness_base * multiplicador_brightness_);
|
||||
|
||||
@@ -72,10 +72,10 @@ class Starfield {
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// Configuració
|
||||
Punt punt_fuga_; // Punt d'origen de les estrelles
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distància màxima del centre al límit de pantalla
|
||||
int densitat_; // Nombre total d'estrelles
|
||||
Punt punt_fuga_; // Punt d'origen de les estrelles
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distància màxima del centre al límit de pantalla
|
||||
int densitat_; // Nombre total d'estrelles
|
||||
float multiplicador_brightness_{1.0f}; // Multiplicador de brillantor (1.0 = default)
|
||||
};
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ class Input {
|
||||
|
||||
private:
|
||||
// --- Constantes ---
|
||||
static constexpr Sint16 AXIS_THRESHOLD = 30000; // Umbral para ejes analógicos
|
||||
static constexpr Sint16 TRIGGER_THRESHOLD = 16384; // Umbral para triggers (50% del rango)
|
||||
static constexpr Sint16 AXIS_THRESHOLD = 30000; // Umbral para ejes analógicos
|
||||
static constexpr Sint16 TRIGGER_THRESHOLD = 16384; // Umbral para triggers (50% del rango)
|
||||
static constexpr std::array<Action, 1> BUTTON_INPUTS = {Action::SHOOT}; // Inputs que usan botones
|
||||
|
||||
// --- Métodos ---
|
||||
|
||||
@@ -4,57 +4,57 @@
|
||||
|
||||
// Definición de los mapas
|
||||
const std::unordered_map<InputAction, std::string> ACTION_TO_STRING = {
|
||||
{InputAction::LEFT, "LEFT"},
|
||||
{InputAction::RIGHT, "RIGHT"},
|
||||
{InputAction::THRUST, "THRUST"},
|
||||
{InputAction::SHOOT, "SHOOT"},
|
||||
{InputAction::WINDOW_INC_ZOOM, "WINDOW_INC_ZOOM"},
|
||||
{InputAction::WINDOW_DEC_ZOOM, "WINDOW_DEC_ZOOM"},
|
||||
{InputAction::TOGGLE_FULLSCREEN, "TOGGLE_FULLSCREEN"},
|
||||
{InputAction::TOGGLE_VSYNC, "TOGGLE_VSYNC"},
|
||||
{InputAction::EXIT, "EXIT"},
|
||||
{InputAction::NONE, "NONE"}};
|
||||
{InputAction::LEFT, "LEFT"},
|
||||
{InputAction::RIGHT, "RIGHT"},
|
||||
{InputAction::THRUST, "THRUST"},
|
||||
{InputAction::SHOOT, "SHOOT"},
|
||||
{InputAction::WINDOW_INC_ZOOM, "WINDOW_INC_ZOOM"},
|
||||
{InputAction::WINDOW_DEC_ZOOM, "WINDOW_DEC_ZOOM"},
|
||||
{InputAction::TOGGLE_FULLSCREEN, "TOGGLE_FULLSCREEN"},
|
||||
{InputAction::TOGGLE_VSYNC, "TOGGLE_VSYNC"},
|
||||
{InputAction::EXIT, "EXIT"},
|
||||
{InputAction::NONE, "NONE"}};
|
||||
|
||||
const std::unordered_map<std::string, InputAction> STRING_TO_ACTION = {
|
||||
{"LEFT", InputAction::LEFT},
|
||||
{"RIGHT", InputAction::RIGHT},
|
||||
{"THRUST", InputAction::THRUST},
|
||||
{"SHOOT", InputAction::SHOOT},
|
||||
{"WINDOW_INC_ZOOM", InputAction::WINDOW_INC_ZOOM},
|
||||
{"WINDOW_DEC_ZOOM", InputAction::WINDOW_DEC_ZOOM},
|
||||
{"TOGGLE_FULLSCREEN", InputAction::TOGGLE_FULLSCREEN},
|
||||
{"TOGGLE_VSYNC", InputAction::TOGGLE_VSYNC},
|
||||
{"EXIT", InputAction::EXIT},
|
||||
{"NONE", InputAction::NONE}};
|
||||
{"LEFT", InputAction::LEFT},
|
||||
{"RIGHT", InputAction::RIGHT},
|
||||
{"THRUST", InputAction::THRUST},
|
||||
{"SHOOT", InputAction::SHOOT},
|
||||
{"WINDOW_INC_ZOOM", InputAction::WINDOW_INC_ZOOM},
|
||||
{"WINDOW_DEC_ZOOM", InputAction::WINDOW_DEC_ZOOM},
|
||||
{"TOGGLE_FULLSCREEN", InputAction::TOGGLE_FULLSCREEN},
|
||||
{"TOGGLE_VSYNC", InputAction::TOGGLE_VSYNC},
|
||||
{"EXIT", InputAction::EXIT},
|
||||
{"NONE", InputAction::NONE}};
|
||||
|
||||
const std::unordered_map<SDL_GamepadButton, std::string> BUTTON_TO_STRING = {
|
||||
{SDL_GAMEPAD_BUTTON_WEST, "WEST"},
|
||||
{SDL_GAMEPAD_BUTTON_NORTH, "NORTH"},
|
||||
{SDL_GAMEPAD_BUTTON_EAST, "EAST"},
|
||||
{SDL_GAMEPAD_BUTTON_SOUTH, "SOUTH"},
|
||||
{SDL_GAMEPAD_BUTTON_START, "START"},
|
||||
{SDL_GAMEPAD_BUTTON_BACK, "BACK"},
|
||||
{SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, "LEFT_SHOULDER"},
|
||||
{SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, "RIGHT_SHOULDER"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_UP, "DPAD_UP"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_DOWN, "DPAD_DOWN"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_LEFT, "DPAD_LEFT"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_RIGHT, "DPAD_RIGHT"},
|
||||
{static_cast<SDL_GamepadButton>(100), "L2_AS_BUTTON"},
|
||||
{static_cast<SDL_GamepadButton>(101), "R2_AS_BUTTON"}};
|
||||
{SDL_GAMEPAD_BUTTON_WEST, "WEST"},
|
||||
{SDL_GAMEPAD_BUTTON_NORTH, "NORTH"},
|
||||
{SDL_GAMEPAD_BUTTON_EAST, "EAST"},
|
||||
{SDL_GAMEPAD_BUTTON_SOUTH, "SOUTH"},
|
||||
{SDL_GAMEPAD_BUTTON_START, "START"},
|
||||
{SDL_GAMEPAD_BUTTON_BACK, "BACK"},
|
||||
{SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, "LEFT_SHOULDER"},
|
||||
{SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, "RIGHT_SHOULDER"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_UP, "DPAD_UP"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_DOWN, "DPAD_DOWN"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_LEFT, "DPAD_LEFT"},
|
||||
{SDL_GAMEPAD_BUTTON_DPAD_RIGHT, "DPAD_RIGHT"},
|
||||
{static_cast<SDL_GamepadButton>(100), "L2_AS_BUTTON"},
|
||||
{static_cast<SDL_GamepadButton>(101), "R2_AS_BUTTON"}};
|
||||
|
||||
const std::unordered_map<std::string, SDL_GamepadButton> STRING_TO_BUTTON = {
|
||||
{"WEST", SDL_GAMEPAD_BUTTON_WEST},
|
||||
{"NORTH", SDL_GAMEPAD_BUTTON_NORTH},
|
||||
{"EAST", SDL_GAMEPAD_BUTTON_EAST},
|
||||
{"SOUTH", SDL_GAMEPAD_BUTTON_SOUTH},
|
||||
{"START", SDL_GAMEPAD_BUTTON_START},
|
||||
{"BACK", SDL_GAMEPAD_BUTTON_BACK},
|
||||
{"LEFT_SHOULDER", SDL_GAMEPAD_BUTTON_LEFT_SHOULDER},
|
||||
{"RIGHT_SHOULDER", SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER},
|
||||
{"DPAD_UP", SDL_GAMEPAD_BUTTON_DPAD_UP},
|
||||
{"DPAD_DOWN", SDL_GAMEPAD_BUTTON_DPAD_DOWN},
|
||||
{"DPAD_LEFT", SDL_GAMEPAD_BUTTON_DPAD_LEFT},
|
||||
{"DPAD_RIGHT", SDL_GAMEPAD_BUTTON_DPAD_RIGHT},
|
||||
{"L2_AS_BUTTON", static_cast<SDL_GamepadButton>(100)},
|
||||
{"R2_AS_BUTTON", static_cast<SDL_GamepadButton>(101)}};
|
||||
{"WEST", SDL_GAMEPAD_BUTTON_WEST},
|
||||
{"NORTH", SDL_GAMEPAD_BUTTON_NORTH},
|
||||
{"EAST", SDL_GAMEPAD_BUTTON_EAST},
|
||||
{"SOUTH", SDL_GAMEPAD_BUTTON_SOUTH},
|
||||
{"START", SDL_GAMEPAD_BUTTON_START},
|
||||
{"BACK", SDL_GAMEPAD_BUTTON_BACK},
|
||||
{"LEFT_SHOULDER", SDL_GAMEPAD_BUTTON_LEFT_SHOULDER},
|
||||
{"RIGHT_SHOULDER", SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER},
|
||||
{"DPAD_UP", SDL_GAMEPAD_BUTTON_DPAD_UP},
|
||||
{"DPAD_DOWN", SDL_GAMEPAD_BUTTON_DPAD_DOWN},
|
||||
{"DPAD_LEFT", SDL_GAMEPAD_BUTTON_DPAD_LEFT},
|
||||
{"DPAD_RIGHT", SDL_GAMEPAD_BUTTON_DPAD_RIGHT},
|
||||
{"L2_AS_BUTTON", static_cast<SDL_GamepadButton>(100)},
|
||||
{"R2_AS_BUTTON", static_cast<SDL_GamepadButton>(101)}};
|
||||
|
||||
@@ -8,23 +8,23 @@
|
||||
|
||||
// --- Enums ---
|
||||
enum class InputAction : int { // Acciones de entrada posibles en el juego
|
||||
// Inputs de juego (movimiento y acción)
|
||||
LEFT, // Rotar izquierda
|
||||
RIGHT, // Rotar derecha
|
||||
THRUST, // Acelerar
|
||||
SHOOT, // Disparar
|
||||
START, // Empezar partida
|
||||
// Inputs de juego (movimiento y acción)
|
||||
LEFT, // Rotar izquierda
|
||||
RIGHT, // Rotar derecha
|
||||
THRUST, // Acelerar
|
||||
SHOOT, // Disparar
|
||||
START, // Empezar partida
|
||||
|
||||
// Inputs de sistema (globales)
|
||||
WINDOW_INC_ZOOM, // F2
|
||||
WINDOW_DEC_ZOOM, // F1
|
||||
TOGGLE_FULLSCREEN, // F3
|
||||
TOGGLE_VSYNC, // F4
|
||||
EXIT, // ESC
|
||||
// Inputs de sistema (globales)
|
||||
WINDOW_INC_ZOOM, // F2
|
||||
WINDOW_DEC_ZOOM, // F1
|
||||
TOGGLE_FULLSCREEN, // F3
|
||||
TOGGLE_VSYNC, // F4
|
||||
EXIT, // ESC
|
||||
|
||||
// Input obligatorio
|
||||
NONE,
|
||||
SIZE,
|
||||
// Input obligatorio
|
||||
NONE,
|
||||
SIZE,
|
||||
};
|
||||
|
||||
// --- Variables ---
|
||||
@@ -36,7 +36,6 @@ extern const std::unordered_map<std::string, SDL_GamepadButton> STRING_TO_BUTTON
|
||||
// --- Constantes ---
|
||||
// Physical arcade buttons (excludes directional controls LEFT/RIGHT)
|
||||
static constexpr std::array<InputAction, 3> ARCADE_BUTTONS = {
|
||||
InputAction::SHOOT,
|
||||
InputAction::THRUST,
|
||||
InputAction::START
|
||||
};
|
||||
InputAction::SHOOT,
|
||||
InputAction::THRUST,
|
||||
InputAction::START};
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
class SDLManager {
|
||||
public:
|
||||
SDLManager(); // Constructor per defecte (usa Defaults::)
|
||||
SDLManager(int width, int height, bool fullscreen); // Constructor amb configuració
|
||||
SDLManager(); // Constructor per defecte (usa Defaults::)
|
||||
SDLManager(int width, int height, bool fullscreen); // Constructor amb configuració
|
||||
~SDLManager();
|
||||
|
||||
// No permetre còpia ni assignació
|
||||
@@ -22,11 +22,11 @@ class SDLManager {
|
||||
SDLManager& operator=(const SDLManager&) = delete;
|
||||
|
||||
// [NUEVO] Gestió de finestra dinàmica
|
||||
void increaseWindowSize(); // F2: +100px
|
||||
void decreaseWindowSize(); // F1: -100px
|
||||
void toggleFullscreen(); // F3
|
||||
void toggleVSync(); // F4
|
||||
bool handleWindowEvent(const SDL_Event& event); // Per a SDL_EVENT_WINDOW_RESIZED
|
||||
void increaseWindowSize(); // F2: +100px
|
||||
void decreaseWindowSize(); // F1: -100px
|
||||
void toggleFullscreen(); // F3
|
||||
void toggleVSync(); // F4
|
||||
bool handleWindowEvent(const SDL_Event& event); // Per a SDL_EVENT_WINDOW_RESIZED
|
||||
|
||||
// Funcions principals (renderitzat)
|
||||
void neteja(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0);
|
||||
|
||||
@@ -14,16 +14,22 @@ namespace Rendering {
|
||||
|
||||
// Estructura per rotacions 3D (pitch, yaw, roll)
|
||||
struct Rotation3D {
|
||||
float pitch; // Rotació eix X (cabeceo arriba/baix)
|
||||
float yaw; // Rotació eix Y (guiñada esquerra/dreta)
|
||||
float roll; // Rotació eix Z (alabeo lateral)
|
||||
float pitch; // Rotació eix X (cabeceo arriba/baix)
|
||||
float yaw; // Rotació eix Y (guiñada esquerra/dreta)
|
||||
float roll; // Rotació eix Z (alabeo lateral)
|
||||
|
||||
Rotation3D() : pitch(0.0f), yaw(0.0f), roll(0.0f) {}
|
||||
Rotation3D(float p, float y, float r) : pitch(p), yaw(y), roll(r) {}
|
||||
Rotation3D()
|
||||
: pitch(0.0f),
|
||||
yaw(0.0f),
|
||||
roll(0.0f) {}
|
||||
Rotation3D(float p, float y, float r)
|
||||
: pitch(p),
|
||||
yaw(y),
|
||||
roll(r) {}
|
||||
|
||||
bool has_rotation() const {
|
||||
return pitch != 0.0f || yaw != 0.0f || roll != 0.0f;
|
||||
}
|
||||
bool has_rotation() const {
|
||||
return pitch != 0.0f || yaw != 0.0f || roll != 0.0f;
|
||||
}
|
||||
};
|
||||
|
||||
// Renderitzar forma amb transformacions
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#include "resource_helper.hpp"
|
||||
|
||||
#include "resource_loader.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "resource_loader.hpp"
|
||||
|
||||
namespace Resource {
|
||||
namespace Helper {
|
||||
|
||||
|
||||
@@ -4,50 +4,50 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "resource_pack.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "resource_pack.hpp"
|
||||
|
||||
namespace Resource {
|
||||
|
||||
// Singleton per gestionar la càrrega de recursos
|
||||
class Loader {
|
||||
public:
|
||||
// Singleton
|
||||
static Loader& get();
|
||||
public:
|
||||
// Singleton
|
||||
static Loader& get();
|
||||
|
||||
// Inicialització
|
||||
bool initialize(const std::string& pack_file, bool enable_fallback);
|
||||
// Inicialització
|
||||
bool initialize(const std::string& pack_file, bool enable_fallback);
|
||||
|
||||
// Càrrega de recursos
|
||||
std::vector<uint8_t> loadResource(const std::string& filename);
|
||||
bool resourceExists(const std::string& filename);
|
||||
// Càrrega de recursos
|
||||
std::vector<uint8_t> loadResource(const std::string& filename);
|
||||
bool resourceExists(const std::string& filename);
|
||||
|
||||
// Validació
|
||||
bool validatePack();
|
||||
bool isPackLoaded() const;
|
||||
// Validació
|
||||
bool validatePack();
|
||||
bool isPackLoaded() const;
|
||||
|
||||
// Estat
|
||||
void setBasePath(const std::string& path);
|
||||
std::string getBasePath() const;
|
||||
// Estat
|
||||
void setBasePath(const std::string& path);
|
||||
std::string getBasePath() const;
|
||||
|
||||
private:
|
||||
Loader() = default;
|
||||
~Loader() = default;
|
||||
private:
|
||||
Loader() = default;
|
||||
~Loader() = default;
|
||||
|
||||
// No es pot copiar ni moure
|
||||
Loader(const Loader&) = delete;
|
||||
Loader& operator=(const Loader&) = delete;
|
||||
// No es pot copiar ni moure
|
||||
Loader(const Loader&) = delete;
|
||||
Loader& operator=(const Loader&) = delete;
|
||||
|
||||
// Dades
|
||||
std::unique_ptr<Pack> pack_;
|
||||
bool fallback_enabled_ = false;
|
||||
std::string base_path_;
|
||||
// Dades
|
||||
std::unique_ptr<Pack> pack_;
|
||||
bool fallback_enabled_ = false;
|
||||
std::string base_path_;
|
||||
|
||||
// Funcions auxiliars
|
||||
std::vector<uint8_t> loadFromFilesystem(const std::string& filename);
|
||||
// Funcions auxiliars
|
||||
std::vector<uint8_t> loadFromFilesystem(const std::string& filename);
|
||||
};
|
||||
|
||||
} // namespace Resource
|
||||
|
||||
@@ -13,55 +13,55 @@ namespace Resource {
|
||||
|
||||
// Capçalera del fitxer de paquet
|
||||
struct PackHeader {
|
||||
char magic[4]; // "ORNI"
|
||||
uint32_t version; // Versió del format (1)
|
||||
char magic[4]; // "ORNI"
|
||||
uint32_t version; // Versió del format (1)
|
||||
};
|
||||
|
||||
// Entrada de recurs dins el paquet
|
||||
struct ResourceEntry {
|
||||
std::string filename; // Nom del recurs (amb barres normals)
|
||||
uint64_t offset; // Posició dins el bloc de dades
|
||||
uint64_t size; // Mida en bytes
|
||||
uint32_t checksum; // Checksum CRC32 per verificació
|
||||
std::string filename; // Nom del recurs (amb barres normals)
|
||||
uint64_t offset; // Posició dins el bloc de dades
|
||||
uint64_t size; // Mida en bytes
|
||||
uint32_t checksum; // Checksum CRC32 per verificació
|
||||
};
|
||||
|
||||
// Classe principal per gestionar paquets de recursos
|
||||
class Pack {
|
||||
public:
|
||||
Pack() = default;
|
||||
~Pack() = default;
|
||||
public:
|
||||
Pack() = default;
|
||||
~Pack() = default;
|
||||
|
||||
// Afegir fitxers al paquet
|
||||
bool addFile(const std::string& filepath, const std::string& pack_name);
|
||||
bool addDirectory(const std::string& dir_path, const std::string& base_path = "");
|
||||
// Afegir fitxers al paquet
|
||||
bool addFile(const std::string& filepath, const std::string& pack_name);
|
||||
bool addDirectory(const std::string& dir_path, const std::string& base_path = "");
|
||||
|
||||
// Guardar i carregar paquets
|
||||
bool savePack(const std::string& pack_file);
|
||||
bool loadPack(const std::string& pack_file);
|
||||
// Guardar i carregar paquets
|
||||
bool savePack(const std::string& pack_file);
|
||||
bool loadPack(const std::string& pack_file);
|
||||
|
||||
// Accés a recursos
|
||||
std::vector<uint8_t> getResource(const std::string& filename);
|
||||
bool hasResource(const std::string& filename) const;
|
||||
std::vector<std::string> getResourceList() const;
|
||||
// Accés a recursos
|
||||
std::vector<uint8_t> getResource(const std::string& filename);
|
||||
bool hasResource(const std::string& filename) const;
|
||||
std::vector<std::string> getResourceList() const;
|
||||
|
||||
// Validació
|
||||
bool validatePack() const;
|
||||
// Validació
|
||||
bool validatePack() const;
|
||||
|
||||
private:
|
||||
// Constants
|
||||
static constexpr const char* MAGIC_HEADER = "ORNI";
|
||||
static constexpr uint32_t VERSION = 1;
|
||||
static constexpr const char* DEFAULT_ENCRYPT_KEY = "ORNI_RESOURCES_2025";
|
||||
private:
|
||||
// Constants
|
||||
static constexpr const char* MAGIC_HEADER = "ORNI";
|
||||
static constexpr uint32_t VERSION = 1;
|
||||
static constexpr const char* DEFAULT_ENCRYPT_KEY = "ORNI_RESOURCES_2025";
|
||||
|
||||
// Dades del paquet
|
||||
std::unordered_map<std::string, ResourceEntry> resources_;
|
||||
std::vector<uint8_t> data_;
|
||||
// Dades del paquet
|
||||
std::unordered_map<std::string, ResourceEntry> resources_;
|
||||
std::vector<uint8_t> data_;
|
||||
|
||||
// Funcions auxiliars
|
||||
std::vector<uint8_t> readFile(const std::string& filepath);
|
||||
uint32_t calculateChecksum(const std::vector<uint8_t>& data) const;
|
||||
void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
// Funcions auxiliars
|
||||
std::vector<uint8_t> readFile(const std::string& filepath);
|
||||
uint32_t calculateChecksum(const std::vector<uint8_t>& data) const;
|
||||
void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
};
|
||||
|
||||
} // namespace Resource
|
||||
|
||||
@@ -10,70 +10,70 @@ namespace GestorEscenes {
|
||||
// Context de transició entre escenes
|
||||
// Conté l'escena destinació i opcions específiques per aquella escena
|
||||
class ContextEscenes {
|
||||
public:
|
||||
// Tipus d'escena del joc
|
||||
enum class Escena {
|
||||
LOGO, // Pantalla d'inici (logo JAILGAMES)
|
||||
TITOL, // Pantalla de títol amb menú
|
||||
JOC, // Joc principal (Asteroids)
|
||||
EIXIR // Sortir del programa
|
||||
};
|
||||
public:
|
||||
// Tipus d'escena del joc
|
||||
enum class Escena {
|
||||
LOGO, // Pantalla d'inici (logo JAILGAMES)
|
||||
TITOL, // Pantalla de títol amb menú
|
||||
JOC, // Joc principal (Asteroids)
|
||||
EIXIR // Sortir del programa
|
||||
};
|
||||
|
||||
// Opcions específiques per a cada escena
|
||||
enum class Opcio {
|
||||
NONE, // Sense opcions especials (comportament per defecte)
|
||||
JUMP_TO_TITLE_MAIN, // TITOL: Saltar directament a MAIN (starfield instantani)
|
||||
// MODE_DEMO, // JOC: Mode demostració amb IA (futur)
|
||||
};
|
||||
// Opcions específiques per a cada escena
|
||||
enum class Opcio {
|
||||
NONE, // Sense opcions especials (comportament per defecte)
|
||||
JUMP_TO_TITLE_MAIN, // TITOL: Saltar directament a MAIN (starfield instantani)
|
||||
// MODE_DEMO, // JOC: Mode demostració amb IA (futur)
|
||||
};
|
||||
|
||||
// Constructor inicial amb escena LOGO i sense opcions
|
||||
ContextEscenes()
|
||||
: escena_desti_(Escena::LOGO),
|
||||
opcio_(Opcio::NONE) {}
|
||||
// Constructor inicial amb escena LOGO i sense opcions
|
||||
ContextEscenes()
|
||||
: escena_desti_(Escena::LOGO),
|
||||
opcio_(Opcio::NONE) {}
|
||||
|
||||
// Canviar escena amb opció específica
|
||||
void canviar_escena(Escena nova_escena, Opcio opcio = Opcio::NONE) {
|
||||
escena_desti_ = nova_escena;
|
||||
opcio_ = opcio;
|
||||
}
|
||||
// Canviar escena amb opció específica
|
||||
void canviar_escena(Escena nova_escena, Opcio opcio = Opcio::NONE) {
|
||||
escena_desti_ = nova_escena;
|
||||
opcio_ = opcio;
|
||||
}
|
||||
|
||||
// Consultar escena destinació
|
||||
[[nodiscard]] auto escena_desti() const -> Escena {
|
||||
return escena_desti_;
|
||||
}
|
||||
// Consultar escena destinació
|
||||
[[nodiscard]] auto escena_desti() const -> Escena {
|
||||
return escena_desti_;
|
||||
}
|
||||
|
||||
// Consultar opció actual
|
||||
[[nodiscard]] auto opcio() const -> Opcio {
|
||||
return opcio_;
|
||||
}
|
||||
// Consultar opció actual
|
||||
[[nodiscard]] auto opcio() const -> Opcio {
|
||||
return opcio_;
|
||||
}
|
||||
|
||||
// Consumir opció (retorna valor i reseteja a NONE)
|
||||
// Utilitzar quan l'escena processa l'opció
|
||||
[[nodiscard]] auto consumir_opcio() -> Opcio {
|
||||
Opcio valor = opcio_;
|
||||
opcio_ = Opcio::NONE;
|
||||
return valor;
|
||||
}
|
||||
// Consumir opció (retorna valor i reseteja a NONE)
|
||||
// Utilitzar quan l'escena processa l'opció
|
||||
[[nodiscard]] auto consumir_opcio() -> Opcio {
|
||||
Opcio valor = opcio_;
|
||||
opcio_ = Opcio::NONE;
|
||||
return valor;
|
||||
}
|
||||
|
||||
// Reset opció a NONE (sense retornar valor)
|
||||
void reset_opcio() {
|
||||
opcio_ = Opcio::NONE;
|
||||
}
|
||||
// Reset opció a NONE (sense retornar valor)
|
||||
void reset_opcio() {
|
||||
opcio_ = Opcio::NONE;
|
||||
}
|
||||
|
||||
// Configurar partida abans de transicionar a JOC
|
||||
void set_config_partida(const GameConfig::ConfigPartida& config) {
|
||||
config_partida_ = config;
|
||||
}
|
||||
// Configurar partida abans de transicionar a JOC
|
||||
void set_config_partida(const GameConfig::ConfigPartida& config) {
|
||||
config_partida_ = config;
|
||||
}
|
||||
|
||||
// Obtenir configuració de partida (consumit per EscenaJoc)
|
||||
[[nodiscard]] const GameConfig::ConfigPartida& get_config_partida() const {
|
||||
return config_partida_;
|
||||
}
|
||||
// Obtenir configuració de partida (consumit per EscenaJoc)
|
||||
[[nodiscard]] const GameConfig::ConfigPartida& get_config_partida() const {
|
||||
return config_partida_;
|
||||
}
|
||||
|
||||
private:
|
||||
Escena escena_desti_; // Escena a la qual transicionar
|
||||
Opcio opcio_; // Opció específica per l'escena
|
||||
GameConfig::ConfigPartida config_partida_; // Configuració de partida (jugadors actius, mode)
|
||||
private:
|
||||
Escena escena_desti_; // Escena a la qual transicionar
|
||||
Opcio opcio_; // Opció específica per l'escena
|
||||
GameConfig::ConfigPartida config_partida_; // Configuració de partida (jugadors actius, mode)
|
||||
};
|
||||
|
||||
// Variable global inline per gestionar l'escena actual (backward compatibility)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include "context_escenes.hpp"
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/audio/audio_cache.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
@@ -20,7 +21,6 @@
|
||||
#include "game/escenes/escena_logo.hpp"
|
||||
#include "game/escenes/escena_titol.hpp"
|
||||
#include "game/options.hpp"
|
||||
#include "context_escenes.hpp"
|
||||
#include "project.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
@@ -240,7 +240,7 @@ auto Director::run() -> int {
|
||||
// Crear context d'escenes
|
||||
ContextEscenes context;
|
||||
#ifdef _DEBUG
|
||||
context.canviar_escena(Escena::JOC);
|
||||
context.canviar_escena(Escena::TITOL);
|
||||
#else
|
||||
context.canviar_escena(Escena::LOGO);
|
||||
#endif
|
||||
|
||||
@@ -12,40 +12,40 @@ enum class Mode {
|
||||
|
||||
// Configuració d'una partida
|
||||
struct ConfigPartida {
|
||||
bool jugador1_actiu{false}; // És actiu el jugador 1?
|
||||
bool jugador2_actiu{false}; // És actiu el jugador 2?
|
||||
Mode mode{Mode::NORMAL}; // Mode de joc
|
||||
bool jugador1_actiu{false}; // És actiu el jugador 1?
|
||||
bool jugador2_actiu{false}; // És actiu el jugador 2?
|
||||
Mode mode{Mode::NORMAL}; // Mode de joc
|
||||
|
||||
// Mètodes auxiliars
|
||||
// Mètodes auxiliars
|
||||
|
||||
// Retorna true si només hi ha un jugador actiu
|
||||
[[nodiscard]] bool es_un_jugador() const {
|
||||
return (jugador1_actiu && !jugador2_actiu) ||
|
||||
(!jugador1_actiu && jugador2_actiu);
|
||||
}
|
||||
// Retorna true si només hi ha un jugador actiu
|
||||
[[nodiscard]] bool es_un_jugador() const {
|
||||
return (jugador1_actiu && !jugador2_actiu) ||
|
||||
(!jugador1_actiu && jugador2_actiu);
|
||||
}
|
||||
|
||||
// Retorna true si hi ha dos jugadors actius
|
||||
[[nodiscard]] bool son_dos_jugadors() const {
|
||||
return jugador1_actiu && jugador2_actiu;
|
||||
}
|
||||
// Retorna true si hi ha dos jugadors actius
|
||||
[[nodiscard]] bool son_dos_jugadors() const {
|
||||
return jugador1_actiu && jugador2_actiu;
|
||||
}
|
||||
|
||||
// Retorna true si no hi ha cap jugador actiu
|
||||
[[nodiscard]] bool cap_jugador() const {
|
||||
return !jugador1_actiu && !jugador2_actiu;
|
||||
}
|
||||
// Retorna true si no hi ha cap jugador actiu
|
||||
[[nodiscard]] bool cap_jugador() const {
|
||||
return !jugador1_actiu && !jugador2_actiu;
|
||||
}
|
||||
|
||||
// Compte de jugadors actius (0, 1 o 2)
|
||||
[[nodiscard]] uint8_t compte_jugadors() const {
|
||||
return (jugador1_actiu ? 1 : 0) + (jugador2_actiu ? 1 : 0);
|
||||
}
|
||||
// Compte de jugadors actius (0, 1 o 2)
|
||||
[[nodiscard]] uint8_t compte_jugadors() const {
|
||||
return (jugador1_actiu ? 1 : 0) + (jugador2_actiu ? 1 : 0);
|
||||
}
|
||||
|
||||
// Retorna l'ID de l'únic jugador actiu (0 o 1)
|
||||
// Només vàlid si es_un_jugador() retorna true
|
||||
[[nodiscard]] uint8_t id_unic_jugador() const {
|
||||
if (jugador1_actiu && !jugador2_actiu) return 0;
|
||||
if (!jugador1_actiu && jugador2_actiu) return 1;
|
||||
return 0; // Fallback (cal comprovar es_un_jugador() primer)
|
||||
}
|
||||
// Retorna l'ID de l'únic jugador actiu (0 o 1)
|
||||
// Només vàlid si es_un_jugador() retorna true
|
||||
[[nodiscard]] uint8_t id_unic_jugador() const {
|
||||
if (jugador1_actiu && !jugador2_actiu) return 0;
|
||||
if (!jugador1_actiu && jugador2_actiu) return 1;
|
||||
return 0; // Fallback (cal comprovar es_un_jugador() primer)
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace GameConfig
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "context_escenes.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/input/mouse.hpp"
|
||||
#include "core/rendering/sdl_manager.hpp"
|
||||
#include "context_escenes.hpp"
|
||||
|
||||
// Using declarations per simplificar el codi
|
||||
using GestorEscenes::ContextEscenes;
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
// Forward declarations
|
||||
class SDLManager;
|
||||
namespace GestorEscenes { class ContextEscenes; }
|
||||
namespace GestorEscenes {
|
||||
class ContextEscenes;
|
||||
}
|
||||
|
||||
namespace GlobalEvents {
|
||||
// Processa events globals (F1/F2/F3/ESC/QUIT)
|
||||
|
||||
Reference in New Issue
Block a user