239 lines
6.1 KiB
C++
239 lines
6.1 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL.h>
|
|
#include "common/animatedsprite.h"
|
|
#include "common/asset.h"
|
|
#include "common/input.h"
|
|
#include "common/texture.h"
|
|
#include "common/utils.h"
|
|
|
|
// Estados del jugador
|
|
#define PLAYER_STATUS_WALKING_LEFT 0
|
|
#define PLAYER_STATUS_WALKING_RIGHT 1
|
|
#define PLAYER_STATUS_WALKING_STOP 2
|
|
|
|
#define PLAYER_STATUS_FIRING_UP 0
|
|
#define PLAYER_STATUS_FIRING_LEFT 1
|
|
#define PLAYER_STATUS_FIRING_RIGHT 2
|
|
#define PLAYER_STATUS_FIRING_NO 3
|
|
|
|
#define PLAYER_STATUS_PLAYING 0
|
|
#define PLAYER_STATUS_CONTINUE 1
|
|
#define PLAYER_STATUS_WAITING 2
|
|
|
|
// Variables del jugador
|
|
#define PLAYER_INVULNERABLE_COUNTER 200
|
|
#define PLAYER_POWERUP_COUNTER 1500
|
|
|
|
// Clase Player
|
|
class Player
|
|
{
|
|
private:
|
|
// Objetos y punteros
|
|
AnimatedSprite *playerSprite; // Sprite para dibujar el jugador
|
|
AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
|
|
|
// Variables
|
|
float posX; // Posicion en el eje X
|
|
int posY; // Posicion en el eje Y
|
|
|
|
float defaultPosX; // Posición inicial para el jugador
|
|
int defaultPosY; // Posición inicial para el jugador
|
|
|
|
int width; // Anchura
|
|
int height; // Altura
|
|
|
|
float velX; // Cantidad de pixeles a desplazarse en el eje X
|
|
int velY; // Cantidad de pixeles a desplazarse en el eje Y
|
|
|
|
float baseSpeed; // Velocidad base del jugador
|
|
int cooldown; // Contador durante el cual no puede disparar
|
|
|
|
int score; // Puntos del jugador
|
|
float scoreMultiplier; // Multiplicador de puntos
|
|
|
|
int statusWalking; // Estado del jugador al moverse
|
|
int statusFiring; // Estado del jugador al disparar
|
|
int statusPlaying; // Estado del jugador en el juego
|
|
|
|
bool invulnerable; // Indica si el jugador es invulnerable
|
|
int invulnerableCounter; // Contador para la invulnerabilidad
|
|
bool extraHit; // Indica si el jugador tiene un toque extra
|
|
int coffees; // Indica cuantos cafes lleva acumulados
|
|
bool powerUp; // Indica si el jugador tiene activo el modo PowerUp
|
|
int powerUpCounter; // Temporizador para el modo PowerUp
|
|
int powerUpDespX; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
|
bool input; // Indica si puede recibir ordenes de entrada
|
|
circle_t collider; // Circulo de colisión del jugador
|
|
int continueCounter; // Contador para poder continuar
|
|
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
|
|
int scoreBoardPanel; // Panel del marcador asociado al jugador
|
|
std::string name; // Nombre del jugador
|
|
|
|
// 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();
|
|
|
|
public:
|
|
// Constructor
|
|
Player(float x, int y, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations);
|
|
|
|
// Destructor
|
|
~Player();
|
|
|
|
// 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(std::vector<Texture *> texture);
|
|
|
|
// Actua en consecuencia de la entrada recibida
|
|
void setInput(int input);
|
|
|
|
// Mueve el jugador a la posición y animación que le corresponde
|
|
void move();
|
|
|
|
// Establece el estado del jugador
|
|
void setWalkingStatus(int status);
|
|
|
|
// Establece el estado del jugador
|
|
void setFiringStatus(int status);
|
|
|
|
// Establece la animación correspondiente al estado
|
|
void setAnimation();
|
|
|
|
// Obtiene el valor de la variable
|
|
int getPosX();
|
|
|
|
// Obtiene el valor de la variable
|
|
int getPosY();
|
|
|
|
// Obtiene el valor de la variable
|
|
int getWidth();
|
|
|
|
// Obtiene el valor de la variable
|
|
int getHeight();
|
|
|
|
// Indica si el jugador puede disparar
|
|
bool canFire();
|
|
|
|
// 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();
|
|
|
|
// Asigna un valor a la puntuación del jugador
|
|
void setScore(Uint32 score);
|
|
|
|
// Incrementa la puntuación del jugador
|
|
void addScore(Uint32 score);
|
|
|
|
// Indica si el jugador está jugando
|
|
bool isPlaying();
|
|
|
|
// Indica si el jugador está continuando
|
|
bool isContinue();
|
|
|
|
// Indica si el jugador está esperando
|
|
bool isWaiting();
|
|
|
|
// Establece el estado del jugador en el juego
|
|
void setStatusPlaying(int value);
|
|
|
|
// Obtiene el estado del jugador en el juego
|
|
int getStatusPlaying();
|
|
|
|
// Obtiene el valor de la variable
|
|
float getScoreMultiplier();
|
|
|
|
// 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();
|
|
|
|
// Establece el valor del estado
|
|
void setInvulnerable(bool value);
|
|
|
|
// Obtiene el valor de la variable
|
|
int getInvulnerableCounter();
|
|
|
|
// Establece el valor de la variable
|
|
void setInvulnerableCounter(int value);
|
|
|
|
// Obtiene el valor de la variable
|
|
bool isPowerUp();
|
|
|
|
// Establece el valor de la variable a verdadero
|
|
void setPowerUp();
|
|
|
|
// Obtiene el valor de la variable
|
|
int getPowerUpCounter();
|
|
|
|
// 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();
|
|
|
|
// 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();
|
|
|
|
// Obtiene el circulo de colisión
|
|
circle_t &getCollider();
|
|
|
|
// Obtiene el valor de la variable
|
|
int getContinueCounter();
|
|
|
|
// Le asigna un panel en el marcador al jugador
|
|
void setScoreBoardPanel(int panel);
|
|
|
|
// Obtiene el valor de la variable
|
|
int getScoreBoardPanel();
|
|
|
|
// Decrementa el contador de continuar
|
|
void decContinueCounter();
|
|
|
|
// Establece el nombre del jugador
|
|
void setName(std::string name);
|
|
|
|
// Obtiene el nombre del jugador
|
|
std::string getName();
|
|
};
|