302 lines
9.2 KiB
C++
302 lines
9.2 KiB
C++
#pragma once
|
||
|
||
#include <SDL2/SDL_rect.h> // para SDL_Rect
|
||
#include <SDL2/SDL_stdinc.h> // para Uint32
|
||
#include <memory> // para unique_ptr, shared_ptr
|
||
#include <string> // para string
|
||
#include <vector> // para vector
|
||
#include "animated_sprite.h" // para SpriteAnimated
|
||
#include "smart_sprite.h" // para SpriteAnimated
|
||
#include "enter_name.h" // para EnterName
|
||
#include "utils.h" // para Circle
|
||
class Texture;
|
||
enum class InputType : int;
|
||
enum class ScoreboardMode; // lines 12-12
|
||
|
||
// Estados del jugador
|
||
enum class PlayerStatus
|
||
{
|
||
WALKING_LEFT,
|
||
WALKING_RIGHT,
|
||
WALKING_STOP,
|
||
|
||
FIRING_UP,
|
||
FIRING_LEFT,
|
||
FIRING_RIGHT,
|
||
FIRING_NONE,
|
||
|
||
PLAYING,
|
||
CONTINUE,
|
||
WAITING,
|
||
ENTERING_NAME,
|
||
DYING,
|
||
DIED,
|
||
GAME_OVER,
|
||
};
|
||
|
||
// Variables del jugador
|
||
|
||
// Clase Player
|
||
class Player
|
||
{
|
||
private:
|
||
// Constantes
|
||
static constexpr int POWERUP_COUNTER_ = 1500; // Duración del estado PowerUp
|
||
static constexpr int INVULNERABLE_COUNTER_ = 200; // Duración del estado invulnerable
|
||
static constexpr int WIDTH_ = 30; // Anchura
|
||
static constexpr int HEIGHT_ = 30; // Altura
|
||
static constexpr float BASE_SPEED_ = 1.5f; // Velocidad base del jugador
|
||
|
||
// Objetos y punteros
|
||
std::unique_ptr<AnimatedSprite> player_sprite_; // Sprite para dibujar el jugador
|
||
std::unique_ptr<AnimatedSprite> power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope
|
||
std::unique_ptr<EnterName> enter_name_; // Clase utilizada para introducir el nombre
|
||
|
||
// Variables
|
||
int id_; // Numero de identificación para el jugador. Player1 = 1, Player2 = 2
|
||
SDL_Rect play_area_; // Rectangulo con la zona de juego
|
||
float pos_x_ = 0.0f; // Posicion en el eje X
|
||
int pos_y_ = 0; // Posicion en el eje Y
|
||
float default_pos_x_; // Posición inicial para el jugador
|
||
int default_pos_y_; // Posición inicial para el jugador
|
||
float vel_x_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje X
|
||
int vel_y_ = 0.0f; // Cantidad de pixeles a desplazarse en el eje Y
|
||
int cooldown_ = 10; // Contador durante el cual no puede disparar
|
||
int score_ = 0; // Puntos del jugador
|
||
float score_multiplier_ = 1.0f; // Multiplicador de puntos
|
||
PlayerStatus status_walking_ = PlayerStatus::WALKING_STOP; // Estado del jugador al moverse
|
||
PlayerStatus status_firing_ = PlayerStatus::FIRING_NONE; // Estado del jugador al disparar
|
||
PlayerStatus status_playing_ = PlayerStatus::WAITING; // Estado del jugador en el juego
|
||
bool invulnerable_ = true; // Indica si el jugador es invulnerable
|
||
int invulnerable_counter_ = INVULNERABLE_COUNTER_; // Contador para la invulnerabilidad
|
||
bool extra_hit_ = false; // Indica si el jugador tiene un toque extra
|
||
int coffees_ = 0; // Indica cuantos cafes lleva acumulados
|
||
bool power_up_ = false; // Indica si el jugador tiene activo el modo PowerUp
|
||
int power_up_counter_ = POWERUP_COUNTER_; // Temporizador para el modo PowerUp
|
||
int power_up_desp_x_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||
Circle collider_ = Circle(0, 0, 9); // Circulo de colisión del jugador
|
||
int continue_counter_ = 10; // Contador para poder continuar
|
||
Uint32 continue_ticks_ = 0; // Variable para poder cambiar el contador de continue en función del tiempo
|
||
int scoreboard_panel_ = 0; // Panel del marcador asociado al jugador
|
||
std::string name_; // Nombre del jugador
|
||
std::string record_name_; // Nombre del jugador para la tabla de mejores puntuaciones
|
||
int controller_index_ = 0; // Indice del array de mandos que utilizará para moverse
|
||
bool demo_; // Para que el jugador sepa si está en el modo demostración
|
||
int enter_name_counter_; // Contador para poner nombre
|
||
Uint32 enter_name_ticks_ = 0; // Variable para poder cambiar el contador de poner nombre en función del tiempo
|
||
|
||
// Actualiza el circulo de colisión a la posición del jugador
|
||
void shiftColliders();
|
||
|
||
// Monitoriza el estado
|
||
void updateInvulnerable();
|
||
|
||
// Actualiza el contador de continue
|
||
void updateContinueCounter();
|
||
|
||
// Actualiza el contador de entrar nombre
|
||
void updateEnterNameCounter();
|
||
|
||
// Decrementa el contador de entrar nombre
|
||
void decEnterNameCounter();
|
||
|
||
// Indica si el jugador se puede dibujar
|
||
bool isRenderable() const;
|
||
|
||
// Actualiza el panel del marcador
|
||
void updateScoreboard();
|
||
|
||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||
bool IsEligibleForHighScore();
|
||
|
||
// Cambia el modo del marcador
|
||
void setScoreboardMode(ScoreboardMode mode);
|
||
|
||
public:
|
||
// Constructor
|
||
Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations);
|
||
|
||
// Destructor
|
||
~Player() = default;
|
||
|
||
// Iniciador
|
||
void init();
|
||
|
||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||
void update();
|
||
|
||
// Pinta el jugador en pantalla
|
||
void render();
|
||
|
||
// Pone las texturas del jugador
|
||
void setPlayerTextures(const std::vector<std::shared_ptr<Texture>> &texture);
|
||
|
||
// Actua en consecuencia de la entrada recibida
|
||
void setInput(InputType input);
|
||
|
||
// Procesa inputs para cuando está jugando
|
||
void setInputPlaying(InputType input);
|
||
|
||
// Procesa inputs para cuando está introduciendo el nombre
|
||
void setInputEnteringName(InputType input);
|
||
|
||
// Mueve el jugador a la posición y animación que le corresponde
|
||
void move();
|
||
|
||
// Establece el estado del jugador
|
||
void setWalkingStatus(PlayerStatus status);
|
||
|
||
// Establece el estado del jugador
|
||
void setFiringStatus(PlayerStatus status);
|
||
|
||
// Establece la animación correspondiente al estado
|
||
void setAnimation();
|
||
|
||
// Obtiene el valor de la variable
|
||
int getPosX() const;
|
||
|
||
// Obtiene el valor de la variable
|
||
int getPosY() const;
|
||
|
||
// Obtiene el valor de la variable
|
||
int getWidth() const;
|
||
|
||
// Obtiene el valor de la variable
|
||
int getHeight() const;
|
||
|
||
// Indica si el jugador puede disparar
|
||
bool canFire() const;
|
||
|
||
// Establece el valor de la variable
|
||
void setFireCooldown(int time);
|
||
|
||
// Actualiza el valor de la variable
|
||
void updateCooldown();
|
||
|
||
// Obtiene la puntuación del jugador
|
||
int getScore() const;
|
||
|
||
// Asigna un valor a la puntuación del jugador
|
||
void setScore(int score);
|
||
|
||
// Incrementa la puntuación del jugador
|
||
void addScore(int score);
|
||
|
||
// Indica si el jugador está jugando
|
||
bool isPlaying() const;
|
||
|
||
// Indica si el jugador está continuando
|
||
bool isContinue() const;
|
||
|
||
// Indica si el jugador está esperando
|
||
bool isWaiting() const;
|
||
|
||
// Indica si el jugador está introduciendo su nombre
|
||
bool isEnteringName() const;
|
||
|
||
// Indica si el jugador está muriendose
|
||
bool isDying() const;
|
||
|
||
// Indica si el jugador ha terminado de morir
|
||
bool hasDied() const;
|
||
|
||
// Indica si el jugador ya ha terminado de jugar
|
||
bool isGameOver() const;
|
||
|
||
// Establece el estado del jugador en el juego
|
||
void setStatusPlaying(PlayerStatus value);
|
||
|
||
// Obtiene el estado del jugador en el juego
|
||
PlayerStatus getStatusPlaying() const;
|
||
|
||
// Obtiene el valor de la variable
|
||
float getScoreMultiplier() const;
|
||
|
||
// Establece el valor de la variable
|
||
void setScoreMultiplier(float value);
|
||
|
||
// Aumenta el valor de la variable hasta un máximo
|
||
void incScoreMultiplier();
|
||
|
||
// Decrementa el valor de la variable hasta un mínimo
|
||
void decScoreMultiplier();
|
||
|
||
// Obtiene el valor de la variable
|
||
bool isInvulnerable() const;
|
||
|
||
// Establece el valor del estado
|
||
void setInvulnerable(bool value);
|
||
|
||
// Obtiene el valor de la variable
|
||
int getInvulnerableCounter() const;
|
||
|
||
// Establece el valor de la variable
|
||
void setInvulnerableCounter(int value);
|
||
|
||
// Obtiene el valor de la variable
|
||
bool isPowerUp() const;
|
||
|
||
// Establece el valor de la variable a verdadero
|
||
void setPowerUp();
|
||
|
||
// Obtiene el valor de la variable
|
||
int getPowerUpCounter() const;
|
||
|
||
// Establece el valor de la variable
|
||
void setPowerUpCounter(int value);
|
||
|
||
// Actualiza el valor de la variable
|
||
void updatePowerUp();
|
||
|
||
// Obtiene el valor de la variable
|
||
bool hasExtraHit() const;
|
||
|
||
// Concede un toque extra al jugador
|
||
void giveExtraHit();
|
||
|
||
// Quita el toque extra al jugador
|
||
void removeExtraHit();
|
||
|
||
// Devuelve el número de cafes actuales
|
||
int getCoffees() const;
|
||
|
||
// Obtiene el circulo de colisión
|
||
Circle &getCollider();
|
||
|
||
// Obtiene el valor de la variable
|
||
int getContinueCounter() const;
|
||
|
||
// Le asigna un panel en el marcador al jugador
|
||
void setScoreBoardPanel(int panel);
|
||
|
||
// Obtiene el valor de la variable
|
||
int getScoreBoardPanel() const;
|
||
|
||
// Decrementa el contador de continuar
|
||
void decContinueCounter();
|
||
|
||
// Establece el nombre del jugador
|
||
void setName(const std::string &name);
|
||
|
||
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||
void setRecordName(const std::string &record_name);
|
||
|
||
// Obtiene el nombre del jugador
|
||
std::string getName() const;
|
||
|
||
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones
|
||
std::string getRecordName() const;
|
||
|
||
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||
int getRecordNamePos() const;
|
||
|
||
// Establece el mando que usará para ser controlado
|
||
void setController(int index);
|
||
|
||
// Obtiene el mando que usa para ser controlado
|
||
int getController() const;
|
||
|
||
// Obtiene el "id" del jugador
|
||
int getId() const;
|
||
};
|