Acomodats els estats del jugador

El compte enrrere per a continuar ara ix al acabar la animació de morir
Afegit el estat "entering_name"
This commit is contained in:
2024-09-29 10:40:35 +02:00
parent 945eaa68e7
commit 8ce09d1355
9 changed files with 193 additions and 68 deletions

View File

@@ -9,7 +9,6 @@
#include <SDL2/SDL_stdinc.h> // for Uint32 #include <SDL2/SDL_stdinc.h> // for Uint32
#include <SDL2/SDL_timer.h> // for SDL_GetTicks #include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <errno.h> // for errno, EACCES, EEXIST, ENAMETOO... #include <errno.h> // for errno, EACCES, EEXIST, ENAMETOO...
#include <pwd.h> // for getpwuid, passwd
#include <stdio.h> // for printf, perror, size_t #include <stdio.h> // for printf, perror, size_t
#include <string.h> // for strcmp #include <string.h> // for strcmp
#include <sys/stat.h> // for stat, mkdir, S_IRWXU #include <sys/stat.h> // for stat, mkdir, S_IRWXU
@@ -34,6 +33,10 @@
#include "title.h" // for Title #include "title.h" // for Title
#include "utils.h" // for music_file_t, sound_file_t, opt... #include "utils.h" // for music_file_t, sound_file_t, opt...
#ifndef _WIN32
#include <pwd.h> // for getpwuid, passwd
#endif
// Constructor // Constructor
Director::Director(int argc, char *argv[]) Director::Director(int argc, char *argv[])
{ {

View File

@@ -4,10 +4,14 @@
// Constructor // Constructor
EnterName::EnterName(std::string *name) EnterName::EnterName(std::string *name)
{ {
characterList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // Obtiene el puntero al nombre
this->name = name; this->name = name;
// Inicia la lista de caracteres permitidos
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
pos = 0; pos = 0;
numCharacters = (int)characterList.size(); numCharacters = (int)characterList.size();
for (int i = 0; i < NAME_LENGHT; ++i) for (int i = 0; i < NAME_LENGHT; ++i)
{ {
characterIndex[i] = 0; characterIndex[i] = 0;
@@ -33,13 +37,32 @@ void EnterName::decPos()
pos = std::max(pos, 0); pos = std::max(pos, 0);
} }
// Incrementa el índice
void EnterName::incIndex()
{
++characterIndex[pos];
if (characterIndex[pos] >= numCharacters)
{
characterIndex[pos] = 0;
}
}
// Decrementa el índice
void EnterName::decIndex()
{
--characterIndex[pos];
if (characterIndex[pos] < 0)
{
characterIndex[pos] = numCharacters - 1;
}
}
// 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->append("a"); name->push_back(characterList[characterIndex[i]]);
//name->append(characterIndex[i] = 0;
} }
} }

View File

