Ja es pot "enner llour neim". Falta decidir quin de tots els dissenys m'agrada mes

This commit is contained in:
2024-09-29 22:25:31 +02:00
parent edc45b6cec
commit 2d5859b1c4
9 changed files with 327 additions and 99 deletions

View File

@@ -4,9 +4,10 @@
#include <stdlib.h> // for rand
#include <algorithm> // for max, min
#include "animated_sprite.h" // for AnimatedSprite
#include "input.h" // for inputs_e
#include "param.h" // for param
#include "texture.h" // for Texture
#include "enter_name.h"
#include "input.h" // for inputs_e
#include "param.h" // for param
#include "texture.h" // for Texture
// Constructor
Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
@@ -15,6 +16,7 @@ Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *
playerSprite = new AnimatedSprite(texture[0], "", animations[0]);
powerSprite = new AnimatedSprite(texture[1], "", animations[1]);
powerSprite->getTexture()->setAlpha(224);
enterName = new EnterName();
// Rectangulo con la zona de juego
this->playArea = playArea;
@@ -40,6 +42,10 @@ Player::~Player()
{
delete playerSprite;
delete powerSprite;
if (enterName)
{
delete enterName;
}
}
// Iniciador
@@ -80,6 +86,21 @@ void Player::init()
// Actua en consecuencia de la entrada recibida
void Player::setInput(int input)
{
switch (statusPlaying)
{
case PLAYER_STATUS_PLAYING:
setInputPlaying(input);
break;
case PLAYER_STATUS_ENTERING_NAME:
setInputEnteringName(input);
break;
}
}
// Procesa inputs para cuando está jugando
void Player::setInputPlaying(int input)
{
switch (input)
{
@@ -112,6 +133,37 @@ void Player::setInput(int input)
}
}
// Procesa inputs para cuando está introduciendo el nombre
void Player::setInputEnteringName(int input)
{
switch (input)
{
case input_left:
enterName->decPos();
break;
case input_right:
enterName->incPos();
break;
case input_up:
enterName->incIndex();
break;
case input_down:
enterName->decIndex();
break;
case input_start:
recordName = enterName->getName();
break;
default:
break;
}
setRecordName(enterName->getName());
}
// Mueve el jugador a la posición y animación que le corresponde
void Player::move()
{
@@ -373,6 +425,7 @@ void Player::setStatusPlaying(int value)
break;
case PLAYER_STATUS_ENTERING_NAME:
setRecordName("");
break;
case PLAYER_STATUS_DYING:
@@ -621,12 +674,35 @@ void Player::setName(std::string name)
this->name = name;
}
// Establece el nombre del jugador para la tabla de mejores puntuaciones
void Player::setRecordName(std::string recordName)
{
this->recordName = recordName.substr(0, 8);
}
// Obtiene el nombre del jugador
std::string Player::getName()
{
return name;
}
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones
std::string Player::getRecordName()
{
return recordName;
}
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
int Player::getRecordNamePos()
{
if (enterName)
{
return enterName->getPos();
}
return 0;
}
// Establece el mando que usará para ser controlado
void Player::setController(int index)
{