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:
@@ -9,7 +9,6 @@
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <errno.h> // for errno, EACCES, EEXIST, ENAMETOO...
|
||||
#include <pwd.h> // for getpwuid, passwd
|
||||
#include <stdio.h> // for printf, perror, size_t
|
||||
#include <string.h> // for strcmp
|
||||
#include <sys/stat.h> // for stat, mkdir, S_IRWXU
|
||||
@@ -34,6 +33,10 @@
|
||||
#include "title.h" // for Title
|
||||
#include "utils.h" // for music_file_t, sound_file_t, opt...
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h> // for getpwuid, passwd
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, char *argv[])
|
||||
{
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
// Constructor
|
||||
EnterName::EnterName(std::string *name)
|
||||
{
|
||||
characterList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
// Obtiene el puntero al nombre
|
||||
this->name = name;
|
||||
|
||||
// Inicia la lista de caracteres permitidos
|
||||
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
pos = 0;
|
||||
numCharacters = (int)characterList.size();
|
||||
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
characterIndex[i] = 0;
|
||||
@@ -33,13 +37,32 @@ void EnterName::decPos()
|
||||
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
|
||||
void EnterName::updateName()
|
||||
{
|
||||
name->clear();
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
name->append("a");
|
||||
//name->append(characterIndex[i] = 0;
|
||||
name->push_back(characterList[characterIndex[i]]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,14 @@
|
||||
|
||||
#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
|
||||
class EnterName
|
||||
{
|
||||
@@ -20,6 +28,12 @@ private:
|
||||
// Decrementa la posición
|
||||
void decPos();
|
||||
|
||||
// Incrementa el índice
|
||||
void incIndex();
|
||||
|
||||
// Decrementa el índice
|
||||
void decIndex();
|
||||
|
||||
// Actualiza la variable
|
||||
void updateName();
|
||||
|
||||
|
||||
@@ -1744,11 +1744,10 @@ void Game::killPlayer(Player *player)
|
||||
JA_PlaySound(playerCollisionSound);
|
||||
screen->shake();
|
||||
JA_PlaySound(coffeeOutSound);
|
||||
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(PLAYER_STATUS_CONTINUE);
|
||||
player->setStatusPlaying(PLAYER_STATUS_DYING);
|
||||
if (!demo.enabled)
|
||||
{ // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla
|
||||
allPlayersAreWaiting() ? JA_StopMusic() : JA_ResumeMusic();
|
||||
addScoreToScoreBoard(player->getName(), player->getScore());
|
||||
allPlayersAreNotPlaying() ? JA_StopMusic() : JA_ResumeMusic();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2584,6 +2583,18 @@ bool Game::allPlayersAreWaiting()
|
||||
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
|
||||
void Game::checkEvents()
|
||||
{
|
||||
@@ -2809,12 +2820,33 @@ void Game::checkPlayersStatusPlaying()
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER);
|
||||
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:
|
||||
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"
|
||||
Player *Game::getPlayer(int id)
|
||||
{
|
||||
|
||||
@@ -410,6 +410,9 @@ private:
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
bool allPlayersAreWaiting();
|
||||
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
bool allPlayersAreNotPlaying();
|
||||
|
||||
// Carga las animaciones
|
||||
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
|
||||
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
|
||||
void checkPlayersStatusPlaying();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ void Player::init()
|
||||
coffees = 0;
|
||||
input = true;
|
||||
continueTicks = 0;
|
||||
continueCounter = 9;
|
||||
continueCounter = 20;
|
||||
width = 30;
|
||||
height = 30;
|
||||
collider.r = 9;
|
||||
@@ -133,7 +133,7 @@ void Player::move()
|
||||
|
||||
powerSprite->setPosX(getPosX() - powerUpDespX);
|
||||
}
|
||||
else
|
||||
else if (isDying())
|
||||
{
|
||||
playerSprite->update();
|
||||
|
||||
@@ -147,6 +147,12 @@ void Player::move()
|
||||
// Rebota
|
||||
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;
|
||||
}
|
||||
|
||||
// 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
|
||||
void Player::setStatusPlaying(int value)
|
||||
{
|
||||
@@ -340,18 +364,25 @@ void Player::setStatusPlaying(int value)
|
||||
break;
|
||||
|
||||
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
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter = 9;
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
@@ -578,7 +609,6 @@ void Player::decContinueCounter()
|
||||
{
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter--;
|
||||
|
||||
if (continueCounter < 0)
|
||||
{
|
||||
setStatusPlaying(PLAYER_STATUS_WAITING);
|
||||
|
||||
@@ -21,6 +21,9 @@ class Texture;
|
||||
#define PLAYER_STATUS_PLAYING 0
|
||||
#define PLAYER_STATUS_CONTINUE 1
|
||||
#define PLAYER_STATUS_WAITING 2
|
||||
#define PLAYER_STATUS_ENTERING_NAME 3
|
||||
#define PLAYER_STATUS_DYING 4
|
||||
#define PLAYER_STATUS_DIED 5
|
||||
|
||||
// Variables del jugador
|
||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||
@@ -149,6 +152,15 @@ public:
|
||||
// Indica si el jugador está esperando
|
||||
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
|
||||
void setStatusPlaying(int value);
|
||||
|
||||
|
||||
@@ -287,6 +287,10 @@ void Scoreboard::fillPanelTextures()
|
||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i]));
|
||||
break;
|
||||
|
||||
case SCOREBOARD_MODE_ENTER_NAME:
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, "ENTER NAME");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ enum scoreboard_modes_e
|
||||
SCOREBOARD_MODE_CONTINUE,
|
||||
SCOREBOARD_MODE_GAME_OVER,
|
||||
SCOREBOARD_MODE_DEMO,
|
||||
SCOREBOARD_MODE_ENTER_NAME,
|
||||
SCOREBOARD_MODE_NUM_MODES,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user