organitzat player.h
This commit is contained in:
180
source/player.h
180
source/player.h
@@ -125,9 +125,7 @@ class Player {
|
||||
// --- Texturas y animaciones ---
|
||||
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>>& texture); // Cambia las texturas del jugador
|
||||
|
||||
// --- Estados y contadores ---
|
||||
|
||||
// --- Puntuación y marcador ---
|
||||
// --- Gameplay: Puntuación y power-ups ---
|
||||
void addScore(int score, int lowest_hi_score_entry); // Añade puntos
|
||||
void incScoreMultiplier(); // Incrementa el multiplicador
|
||||
void decScoreMultiplier(); // Decrementa el multiplicador
|
||||
@@ -140,11 +138,13 @@ class Player {
|
||||
void giveExtraHit(); // Concede un toque extra al jugador
|
||||
void removeExtraHit(); // Quita el toque extra al jugador
|
||||
void decContinueCounter(); // Decrementa el contador de continuar
|
||||
void setWalkingState(State state) { walking_state_ = state; } // Establece el estado de caminar
|
||||
void startFiringSystem(int cooldown_frames); // Inicia el sistema de disparo
|
||||
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; } // Establece el panel del marcador
|
||||
void addCredit();
|
||||
void passShowingName();
|
||||
|
||||
// --- Getters y comprobaciones de estado ---
|
||||
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
|
||||
// Comprobación de playing_state
|
||||
// --- Estado del juego: Consultas (is* methods) ---
|
||||
[[nodiscard]] auto isLyingOnTheFloorForever() const -> bool { return playing_state_ == State::LYING_ON_THE_FLOOR_FOREVER; }
|
||||
[[nodiscard]] auto isCelebrating() const -> bool { return playing_state_ == State::CELEBRATING; }
|
||||
[[nodiscard]] auto isContinue() const -> bool { return playing_state_ == State::CONTINUE; }
|
||||
@@ -158,7 +158,7 @@ class Player {
|
||||
[[nodiscard]] auto isWaiting() const -> bool { return playing_state_ == State::WAITING; }
|
||||
[[nodiscard]] auto isTitleHidden() const -> bool { return playing_state_ == State::TITLE_HIDDEN; }
|
||||
|
||||
// Getters
|
||||
// --- Estados específicos: Consultas adicionales ---
|
||||
[[nodiscard]] auto canFire() const -> bool { return can_fire_new_system_; } // Usa nuevo sistema
|
||||
[[nodiscard]] auto hasExtraHit() const -> bool { return extra_hit_; }
|
||||
[[nodiscard]] auto isCooling() const -> bool { return firing_state_ == State::COOLING_LEFT || firing_state_ == State::COOLING_UP || firing_state_ == State::COOLING_RIGHT; }
|
||||
@@ -166,48 +166,47 @@ class Player {
|
||||
[[nodiscard]] auto qualifiesForHighScore() const -> bool { return qualifies_for_high_score_; }
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
|
||||
[[nodiscard]] auto isPowerUp() const -> bool { return power_up_; }
|
||||
auto getCollider() -> Circle& { return collider_; }
|
||||
[[nodiscard]] auto getScoreMultiplier() const -> float { return score_multiplier_; }
|
||||
[[nodiscard]] auto getCoffees() const -> int { return coffees_; }
|
||||
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
|
||||
[[nodiscard]] auto getController() const -> int { return controller_index_; }
|
||||
[[nodiscard]] static auto getHeight() -> int { return HEIGHT; }
|
||||
[[nodiscard]] auto getId() const -> Player::Id { return id_; }
|
||||
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
|
||||
[[nodiscard]] auto isInBulletColorToggleMode() const -> bool { return in_power_up_ending_phase_; }
|
||||
|
||||
// --- Getters: Propiedades y valores ---
|
||||
// Posición y dimensiones
|
||||
[[nodiscard]] auto getPosX() const -> int { return static_cast<int>(pos_x_); }
|
||||
[[nodiscard]] auto getPosY() const -> int { return pos_y_; }
|
||||
[[nodiscard]] auto getPowerUpCounter() const -> int { return power_up_counter_; }
|
||||
[[nodiscard]] auto getRecordName() const -> std::string { return enter_name_ ? enter_name_->getFinalName() : "xxx"; }
|
||||
[[nodiscard]] auto getLastEnterName() const -> std::string { return last_enter_name_; }
|
||||
[[nodiscard]] auto getScore() const -> int { return score_; }
|
||||
[[nodiscard]] auto getScoreBoardPanel() const -> Scoreboard::Id { return scoreboard_panel_; }
|
||||
[[nodiscard]] static auto getWidth() -> int { return WIDTH; }
|
||||
[[nodiscard]] auto getPlayingState() const -> State { return playing_state_; }
|
||||
[[nodiscard]] static auto getHeight() -> int { return HEIGHT; }
|
||||
// Jugador y identificación
|
||||
[[nodiscard]] auto getId() const -> Player::Id { return id_; }
|
||||
[[nodiscard]] auto getName() const -> const std::string& { return name_; }
|
||||
[[nodiscard]] auto getPlayingState() const -> State { return playing_state_; }
|
||||
auto getCollider() -> Circle& { return collider_; }
|
||||
|
||||
// Puntuación y juego
|
||||
[[nodiscard]] auto getScore() const -> int { return score_; }
|
||||
[[nodiscard]] auto getScoreMultiplier() const -> float { return score_multiplier_; }
|
||||
[[nodiscard]] auto get1CC() const -> bool { return game_completed_ && credits_used_ <= 1; }
|
||||
[[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; }
|
||||
[[nodiscard]] auto getScoreBoardPanel() const -> Scoreboard::Id { return scoreboard_panel_; }
|
||||
|
||||
// Power-ups y estado especial
|
||||
[[nodiscard]] auto getCoffees() const -> int { return coffees_; }
|
||||
[[nodiscard]] auto getPowerUpCounter() const -> int { return power_up_counter_; }
|
||||
[[nodiscard]] auto getInvulnerableCounter() const -> int { return invulnerable_counter_; }
|
||||
[[nodiscard]] auto getBulletColor() const -> Bullet::Color { return bullet_color_; }
|
||||
[[nodiscard]] auto isInBulletColorToggleMode() const -> bool { return in_power_up_ending_phase_; }
|
||||
auto getNextBulletColor() -> Bullet::Color; // Devuelve el color para la próxima bala (alterna si está en modo toggle)
|
||||
|
||||
// Setters inline
|
||||
void setController(int index) { controller_index_ = index; }
|
||||
void startFiringSystem(int cooldown_frames); // Método público para iniciar disparo
|
||||
void setFiringState(State state) { firing_state_ = state; }
|
||||
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
||||
void setName(const std::string& name) { name_ = name; }
|
||||
void setPowerUpCounter(int value) { power_up_counter_ = value; }
|
||||
void setScore(int score) { score_ = score; }
|
||||
void setScoreBoardPanel(Scoreboard::Id panel) { scoreboard_panel_ = panel; }
|
||||
void setScoreMultiplier(float value) { score_multiplier_ = value; }
|
||||
void setWalkingState(State state) { walking_state_ = state; }
|
||||
// Contadores y timers
|
||||
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
|
||||
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
[[nodiscard]] auto getRecordName() const -> std::string { return enter_name_ ? enter_name_->getFinalName() : "xxx"; }
|
||||
[[nodiscard]] auto getLastEnterName() const -> std::string { return last_enter_name_; }
|
||||
[[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; }
|
||||
|
||||
void addCredit();
|
||||
void passShowingName();
|
||||
// --- Configuración e interfaz externa ---
|
||||
void setName(const std::string& name) { name_ = name; }
|
||||
void setGamepad(std::shared_ptr<Input::Gamepad> gamepad) { gamepad_ = std::move(gamepad); }
|
||||
[[nodiscard]] auto getGamepad() const -> std::shared_ptr<Input::Gamepad> { return gamepad_; }
|
||||
void setUsesKeyboard(bool value) { uses_keyboard_ = value; }
|
||||
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
|
||||
[[nodiscard]] auto getController() const -> int { return controller_index_; }
|
||||
|
||||
private:
|
||||
// --- Constantes de física y movimiento ---
|
||||
@@ -314,60 +313,71 @@ class Player {
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Actualiza el círculo de colisión a la posición del jugador
|
||||
void shiftSprite(); // Recoloca el sprite
|
||||
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad (time-based)
|
||||
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue (time-based)
|
||||
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre (time-based)
|
||||
void updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME (time-based)
|
||||
|
||||
// --- Setters internos ---
|
||||
void setController(int index) { controller_index_ = index; }
|
||||
void setFiringState(State state) { firing_state_ = state; }
|
||||
void setInvulnerableCounter(int value) { invulnerable_counter_ = value; }
|
||||
void setPowerUpCounter(int value) { power_up_counter_ = value; }
|
||||
void setScore(int score) { score_ = score; }
|
||||
void setScoreMultiplier(float value) { score_multiplier_ = value; }
|
||||
|
||||
// --- Actualizadores de estado (time-based) ---
|
||||
void updateInvulnerable(float deltaTime); // Monitoriza el estado de invulnerabilidad
|
||||
void updateContinueCounter(float deltaTime); // Actualiza el contador de continue
|
||||
void updateEnterNameCounter(float deltaTime); // Actualiza el contador de entrar nombre
|
||||
void updateShowingName(float deltaTime); // Actualiza el estado SHOWING_NAME
|
||||
void decNameEntryCounter(); // Decrementa el contador de entrar nombre
|
||||
|
||||
// --- Utilidades generales ---
|
||||
void updateScoreboard(); // Actualiza el panel del marcador
|
||||
void setScoreboardMode(Scoreboard::Mode mode) const; // Cambia el modo del marcador
|
||||
void playSound(const std::string& name) const; // Hace sonar un sonido
|
||||
[[nodiscard]] auto isRenderable() const -> bool; // Indica si se puede dibujar el objeto
|
||||
void addScoreToScoreBoard() const; // Añade una puntuación a la tabla de records
|
||||
|
||||
// --- Métodos del sistema de disparo de dos líneas ---
|
||||
void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo
|
||||
void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire)
|
||||
void updateVisualLine(float deltaTime); // Actualiza la línea visual (Animaciones)
|
||||
void startFiring(int cooldown_frames); // Inicia un nuevo disparo en ambas líneas
|
||||
void updateFiringStateFromVisual(); // Sincroniza firing_state_ con visual_fire_state_
|
||||
void transitionToRecoilingNew(); // Transición AIMING → RECOILING
|
||||
void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE
|
||||
void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL
|
||||
// --- Sistema de disparo (nuevo - dos líneas) ---
|
||||
void updateFireSystem(float deltaTime); // Método principal del nuevo sistema de disparo
|
||||
void updateFunctionalLine(float deltaTime); // Actualiza la línea funcional (CanFire)
|
||||
void updateVisualLine(float deltaTime); // Actualiza la línea visual (Animaciones)
|
||||
void startFiring(int cooldown_frames); // Inicia un nuevo disparo en ambas líneas
|
||||
void updateFiringStateFromVisual(); // Sincroniza firing_state_ con visual_fire_state_
|
||||
void transitionToRecoilingNew(); // Transición AIMING → RECOILING
|
||||
void transitionToThreatPose(); // Transición RECOILING → THREAT_POSE
|
||||
void transitionToNormalNew(); // Transición THREAT_POSE → NORMAL
|
||||
|
||||
// --- Métodos del sistema de disparo obsoleto ---
|
||||
void handleFiringCooldown(); // Gestiona el tiempo de espera después de disparar (frame-based)
|
||||
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar (time-based)
|
||||
void handleRecoilAndCooling(); // Procesa retroceso y enfriamiento (frame-based)
|
||||
void handleRecoilAndCooling(float deltaTime); // Procesa retroceso y enfriamiento (time-based)
|
||||
void handleCoolingState(); // Actualiza estado de enfriamiento (frame-based)
|
||||
void handleCoolingState(float deltaTime); // Actualiza estado de enfriamiento (time-based)
|
||||
void transitionToRecoiling(); // Transición a retroceso (sistema obsoleto)
|
||||
void transitionToCooling(); // Transición a enfriamiento (sistema obsoleto)
|
||||
void completeCooling(); // Finaliza enfriamiento (sistema obsoleto)
|
||||
void handlePlayingMovement(); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (frame-based)
|
||||
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento del personaje u objeto durante el estado de juego activo (time-based)
|
||||
void handleRecoverMovement(); // Comprueba si ha acabado la animación
|
||||
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar" (posiblemente tras impacto o acción especial)
|
||||
void handleRollingBoundaryCollision(); // Detecta y maneja colisiones del objeto rodante con los límites de la pantalla
|
||||
void handleRollingGroundCollision(); // Gestiona la interacción del objeto rodante con el suelo (rebotes, frenado, etc.)
|
||||
void handleRollingStop(); // Detiene el movimiento del objeto rodante cuando se cumplen las condiciones necesarias
|
||||
void handleRollingBounce(); // Aplica una lógica de rebote al colisionar con superficies durante el rodamiento
|
||||
void handleTitleAnimation(float deltaTime); // Ejecuta la animación del título en pantalla (ej. entrada, parpadeo o desplazamiento)
|
||||
void handleContinueTimeOut(); // Gestiona el tiempo de espera en la pantalla de "Continuar" y decide si pasar a otro estado
|
||||
void handleLeavingScreen(float deltaTime); // Lógica para salir de la pantalla actual (transición visual o cambio de escena)
|
||||
void handleEnteringScreen(float deltaTime); // Lógica para entrar en una nueva pantalla, posiblemente con animación o retraso
|
||||
void handlePlayer1Entering(float deltaTime); // Controla la animación o posición de entrada del Jugador 1 en pantalla
|
||||
void handlePlayer2Entering(float deltaTime); // Controla la animación o posición de entrada del Jugador 2 en pantalla
|
||||
void handleCreditsMovement(); // Movimiento general en la pantalla de créditos (frame-based)
|
||||
void handleCreditsMovement(float deltaTime); // Movimiento general en la pantalla de créditos (time-based)
|
||||
void handleCreditsRightMovement(); // Lógica específica para mover los créditos hacia la derecha
|
||||
void handleCreditsLeftMovement(); // Lógica específica para mover los créditos hacia la izquierda
|
||||
void handleWaitingMovement(); // Controla la animación del jugador saludando (frame-based)
|
||||
void handleWaitingMovement(float deltaTime); // Controla la animación del jugador saludando (time-based)
|
||||
void updateWalkingStateForCredits(); // Actualiza el estado de caminata de algún personaje u elemento animado en los créditos
|
||||
void setInputBasedOnPlayerId(); // Asocia las entradas de control en función del identificador del jugador (teclas, mando, etc.)
|
||||
void updateStepCounter(); // Incrementa o ajusta el contador de pasos (frame-based)
|
||||
void updateStepCounter(float deltaTime); // Incrementa o ajusta el contador de pasos (time-based)
|
||||
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula la animacion de moverse y disparar del jugador
|
||||
// --- Sistema de disparo obsoleto (legacy) ---
|
||||
void handleFiringCooldown(float deltaTime); // Gestiona el tiempo de espera después de disparar
|
||||
void handleRecoilAndCooling(float deltaTime); // Procesa retroceso y enfriamiento
|
||||
void handleCoolingState(float deltaTime); // Actualiza estado de enfriamiento
|
||||
// --- Manejadores de movimiento ---
|
||||
void handlePlayingMovement(float deltaTime); // Gestiona el movimiento durante el juego
|
||||
void handleRecoverMovement(); // Comprueba si ha acabado la animación de recuperación
|
||||
void updateStepCounter(float deltaTime); // Incrementa o ajusta el contador de pasos
|
||||
void setInputBasedOnPlayerId(); // Asocia las entradas de control según el jugador
|
||||
|
||||
// --- Manejadores de estados especiales ---
|
||||
void handleRollingMovement(); // Actualiza la lógica de movimiento de "rodar"
|
||||
void handleRollingBoundaryCollision(); // Detecta colisiones con límites durante rodamiento
|
||||
void handleRollingGroundCollision(); // Gestiona interacción con el suelo durante rodamiento
|
||||
void handleRollingStop(); // Detiene el movimiento del objeto rodante
|
||||
void handleRollingBounce(); // Aplica lógica de rebote durante rodamiento
|
||||
void handleContinueTimeOut(); // Gestiona tiempo de espera en pantalla "Continuar"
|
||||
|
||||
// --- Manejadores de transiciones de pantalla ---
|
||||
void handleTitleAnimation(float deltaTime); // Ejecuta animación del título
|
||||
void handleLeavingScreen(float deltaTime); // Lógica para salir de pantalla
|
||||
void handleEnteringScreen(float deltaTime); // Lógica para entrar en pantalla
|
||||
void handlePlayer1Entering(float deltaTime); // Entrada del Jugador 1
|
||||
void handlePlayer2Entering(float deltaTime); // Entrada del Jugador 2
|
||||
|
||||
// --- Manejadores de pantallas especiales ---
|
||||
void handleCreditsMovement(float deltaTime); // Movimiento en pantalla de créditos
|
||||
void handleCreditsRightMovement(); // Movimiento hacia la derecha en créditos
|
||||
void handleCreditsLeftMovement(); // Movimiento hacia la izquierda en créditos
|
||||
void handleWaitingMovement(float deltaTime); // Animación del jugador saludando
|
||||
void updateWalkingStateForCredits(); // Actualiza estado de caminata en créditos
|
||||
|
||||
// --- Utilidades de animación ---
|
||||
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula animación de movimiento y disparo
|
||||
};
|
||||
Reference in New Issue
Block a user