Ja es pot "enner llour neim". Falta decidir quin de tots els dissenys m'agrada mes
This commit is contained in:
@@ -2,20 +2,19 @@
|
|||||||
#include <algorithm> // for max, min
|
#include <algorithm> // for max, min
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
EnterName::EnterName(std::string *name)
|
EnterName::EnterName()
|
||||||
{
|
{
|
||||||
// Obtiene el puntero al nombre
|
// Obtiene el puntero al nombre
|
||||||
this->name = name;
|
name = "";
|
||||||
|
|
||||||
// Inicia la lista de caracteres permitidos
|
// Inicia la lista de caracteres permitidos
|
||||||
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
// characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
|
||||||
pos = 0;
|
pos = 0;
|
||||||
numCharacters = (int)characterList.size();
|
numCharacters = (int)characterList.size();
|
||||||
|
|
||||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
// Pone la lista de indices para que refleje el nombre
|
||||||
{
|
updateCharacterIndex();
|
||||||
characterIndex[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -45,6 +44,7 @@ void EnterName::incIndex()
|
|||||||
{
|
{
|
||||||
characterIndex[pos] = 0;
|
characterIndex[pos] = 0;
|
||||||
}
|
}
|
||||||
|
updateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrementa el índice
|
// Decrementa el índice
|
||||||
@@ -55,14 +55,54 @@ void EnterName::decIndex()
|
|||||||
{
|
{
|
||||||
characterIndex[pos] = numCharacters - 1;
|
characterIndex[pos] = numCharacters - 1;
|
||||||
}
|
}
|
||||||
|
updateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la variable
|
// Actualiza la variable
|
||||||
void EnterName::updateName()
|
void EnterName::updateName()
|
||||||
{
|
{
|
||||||
name->clear();
|
name.clear();
|
||||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||||
{
|
{
|
||||||
name->push_back(characterList[characterIndex[i]]);
|
name.push_back(characterList[characterIndex[i]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza la variable
|
||||||
|
void EnterName::updateCharacterIndex()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||||
|
{
|
||||||
|
characterIndex[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (int)name.size(); ++i)
|
||||||
|
{
|
||||||
|
characterIndex[i] = findIndex(name.at(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encuentra el indice de un caracter en "characterList"
|
||||||
|
int EnterName::findIndex(char character)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)characterList.size(); ++i)
|
||||||
|
{
|
||||||
|
if (character == characterList[i])
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el nombre
|
||||||
|
std::string EnterName::getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la posición que se está editando
|
||||||
|
int EnterName::getPos()
|
||||||
|
{
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
@@ -17,11 +17,27 @@ class EnterName
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string characterList; // Lista de todos los caracteres permitidos
|
std::string characterList; // Lista de todos los caracteres permitidos
|
||||||
std::string *name; // Nombre introducido
|
std::string name; // Nombre introducido
|
||||||
int pos; // Posición a editar del nombre
|
int pos; // Posición a editar del nombre
|
||||||
int numCharacters; // Cantidad de caracteres de la lista de caracteres
|
int numCharacters; // Cantidad de caracteres de la lista de caracteres
|
||||||
int characterIndex[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
int characterIndex[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||||
|
|
||||||
|
// Actualiza la variable
|
||||||
|
void updateName();
|
||||||
|
|
||||||
|
// Actualiza la variable
|
||||||
|
void updateCharacterIndex();
|
||||||
|
|
||||||
|
// Encuentra el indice de un caracter en "characterList"
|
||||||
|
int findIndex(char character);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
EnterName();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~EnterName();
|
||||||
|
|
||||||
// Incrementa la posición
|
// Incrementa la posición
|
||||||
void incPos();
|
void incPos();
|
||||||
|
|
||||||
@@ -34,13 +50,9 @@ private:
|
|||||||
// Decrementa el índice
|
// Decrementa el índice
|
||||||
void decIndex();
|
void decIndex();
|
||||||
|
|
||||||
// Actualiza la variable
|
// Obtiene el nombre
|
||||||
void updateName();
|
std::string getName();
|
||||||
|
|
||||||
public:
|
// Obtiene la posición que se está editando
|
||||||
// Constructor
|
int getPos();
|
||||||
EnterName(std::string *name);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~EnterName();
|
|
||||||
};
|
};
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
|
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
|
||||||
#include "explosions.h" // for Explosions
|
#include "explosions.h" // for Explosions
|
||||||
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN...
|
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN...
|
||||||
|
#include "global_inputs.h" // for checkGlobalInputs
|
||||||
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
|
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
|
||||||
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
||||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
||||||
@@ -2054,48 +2055,9 @@ void Game::updateMenace()
|
|||||||
// Gestiona la entrada durante el juego
|
// Gestiona la entrada durante el juego
|
||||||
void Game::checkInput()
|
void Game::checkInput()
|
||||||
{
|
{
|
||||||
// Comprueba si se sale con el teclado
|
// Comprueba si se pulsa el botón de pausa
|
||||||
if (input->checkInput(input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
quit(section::OPTIONS_QUIT_NORMAL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se va a resetear el juego
|
|
||||||
if (input->checkInput(input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
|
||||||
{
|
|
||||||
section::name = section::NAME_INIT;
|
|
||||||
screen->showNotification("Reset");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
for (int i = 0; i < input->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Comprueba si se sale con el mando
|
|
||||||
if (input->checkModInput(input_service, input_exit, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
quit(section::OPTIONS_QUIT_SHUTDOWN);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se va a resetear el juego
|
|
||||||
if (input->checkModInput(input_service, input_reset, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
section::name = section::NAME_LOGO;
|
|
||||||
screen->showNotification("Reset");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se va a activar o desactivar el audio
|
|
||||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
|
||||||
{
|
|
||||||
options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled;
|
|
||||||
JA_EnableMusic(options.audio.music.enabled);
|
|
||||||
JA_EnableSound(options.audio.sound.enabled);
|
|
||||||
screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si se va a pausar el juego
|
// Comprueba si se va a pausar el juego
|
||||||
if (input->checkModInput(input_service, input_pause, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
if (input->checkModInput(input_service, input_pause, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||||
{
|
{
|
||||||
@@ -2275,10 +2237,10 @@ void Game::checkInput()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else if (player->isContinue())
|
||||||
{
|
{
|
||||||
// Si no está jugando, el botón de start le permite continuar jugando
|
// Si no está jugando, el botón de start le permite continuar jugando
|
||||||
if (input->checkInput(input_start, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||||
{
|
{
|
||||||
// Si no ha entrado ya en el estado de game over, entonces se puede continuar
|
// Si no ha entrado ya en el estado de game over, entonces se puede continuar
|
||||||
if (gameOverCounter == GAME_OVER_COUNTER)
|
if (gameOverCounter == GAME_OVER_COUNTER)
|
||||||
@@ -2288,19 +2250,60 @@ void Game::checkInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si está continuando, los botones de fuego hacen decrementar el contador
|
// Si está continuando, los botones de fuego hacen decrementar el contador
|
||||||
const bool fire1 = input->checkInput(input_fire_left, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
const bool fire1 = input->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||||
const bool fire2 = input->checkInput(input_fire_center, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
const bool fire2 = input->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||||
const bool fire3 = input->checkInput(input_fire_right, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
const bool fire3 = input->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||||
if (fire1 || fire2 || fire3)
|
if (fire1 || fire2 || fire3)
|
||||||
{
|
{
|
||||||
player->decContinueCounter();
|
player->decContinueCounter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (player->isEnteringName())
|
||||||
|
{
|
||||||
|
const bool fire1 = input->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||||
|
const bool fire2 = input->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||||
|
const bool fire3 = input->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||||
|
if (fire1 || fire2 || fire3)
|
||||||
|
{
|
||||||
|
player->setInput(input_right);
|
||||||
|
if (player->getRecordNamePos() == 7)
|
||||||
|
{
|
||||||
|
player->setInput(input_start);
|
||||||
|
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||||
|
player->setStatusPlaying(PLAYER_STATUS_CONTINUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (input->checkInput(input_up, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||||
|
{
|
||||||
|
player->setInput(input_up);
|
||||||
|
}
|
||||||
|
else if (input->checkInput(input_down, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||||
|
{
|
||||||
|
player->setInput(input_down);
|
||||||
|
}
|
||||||
|
else if (input->checkInput(input_left, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||||
|
{
|
||||||
|
player->setInput(input_left);
|
||||||
|
}
|
||||||
|
else if (input->checkInput(input_right, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||||
|
{
|
||||||
|
player->setInput(input_right);
|
||||||
|
}
|
||||||
|
else if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||||
|
{
|
||||||
|
player->setInput(input_start);
|
||||||
|
addScoreToScoreBoard(player->getRecordName(), player->getScore());
|
||||||
|
player->setStatusPlaying(PLAYER_STATUS_CONTINUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input para el resto de objetos
|
// Comprueba el input para el resto de objetos
|
||||||
screen->checkInput();
|
screen->checkInput();
|
||||||
|
|
||||||
|
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||||
|
checkGlobalInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta diferentes mensajes en la pantalla
|
// Pinta diferentes mensajes en la pantalla
|
||||||
@@ -2789,7 +2792,7 @@ void Game::pause(bool value)
|
|||||||
// Añade una puntuación a la tabla de records
|
// Añade una puntuación a la tabla de records
|
||||||
void Game::addScoreToScoreBoard(std::string name, int score)
|
void Game::addScoreToScoreBoard(std::string name, int score)
|
||||||
{
|
{
|
||||||
const hiScoreEntry_t entry = {name, score};
|
const hiScoreEntry_t entry = {trim(name), score};
|
||||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||||
manager->add(entry);
|
manager->add(entry);
|
||||||
delete manager;
|
delete manager;
|
||||||
@@ -2822,6 +2825,8 @@ void Game::checkPlayersStatusPlaying()
|
|||||||
|
|
||||||
case PLAYER_STATUS_ENTERING_NAME:
|
case PLAYER_STATUS_ENTERING_NAME:
|
||||||
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME);
|
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME);
|
||||||
|
scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName());
|
||||||
|
scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_DYING:
|
case PLAYER_STATUS_DYING:
|
||||||
|
|||||||
@@ -4,9 +4,10 @@
|
|||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // for rand
|
||||||
#include <algorithm> // for max, min
|
#include <algorithm> // for max, min
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "animated_sprite.h" // for AnimatedSprite
|
||||||
#include "input.h" // for inputs_e
|
#include "enter_name.h"
|
||||||
#include "param.h" // for param
|
#include "input.h" // for inputs_e
|
||||||
#include "texture.h" // for Texture
|
#include "param.h" // for param
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(int id, 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)
|
||||||
@@ -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]);
|
playerSprite = new AnimatedSprite(texture[0], "", animations[0]);
|
||||||
powerSprite = new AnimatedSprite(texture[1], "", animations[1]);
|
powerSprite = new AnimatedSprite(texture[1], "", animations[1]);
|
||||||
powerSprite->getTexture()->setAlpha(224);
|
powerSprite->getTexture()->setAlpha(224);
|
||||||
|
enterName = new EnterName();
|
||||||
|
|
||||||
// Rectangulo con la zona de juego
|
// Rectangulo con la zona de juego
|
||||||
this->playArea = playArea;
|
this->playArea = playArea;
|
||||||
@@ -40,6 +42,10 @@ Player::~Player()
|
|||||||
{
|
{
|
||||||
delete playerSprite;
|
delete playerSprite;
|
||||||
delete powerSprite;
|
delete powerSprite;
|
||||||
|
if (enterName)
|
||||||
|
{
|
||||||
|
delete enterName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
@@ -80,6 +86,21 @@ void Player::init()
|
|||||||
|
|
||||||
// Actua en consecuencia de la entrada recibida
|
// Actua en consecuencia de la entrada recibida
|
||||||
void Player::setInput(int input)
|
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)
|
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
|
// Mueve el jugador a la posición y animación que le corresponde
|
||||||
void Player::move()
|
void Player::move()
|
||||||
{
|
{
|
||||||
@@ -373,6 +425,7 @@ void Player::setStatusPlaying(int value)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_ENTERING_NAME:
|
case PLAYER_STATUS_ENTERING_NAME:
|
||||||
|
setRecordName("");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STATUS_DYING:
|
case PLAYER_STATUS_DYING:
|
||||||
@@ -621,12 +674,35 @@ void Player::setName(std::string name)
|
|||||||
this->name = 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
|
// Obtiene el nombre del jugador
|
||||||
std::string Player::getName()
|
std::string Player::getName()
|
||||||
{
|
{
|
||||||
return name;
|
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
|
// Establece el mando que usará para ser controlado
|
||||||
void Player::setController(int index)
|
void Player::setController(int index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for circle_t
|
#include "utils.h" // for circle_t
|
||||||
class AnimatedSprite;
|
class AnimatedSprite;
|
||||||
|
class EnterName;
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
// Estados del jugador
|
// Estados del jugador
|
||||||
@@ -37,6 +38,7 @@ private:
|
|||||||
AnimatedSprite *playerSprite; // Sprite para dibujar el jugador
|
AnimatedSprite *playerSprite; // Sprite para dibujar el jugador
|
||||||
AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
|
||||||
SDL_Rect *playArea; // Rectangulo con la zona de juego
|
SDL_Rect *playArea; // Rectangulo con la zona de juego
|
||||||
|
EnterName *enterName;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int id; // Numero de identificación para el jugador
|
int id; // Numero de identificación para el jugador
|
||||||
@@ -68,6 +70,7 @@ private:
|
|||||||
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
|
Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo
|
||||||
int scoreBoardPanel; // Panel del marcador asociado al jugador
|
int scoreBoardPanel; // Panel del marcador asociado al jugador
|
||||||
std::string name; // Nombre del jugador
|
std::string name; // Nombre del jugador
|
||||||
|
std::string recordName; // Nombre del jugador para l atabla de mejores puntuaciones
|
||||||
int controllerIndex; // Indice del array de mandos que utilizará para moverse
|
int controllerIndex; // Indice del array de mandos que utilizará para moverse
|
||||||
|
|
||||||
// Actualiza el circulo de colisión a la posición del jugador
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
@@ -101,6 +104,12 @@ public:
|
|||||||
// Actua en consecuencia de la entrada recibida
|
// Actua en consecuencia de la entrada recibida
|
||||||
void setInput(int input);
|
void setInput(int input);
|
||||||
|
|
||||||
|
// Procesa inputs para cuando está jugando
|
||||||
|
void setInputPlaying(int input);
|
||||||
|
|
||||||
|
// Procesa inputs para cuando está introduciendo el nombre
|
||||||
|
void setInputEnteringName(int input);
|
||||||
|
|
||||||
// Mueve el jugador a la posición y animación que le corresponde
|
// Mueve el jugador a la posición y animación que le corresponde
|
||||||
void move();
|
void move();
|
||||||
|
|
||||||
@@ -242,9 +251,18 @@ public:
|
|||||||
// Establece el nombre del jugador
|
// Establece el nombre del jugador
|
||||||
void setName(std::string name);
|
void setName(std::string name);
|
||||||
|
|
||||||
|
// Establece el nombre del jugador para la tabla de mejores puntuaciones
|
||||||
|
void setRecordName(std::string recordName);
|
||||||
|
|
||||||
// Obtiene el nombre del jugador
|
// Obtiene el nombre del jugador
|
||||||
std::string getName();
|
std::string getName();
|
||||||
|
|
||||||
|
// Obtiene el nombre del jugador para la tabla de mejores puntuaciones
|
||||||
|
std::string getRecordName();
|
||||||
|
|
||||||
|
// Obtiene la posici´´on que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||||
|
int getRecordNamePos();
|
||||||
|
|
||||||
// Establece el mando que usará para ser controlado
|
// Establece el mando que usará para ser controlado
|
||||||
void setController(int index);
|
void setController(int index);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <math.h> // for roundf
|
#include <math.h> // for roundf
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||||
@@ -23,9 +23,11 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
|||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
stage = 1;
|
stage = 1;
|
||||||
for (int i = 0; i< SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
name[i] = "";
|
name[i] = "";
|
||||||
|
recordName[i] = "";
|
||||||
|
selectorPos[i] = 0;
|
||||||
score[i] = 0;
|
score[i] = 0;
|
||||||
mult[i] = 0;
|
mult[i] = 0;
|
||||||
continueCounter[i] = 0;
|
continueCounter[i] = 0;
|
||||||
@@ -149,6 +151,18 @@ void Scoreboard::setName(int panel, std::string name)
|
|||||||
this->name[panel] = name;
|
this->name[panel] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Scoreboard::setRecordName(int panel, std::string recordName)
|
||||||
|
{
|
||||||
|
this->recordName[panel] = recordName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Scoreboard::setSelectorPos(int panel, int pos)
|
||||||
|
{
|
||||||
|
selectorPos[panel] = pos;
|
||||||
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Scoreboard::setScore(int panel, int score)
|
void Scoreboard::setScore(int panel, int score)
|
||||||
{
|
{
|
||||||
@@ -274,7 +288,7 @@ void Scoreboard::fillPanelTextures()
|
|||||||
|
|
||||||
// HI-SCORE
|
// HI-SCORE
|
||||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(56));
|
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(56));
|
||||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, hiScoreName + " - " +updateScoreText(hiScore));
|
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, hiScoreName + " - " + updateScoreText(hiScore));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCOREBOARD_MODE_CONTINUE:
|
case SCOREBOARD_MODE_CONTINUE:
|
||||||
@@ -288,8 +302,36 @@ void Scoreboard::fillPanelTextures()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SCOREBOARD_MODE_ENTER_NAME:
|
case SCOREBOARD_MODE_ENTER_NAME:
|
||||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, "ENTER NAME");
|
{
|
||||||
|
// SCORE
|
||||||
|
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, name[i]);
|
||||||
|
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score[i]));
|
||||||
|
|
||||||
|
// ENTER NAME
|
||||||
|
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang::getText(106));
|
||||||
|
//color_t selectorColor = lightenColor(color, 36);
|
||||||
|
color_t textColor = {0xFB, 0xF2, 0x36};
|
||||||
|
SDL_Rect rect = {enterNamePos.x, enterNamePos.y, 8, 8};
|
||||||
|
for (int j = 0; j < (int)recordName[i].size(); ++j)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 255);
|
||||||
|
SDL_RenderDrawLine(renderer, rect.x + 1, rect.y + rect.h + 1, rect.x + rect.w - 2, rect.y + rect.h + 1);
|
||||||
|
if (j == selectorPos[i])
|
||||||
|
{
|
||||||
|
// SDL_SetRenderDrawColor(renderer, selectorColor.r, selectorColor.g, selectorColor.b, 255);
|
||||||
|
// SDL_RenderFillRect(renderer, &rect);
|
||||||
|
SDL_SetRenderDrawColor(renderer, textColor.r, textColor.g, textColor.b, 255);
|
||||||
|
SDL_RenderDrawLine(renderer, rect.x + 1, rect.y + rect.h + 1, rect.x + rect.w - 2, rect.y + rect.h + 1);
|
||||||
|
textScoreBoard->writeColored(rect.x + 1, rect.y + 1, recordName[i].substr(j, 1), textColor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textScoreBoard->write(rect.x + 1, rect.y + 1, recordName[i].substr(j, 1));
|
||||||
|
}
|
||||||
|
rect.x += 8;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -359,6 +401,11 @@ void Scoreboard::recalculateAnchors()
|
|||||||
slot4_3 = {col, row3};
|
slot4_3 = {col, row3};
|
||||||
slot4_4 = {col, row4};
|
slot4_4 = {col, row4};
|
||||||
|
|
||||||
|
// Primer cuadrado para poner el nombre de record
|
||||||
|
const int enterNameLenght = 8 * 8;
|
||||||
|
enterNamePos.x = (panelWidth - enterNameLenght) / 2;
|
||||||
|
enterNamePos.y = row4 - 1;
|
||||||
|
|
||||||
// Recoloca los sprites
|
// Recoloca los sprites
|
||||||
if (powerMeterSprite)
|
if (powerMeterSprite)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <string> // for string, basic_string
|
#include <string> // for string, basic_string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for color_t
|
#include "utils.h" // for color_t
|
||||||
class Asset;
|
class Asset;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
class Text;
|
class Text;
|
||||||
@@ -52,22 +52,25 @@ private:
|
|||||||
std::vector<SDL_Texture *> panelTexture; // Texturas para dibujar cada panel;
|
std::vector<SDL_Texture *> panelTexture; // Texturas para dibujar cada panel;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int stage; // Número de fase actual
|
int stage; // Número de fase actual
|
||||||
std::string name[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
|
std::string name[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
|
||||||
int score[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores
|
std::string recordName[SCOREBOARD_MAX_PANELS]; // Nombre introducido para la tabla de records
|
||||||
float mult[SCOREBOARD_MAX_PANELS]; // Multiplicador de los jugadores
|
int selectorPos[SCOREBOARD_MAX_PANELS]; // Posición del selector de letra para introducir el nombre
|
||||||
int continueCounter[SCOREBOARD_MAX_PANELS]; // Tiempo para continuar de los jugadores
|
int score[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores
|
||||||
int hiScore; // Máxima puntuación
|
float mult[SCOREBOARD_MAX_PANELS]; // Multiplicador de los jugadores
|
||||||
float power; // Poder actual de la fase
|
int continueCounter[SCOREBOARD_MAX_PANELS]; // Tiempo para continuar de los jugadores
|
||||||
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
int hiScore; // Máxima puntuación
|
||||||
color_t color; // Color del marcador
|
float power; // Poder actual de la fase
|
||||||
SDL_Rect rect; // Posición y dimensiones del marcador
|
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
||||||
panel_t panel[SCOREBOARD_MAX_PANELS]; // Lista con todos los paneles del marcador
|
color_t color; // Color del marcador
|
||||||
Uint32 ticks; // Variable donde almacenar el valor de SDL_GetTiks()
|
SDL_Rect rect; // Posición y dimensiones del marcador
|
||||||
int counter; // Contador
|
panel_t panel[SCOREBOARD_MAX_PANELS]; // Lista con todos los paneles del marcador
|
||||||
|
Uint32 ticks; // Variable donde almacenar el valor de SDL_GetTiks()
|
||||||
|
int counter; // Contador
|
||||||
|
|
||||||
// Puntos predefinidos para colocar elementos en los paneles
|
// Puntos predefinidos para colocar elementos en los paneles
|
||||||
SDL_Point slot4_1, slot4_2, slot4_3, slot4_4;
|
SDL_Point slot4_1, slot4_2, slot4_3, slot4_4;
|
||||||
|
SDL_Point enterNamePos;
|
||||||
|
|
||||||
// Recalcula las anclas de los elementos
|
// Recalcula las anclas de los elementos
|
||||||
void recalculateAnchors();
|
void recalculateAnchors();
|
||||||
@@ -109,6 +112,12 @@ public:
|
|||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setName(int panel, std::string name);
|
void setName(int panel, std::string name);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setRecordName(int panel, std::string recordName);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setSelectorPos(int panel, int pos);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setScore(int panel, int score);
|
void setScore(int panel, int score);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <stdlib.h> // for free, malloc
|
#include <stdlib.h> // for free, malloc
|
||||||
struct JA_Music_t;
|
struct JA_Music_t;
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
@@ -288,4 +288,22 @@ color_t DarkenColor(color_t color, int amount)
|
|||||||
newColor.g = std::max(0, (int)color.g - amount);
|
newColor.g = std::max(0, (int)color.g - amount);
|
||||||
newColor.b = std::max(0, (int)color.b - amount);
|
newColor.b = std::max(0, (int)color.b - amount);
|
||||||
return newColor;
|
return newColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quita los espacioes en un string
|
||||||
|
std::string trim(const std::string &str)
|
||||||
|
{
|
||||||
|
auto start = str.begin();
|
||||||
|
while (start != str.end() && std::isspace(*start))
|
||||||
|
{
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end = str.end();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
end--;
|
||||||
|
} while (std::distance(start, end) > 0 && std::isspace(*end));
|
||||||
|
|
||||||
|
return std::string(start, end + 1);
|
||||||
}
|
}
|
||||||
@@ -302,6 +302,9 @@ color_t lightenColor(color_t color, int amount);
|
|||||||
// Oscurece el color
|
// Oscurece el color
|
||||||
color_t DarkenColor(color_t color, int amount);
|
color_t DarkenColor(color_t color, int amount);
|
||||||
|
|
||||||
|
// Quita los espacioes en un string
|
||||||
|
std::string trim(const std::string &str);
|
||||||
|
|
||||||
// Colores
|
// Colores
|
||||||
extern const color_t bgColor;
|
extern const color_t bgColor;
|
||||||
extern const color_t noColor;
|
extern const color_t noColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user