@@ -4,6 +4,14 @@
#define NAME_LENGHT 8 #define NAME_LENGHT 8
/*
Un array, "characterList", contiene la lista de caracteres
Un segundo array, "characterIndex", contiene el indice a "characterList" de cada una de las letras que conforman el nombre
"pos" es la posición de "characterIndex" que se está modificando
Izquierda o derecha modifican "pos", arriba o abajo modifican el índice de "characterIndex[pos]"
Pulsar cualquier botón, mueve "pos" a la derecha. Al pulsar el botón en la ´´ultima posición se finaliza la introducción de nombres
*/
// Clase EnterName // Clase EnterName
class EnterName class EnterName
{ {
@@ -20,6 +28,12 @@ private:
// Decrementa la posición // Decrementa la posición
void decPos(); void decPos();
// Incrementa el índice
void incIndex();
// Decrementa el índice
void decIndex();
// Actualiza la variable // Actualiza la variable
void updateName(); void updateName();

View File

@@ -1744,11 +1744,10 @@ void Game::killPlayer(Player *player)
JA_PlaySound(playerCollisionSound); JA_PlaySound(playerCollisionSound);
screen->shake(); screen->shake();
JA_PlaySound(coffeeOutSound); JA_PlaySound(coffeeOutSound);
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(PLAYER_STATUS_CONTINUE); player->setStatusPlaying(PLAYER_STATUS_DYING);
if (!demo.enabled) if (!demo.enabled)
{ // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla { // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla
allPlayersAreWaiting() ? JA_StopMusic() : JA_ResumeMusic(); allPlayersAreNotPlaying() ? JA_StopMusic() : JA_ResumeMusic();
addScoreToScoreBoard(player->getName(), player->getScore());
} }
} }
} }
@@ -2584,6 +2583,18 @@ bool Game::allPlayersAreWaiting()
return success; return success;
} }
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreNotPlaying()
{
bool success = true;
for (auto player : players)
{
success &= !player->isPlaying();
}
return success;
}
// Comprueba los eventos que hay en cola // Comprueba los eventos que hay en cola
void Game::checkEvents() void Game::checkEvents()
{ {
@@ -2809,12 +2820,33 @@ void Game::checkPlayersStatusPlaying()
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER); scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER);
break; break;
case PLAYER_STATUS_ENTERING_NAME:
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME);
break;
case PLAYER_STATUS_DYING:
break;
case PLAYER_STATUS_DIED:
{
const int nextPlayerStatus = IsEligibleForHighScore(player->getScore()) ? PLAYER_STATUS_ENTERING_NAME : PLAYER_STATUS_CONTINUE;
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(nextPlayerStatus);
// addScoreToScoreBoard(player->getName(), player->getScore());
break;
}
default: default:
break; break;
} }
} }
} }
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
bool Game::IsEligibleForHighScore(int score)
{
return score > options.game.hiScoreTable.back().score;
}
// Obtiene un jugador a partir de su "id" // Obtiene un jugador a partir de su "id"
Player *Game::getPlayer(int id) Player *Game::getPlayer(int id)
{ {

View File

@@ -410,6 +410,9 @@ private:
// Comprueba si todos los jugadores han terminado de jugar // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreWaiting(); bool allPlayersAreWaiting();
// Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreNotPlaying();
// Carga las animaciones // Carga las animaciones
void loadAnimations(std::string filePath, std::vector<std::string> *buffer); void loadAnimations(std::string filePath, std::vector<std::string> *buffer);
@@ -434,6 +437,9 @@ private:
// Añade una puntuación a la tabla de records // Añade una puntuación a la tabla de records
void addScoreToScoreBoard(std::string name, int score); void addScoreToScoreBoard(std::string name, int score);
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
bool IsEligibleForHighScore(int score);
// Comprueba el estado de juego de los jugadores // Comprueba el estado de juego de los jugadores
void checkPlayersStatusPlaying(); void checkPlayersStatusPlaying();

View File

@@ -58,7 +58,7 @@ void Player::init()
coffees = 0; coffees = 0;
input = true; input = true;
continueTicks = 0; continueTicks = 0;
continueCounter = 9; continueCounter = 20;
width = 30; width = 30;
height = 30; height = 30;
collider.r = 9; collider.r = 9;
@@ -133,7 +133,7 @@ void Player::move()
powerSprite->setPosX(getPosX() - powerUpDespX); powerSprite->setPosX(getPosX() - powerUpDespX);
} }
else else if (isDying())
{ {
playerSprite->update(); playerSprite->update();
@@ -147,6 +147,12 @@ void Player::move()
// Rebota // Rebota
playerSprite->setVelX(-vx); playerSprite->setVelX(-vx);
} }
// Si el cadaver abandona el area de juego por abajo
if (playerSprite->getPosY() > param.game.playArea.rect.h)
{
setStatusPlaying(PLAYER_STATUS_DIED);
}
} }
} }
@@ -327,6 +333,24 @@ bool Player::isWaiting()
return statusPlaying == PLAYER_STATUS_WAITING; return statusPlaying == PLAYER_STATUS_WAITING;
} }
// Indica si el jugador está introduciendo su nombre
bool Player::isEnteringName()
{
return statusPlaying == PLAYER_STATUS_ENTERING_NAME;
}
// Indica si el jugador está muriendose
bool Player::isDying()
{
return statusPlaying == PLAYER_STATUS_DYING;
}
// Indica si el jugador ha terminado de morir
bool Player::hasDied()
{
return statusPlaying == PLAYER_STATUS_DIED;
}
// Establece el estado del jugador en el juego // Establece el estado del jugador en el juego
void Player::setStatusPlaying(int value) void Player::setStatusPlaying(int value)
{ {
@@ -340,18 +364,25 @@ void Player::setStatusPlaying(int value)
break; break;
case PLAYER_STATUS_CONTINUE: case PLAYER_STATUS_CONTINUE:
// Activa la animación de morir
playerSprite->setAccelY(0.2f);
playerSprite->setVelY(-6.6f);
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
// Inicializa el contador de continuar // Inicializa el contador de continuar
continueTicks = SDL_GetTicks(); continueTicks = SDL_GetTicks();
continueCounter = 9; continueCounter = 9;
break; break;
case PLAYER_STATUS_WAITING: case PLAYER_STATUS_WAITING:
break;
case PLAYER_STATUS_ENTERING_NAME:
break;
case PLAYER_STATUS_DYING:
// Activa la animación de morir
playerSprite->setAccelY(0.2f);
playerSprite->setVelY(-6.6f);
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
break;
case PLAYER_STATUS_DIED:
break; break;
default: default:
@@ -578,7 +609,6 @@ void Player::decContinueCounter()
{ {
continueTicks = SDL_GetTicks(); continueTicks = SDL_GetTicks();
continueCounter--; continueCounter--;
if (continueCounter < 0) if (continueCounter < 0)
{ {
setStatusPlaying(PLAYER_STATUS_WAITING); setStatusPlaying(PLAYER_STATUS_WAITING);

View File

@@ -21,6 +21,9 @@ class Texture;
#define PLAYER_STATUS_PLAYING 0 #define PLAYER_STATUS_PLAYING 0
#define PLAYER_STATUS_CONTINUE 1 #define PLAYER_STATUS_CONTINUE 1
#define PLAYER_STATUS_WAITING 2 #define PLAYER_STATUS_WAITING 2
#define PLAYER_STATUS_ENTERING_NAME 3
#define PLAYER_STATUS_DYING 4
#define PLAYER_STATUS_DIED 5
// Variables del jugador // Variables del jugador
#define PLAYER_INVULNERABLE_COUNTER 200 #define PLAYER_INVULNERABLE_COUNTER 200
@@ -149,6 +152,15 @@ public:
// Indica si el jugador está esperando // Indica si el jugador está esperando
bool isWaiting(); bool isWaiting();
// Indica si el jugador está introduciendo su nombre
bool isEnteringName();
// Indica si el jugador está muriendose
bool isDying();
// Indica si el jugador ha terminado de morir
bool hasDied();
// Establece el estado del jugador en el juego // Establece el estado del jugador en el juego
void setStatusPlaying(int value); void setStatusPlaying(int value);

View File

@@ -287,6 +287,10 @@ void Scoreboard::fillPanelTextures()
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i])); textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i]));
break; break;
case SCOREBOARD_MODE_ENTER_NAME:
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, "ENTER NAME");
break;
default: default:
break; break;
} }

View File

@@ -27,6 +27,7 @@ enum scoreboard_modes_e
SCOREBOARD_MODE_CONTINUE, SCOREBOARD_MODE_CONTINUE,
SCOREBOARD_MODE_GAME_OVER, SCOREBOARD_MODE_GAME_OVER,
SCOREBOARD_MODE_DEMO, SCOREBOARD_MODE_DEMO,
SCOREBOARD_MODE_ENTER_NAME,
SCOREBOARD_MODE_NUM_MODES, SCOREBOARD_MODE_NUM_MODES,
}; };