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

@@ -2,20 +2,19 @@
#include <algorithm> // for max, min
// Constructor
EnterName::EnterName(std::string *name)
EnterName::EnterName()
{
// Obtiene el puntero al nombre
this->name = name;
name = "";
// Inicia la lista de caracteres permitidos
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+-*/=?¿<>!\"#$%&/()";
pos = 0;
numCharacters = (int)characterList.size();
for (int i = 0; i < NAME_LENGHT; ++i)
{
characterIndex[i] = 0;
}
// Pone la lista de indices para que refleje el nombre
updateCharacterIndex();
}
// Destructor
@@ -45,6 +44,7 @@ void EnterName::incIndex()
{
characterIndex[pos] = 0;
}
updateName();
}
// Decrementa el índice
@@ -55,14 +55,54 @@ void EnterName::decIndex()
{
characterIndex[pos] = numCharacters - 1;
}
updateName();
}
// Actualiza la variable
void EnterName::updateName()
{
name->clear();
name.clear();
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;
}

View File

@@ -17,11 +17,27 @@ class EnterName
{
private:
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 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
// 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
void incPos();
@@ -34,13 +50,9 @@ private:
// Decrementa el índice
void decIndex();
// Actualiza la variable
void updateName();
// Obtiene el nombre
std::string getName();
public:
// Constructor
EnterName(std::string *name);
// Destructor
~EnterName();
// Obtiene la posición que se está editando
int getPos();
};

View File

@@ -16,6 +16,7 @@
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
#include "explosions.h" // for Explosions
#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 "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
@@ -2054,48 +2055,9 @@ void Game::updateMenace()
// Gestiona la entrada durante el juego
void Game::checkInput()
{
// Comprueba si se sale con el teclado
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;
}
// Comprueba si se pulsa el botón de pausa
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
if (input->checkModInput(input_service, input_pause, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
@@ -2275,10 +2237,10 @@ void Game::checkInput()
}
#endif
}
else
else if (player->isContinue())
{
// 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
if (gameOverCounter == GAME_OVER_COUNTER)
@@ -2288,19 +2250,60 @@ void Game::checkInput()
}
// 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 fire2 = input->checkInput(input_fire_center, false, 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 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->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
screen->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
checkGlobalInputs();
}
// 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
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);
manager->add(entry);
delete manager;
@@ -2822,6 +2825,8 @@ void Game::checkPlayersStatusPlaying()
case PLAYER_STATUS_ENTERING_NAME:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME);
scoreboard->setRecordName(player->getScoreBoardPanel(), player->getRecordName());
scoreboard->setSelectorPos(player->getScoreBoardPanel(), player->getRecordNamePos());
break;
case PLAYER_STATUS_DYING:

View File

@@ -4,6 +4,7 @@
#include <stdlib.h> // for rand
#include <algorithm> // for max, min
#include "animated_sprite.h" // for AnimatedSprite
#include "enter_name.h"
#include "input.h" // for inputs_e
#include "param.h" // for param
#include "texture.h" // for Texture
@@ -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)
{

View File

@@ -6,6 +6,7 @@
#include <vector> // for vector
#include "utils.h" // for circle_t
class AnimatedSprite;
class EnterName;
class Texture;
// Estados del jugador
@@ -37,6 +38,7 @@ private:
AnimatedSprite *playerSprite; // Sprite para dibujar el jugador
AnimatedSprite *powerSprite; // Sprite para dibujar el aura del jugador con el poder a tope
SDL_Rect *playArea; // Rectangulo con la zona de juego
EnterName *enterName;
// Variables
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
int scoreBoardPanel; // Panel del marcador asociado al 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
// Actualiza el circulo de colisión a la posición del jugador
@@ -101,6 +104,12 @@ public:
// Actua en consecuencia de la entrada recibida
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
void move();
@@ -242,9 +251,18 @@ public:
// Establece el nombre del jugador
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
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
void setController(int index);

View File

@@ -23,9 +23,11 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
// Inicializa variables
stage = 1;
for (int i = 0; i< SCOREBOARD_MAX_PANELS; ++i)
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
{
name[i] = "";
recordName[i] = "";
selectorPos[i] = 0;
score[i] = 0;
mult[i] = 0;
continueCounter[i] = 0;
@@ -149,6 +151,18 @@ void Scoreboard::setName(int panel, std::string 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
void Scoreboard::setScore(int panel, int score)
{
@@ -274,7 +288,7 @@ void Scoreboard::fillPanelTextures()
// HI-SCORE
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;
case SCOREBOARD_MODE_CONTINUE:
@@ -288,8 +302,36 @@ void Scoreboard::fillPanelTextures()
break;
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;
}
default:
break;
@@ -359,6 +401,11 @@ void Scoreboard::recalculateAnchors()
slot4_3 = {col, row3};
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
if (powerMeterSprite)
{

View File

@@ -54,6 +54,8 @@ private:
// Variables
int stage; // Número de fase actual
std::string name[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
std::string recordName[SCOREBOARD_MAX_PANELS]; // Nombre introducido para la tabla de records
int selectorPos[SCOREBOARD_MAX_PANELS]; // Posición del selector de letra para introducir el nombre
int score[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores
float mult[SCOREBOARD_MAX_PANELS]; // Multiplicador de los jugadores
int continueCounter[SCOREBOARD_MAX_PANELS]; // Tiempo para continuar de los jugadores
@@ -68,6 +70,7 @@ private:
// Puntos predefinidos para colocar elementos en los paneles
SDL_Point slot4_1, slot4_2, slot4_3, slot4_4;
SDL_Point enterNamePos;
// Recalcula las anclas de los elementos
void recalculateAnchors();
@@ -109,6 +112,12 @@ public:
// Establece el valor de la variable
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
void setScore(int panel, int score);

View File

@@ -289,3 +289,21 @@ color_t DarkenColor(color_t color, int amount)
newColor.b = std::max(0, (int)color.b - amount);
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);
}

View File

@@ -302,6 +302,9 @@ color_t lightenColor(color_t color, int amount);
// Oscurece el color
color_t DarkenColor(color_t color, int amount);
// Quita los espacioes en un string
std::string trim(const std::string &str);
// Colores
extern const color_t bgColor;
extern const color_t noColor;