298 lines
8.5 KiB
C++
298 lines
8.5 KiB
C++
#pragma once
|
||
|
||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||
#include <memory> // for unique_ptr, shared_ptr
|
||
#include <string> // for string
|
||
#include <vector> // for vector
|
||
#include "animated_sprite.h" // for AnimatedSprite
|
||
#include "enter_name.h" // for EnterName
|
||
#include "utils.h" // for 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_NO,
|
||
|
||
PLAYING,
|
||
CONTINUE,
|
||
WAITING,
|
||
ENTERING_NAME,
|
||
DYING,
|
||
DIED,
|
||
GAME_OVER,
|
||
};
|
||
|
||
// Variables del jugador
|
||
constexpr int PLAYER_INVULNERABLE_COUNTER = 200;
|
||
constexpr int PLAYER_POWERUP_COUNTER = 1500;
|
||
|
||
// Clase Player
|
||
class Player
|
||
{
|
||
private:
|
||
// 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
|
||
SDL_Rect *play_area_; // Rectangulo con la zona de juego
|
||
|
||
// Variables
|
||
int id_; // Numero de identificación para el jugador
|
||
float pos_x_; // Posicion en el eje X
|
||
int pos_y_; // 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
|
||
int width_; // Anchura
|
||
int height_; // Altura
|
||
float vel_x_; // Cantidad de pixeles a desplazarse en el eje X
|
||
int vel_y_; // Cantidad de pixeles a desplazarse en el eje Y
|
||
float base_speed_; // Velocidad base del jugador
|
||
int cooldown_; // Contador durante el cual no puede disparar
|
||
int score_; // Puntos del jugador
|
||
float score_multiplier_; // Multiplicador de puntos
|
||
PlayerStatus status_walking_; // Estado del jugador al moverse
|
||
PlayerStatus status_firing_; // Estado del jugador al disparar
|
||
PlayerStatus status_playing_; // Estado del jugador en el juego
|
||
bool invulnerable_; // Indica si el jugador es invulnerable
|
||
int invulnerable_counter_; // Contador para la invulnerabilidad
|
||
bool extra_hit_; // Indica si el jugador tiene un toque extra
|
||
int coffees_; // Indica cuantos cafes lleva acumulados
|
||
bool power_up_; // Indica si el jugador tiene activo el modo PowerUp
|
||
int power_up_counter_; // Temporizador para el modo PowerUp
|
||
int power_up_desp_x_; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||
bool input_; // Indica si puede recibir ordenes de entrada
|
||
Circle collider_; // Circulo de colisión del jugador
|
||
int continue_counter_; // Contador para poder continuar
|
||
Uint32 continue_ticks_; // Variable para poder cambiar el contador de continue en función del tiempo
|
||
int scoreboard_panel_; // Panel del marcador asociado al jugador
|
||
std::string name_; // Nombre del jugador
|
||
std::string record_name_; // Nombre del jugador para l atabla de mejores puntuaciones
|
||
int controller_index_; // Indice del array de mandos que utilizará para moverse
|
||
bool demo_; // Para que el jugador sepa si está en el modo demostración
|
||
|
||
// 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();
|
||
|
||
// 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, 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 updatePowerUpCounter();
|
||
|
||
// 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();
|
||
|
||
// Habilita la entrada de ordenes
|
||
void enableInput();
|
||
|
||
// Deshabilita la entrada de ordenes
|
||
void disableInput();
|
||
|
||
// 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;
|
||
};
|