Añadido campo ID al jugador

Las balas y los mandos utilizan ahora este ID
This commit is contained in:
2024-09-11 12:15:18 +02:00
parent 1e2f121d82
commit ecf34558f4
6 changed files with 98 additions and 26 deletions

View File

@@ -2,16 +2,16 @@
#include "player.h"
// Constructor
Player::Player(float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
{
// Reserva memoria para los objetos
playerSprite = new AnimatedSprite(texture[0], "", animations[0]);
powerSprite = new AnimatedSprite(texture[1], "", animations[1]);
powerSprite->getTexture()->setAlpha(224);
// Rectangulo con la zona de juego
this->playArea = playArea;
// Establece la posición inicial del jugador
defaultPosX = posX = x;
defaultPosY = posY = y;
@@ -21,6 +21,7 @@ Player::Player(float x, int y, SDL_Rect *playArea, std::vector<Texture *> textur
powerSprite->setPosY(y - (powerSprite->getHeight() - playerSprite->getHeight()));
// Inicializa variables
this->id = id;
statusPlaying = PLAYER_STATUS_WAITING;
scoreBoardPanel = 0;
name = "";
@@ -587,4 +588,22 @@ void Player::setName(std::string name)
std::string Player::getName()
{
return name;
}
// Establece el mando que usará para ser controlado
void Player::setController(int index)
{
controllerIndex = index;
}
// Obtiene el mando que usa para ser controlado
int Player::getController()
{
return controllerIndex;
}
// Obtiene el "id" del jugador
int Player::getId()
{
return id;
}