Compare commits

...

2 Commits

4 changed files with 123 additions and 44 deletions

View File

@@ -111,11 +111,11 @@ void DefineButtons::checkInput()
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section->name = SECTION_PROG_QUIT; section->name = SECTION_PROG_QUIT;
break; break;
} }
if (event.type == SDL_CONTROLLERBUTTONDOWN) if (event.type == SDL_CONTROLLERBUTTONDOWN)
doControllerButtonDown(&event.cbutton); doControllerButtonDown(&event.cbutton);
@@ -126,9 +126,12 @@ void DefineButtons::checkInput()
// Habilita el objeto // Habilita el objeto
void DefineButtons::enable(int index) void DefineButtons::enable(int index)
{ {
enabled = true; if (input->getNumControllers() > 0)
indexController = index; {
indexButton = 0; enabled = true;
indexController = index;
indexButton = 0;
}
} }
// Comprueba si está habilitado // Comprueba si está habilitado

View File

@@ -288,7 +288,7 @@ void Game::init(int playerID)
powerBallCounter = 0; powerBallCounter = 0;
coffeeMachineEnabled = false; coffeeMachineEnabled = false;
// Inicializa las variables para el modo demo // Inicializa las variables para el modo DEMO
if (demo.enabled) if (demo.enabled)
{ {
// Selecciona una pantalla al azar // Selecciona una pantalla al azar
@@ -325,6 +325,10 @@ void Game::init(int playerID)
// Deshabilita los sonidos // Deshabilita los sonidos
JA_EnableSound(false); JA_EnableSound(false);
// Configura los marcadores
scoreboard->setMode(SCOREBOARD_LEFT_SIDE, SCOREBOARD_MODE_DEMO);
scoreboard->setMode(SCOREBOARD_RIGHT_SIDE, SCOREBOARD_MODE_DEMO);
} }
initPaths(); initPaths();
@@ -3417,6 +3421,9 @@ void Game::updateScoreboard()
scoreboard->setPower((float)stage[currentStage].currentPower / (float)stage[currentStage].powerToComplete); scoreboard->setPower((float)stage[currentStage].currentPower / (float)stage[currentStage].powerToComplete);
scoreboard->setHiScore(hiScore); scoreboard->setHiScore(hiScore);
scoreboard->setHiScoreName(hiScoreName); scoreboard->setHiScoreName(hiScoreName);
// Lógica del marcador
scoreboard->update();
} }
// Pausa el juego // Pausa el juego

View File

@@ -21,6 +21,10 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
hiScoreName = ""; hiScoreName = "";
color = {0, 0, 0}; color = {0, 0, 0};
rect = {0, 0, 320, 40}; rect = {0, 0, 320, 40};
mode[0] = SCOREBOARD_MODE_PLAYING;
mode[1] = SCOREBOARD_MODE_PLAYING;
ticks = SDL_GetTicks();
counter = 0;
// Recalcula las anclas de los elementos // Recalcula las anclas de los elementos
recalculateAnchors(); recalculateAnchors();
@@ -88,10 +92,26 @@ std::string Scoreboard::updateScoreText(Uint32 num)
return (std::to_string(num)); return (std::to_string(num));
} }
// Actualiza el contador
void Scoreboard::updateCounter()
{
if (SDL_GetTicks() - ticks > SCOREBOARD_TICK_SPEED)
{
ticks = SDL_GetTicks();
counter++;
}
}
// Actualiza la lógica del marcador
void Scoreboard::update()
{
fillBackgroundTexture();
updateCounter();
}
// Pinta el marcador // Pinta el marcador
void Scoreboard::render() void Scoreboard::render()
{ {
fillBackgroundTexture();
SDL_RenderCopy(renderer, background, nullptr, &rect); SDL_RenderCopy(renderer, background, nullptr, &rect);
} }
@@ -182,21 +202,47 @@ void Scoreboard::fillBackgroundTexture()
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255); SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_RenderFillRect(renderer, nullptr); SDL_RenderFillRect(renderer, nullptr);
// PLAYER1 - SCORE // PARTE IZQUIERDA
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53)); if (mode[SCOREBOARD_LEFT_SIDE] == SCOREBOARD_MODE_PLAYING)
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1)); { // PLAYER1 - SCORE
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
// PLAYER1 - MULT // PLAYER1 - MULT
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, lang->getText(55)); textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, lang->getText(55));
textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y, std::to_string(mult1).substr(0, 3)); textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y, std::to_string(mult1).substr(0, 3));
}
// PLAYER2 - SCORE else if (mode[SCOREBOARD_LEFT_SIDE] == SCOREBOARD_MODE_DEMO)
textScoreBoard->writeCentered(offsetScoreP2Label.x, offsetScoreP2Label.y, lang->getText(54)); {
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, updateScoreText(score2)); if (counter % 10 < 8)
{
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, "Mode");
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, "Demo");
}
}
// PLAYER2 - MULT // PARTE DERECHA
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, lang->getText(55)); if (mode[SCOREBOARD_RIGHT_SIDE] == SCOREBOARD_MODE_PLAYING)
textScoreBoard->writeCentered(offsetMultP2.x, offsetMultP2.y, std::to_string(mult2).substr(0, 3)); { // PLAYER2 - SCORE
textScoreBoard->writeCentered(offsetScoreP2Label.x, offsetScoreP2Label.y, lang->getText(54));
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, updateScoreText(score2));
// PLAYER2 - MULT
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, lang->getText(55));
textScoreBoard->writeCentered(offsetMultP2.x, offsetMultP2.y, std::to_string(mult2).substr(0, 3));
}
else if (mode[SCOREBOARD_RIGHT_SIDE] == SCOREBOARD_MODE_DEMO)
{
if (counter % 10 < 8)
{
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, "Mode");
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, "Demo");
}
}
// PARTE CENTRAL
// STAGE // STAGE
textScoreBoard->writeCentered(offsetStage.x, offsetStage.y, lang->getText(57) + std::to_string(stage)); textScoreBoard->writeCentered(offsetStage.x, offsetStage.y, lang->getText(57) + std::to_string(stage));
@@ -250,4 +296,10 @@ void Scoreboard::recalculateAnchors()
offsetMultP1 = {col1, row4}; offsetMultP1 = {col1, row4};
offsetHiScore = {col2, row4}; offsetHiScore = {col2, row4};
offsetMultP2 = {col3, row4}; offsetMultP2 = {col3, row4};
}
// Establece el modo del marcador
void Scoreboard::setMode(int index, scoreboard_modes_e mode)
{
this->mode[index] = mode;
} }

View File

@@ -11,11 +11,16 @@
enum scoreboard_modes_e enum scoreboard_modes_e
{ {
scoreboard_mode_playing, SCOREBOARD_MODE_PLAYING,
scoreboard_mode_game_over, SCOREBOARD_MODE_GAME_OVER,
scoreboard_mode_demo, SCOREBOARD_MODE_DEMO,
}; };
#define SCOREBOARD_LEFT_SIDE 0
#define SCOREBOARD_RIGHT_SIDE 1
#define SCOREBOARD_TICK_SPEED 100
// Clase Scoreboard // Clase Scoreboard
class Scoreboard class Scoreboard
{ {
@@ -31,17 +36,20 @@ private:
SDL_Texture *background; // Textura para dibujar el marcador SDL_Texture *background; // Textura para dibujar el marcador
// Variables // Variables
struct options_t *options; // Variable con todas las variables de las opciones del programa struct options_t *options; // Variable con todas las variables de las opciones del programa
int stage; // Número de fase actual int stage; // Número de fase actual
int score1; // Puntuación del jugador 1 int score1; // Puntuación del jugador 1
int score2; // Puntuación del jugador 2 int score2; // Puntuación del jugador 2
float mult1; // Multiplicador del jugador 1 float mult1; // Multiplicador del jugador 1
float mult2; // MUltiplicador del jugador 2 float mult2; // MUltiplicador del jugador 2
int hiScore; // Mäxima puntuación int hiScore; // Mäxima puntuación
float power; // Poder actual de la fase float power; // Poder actual de la fase
std::string hiScoreName; // Nombre del jugador con la máxima puntuación std::string hiScoreName; // Nombre del jugador con la máxima puntuación
color_t color; // Color del marcador color_t color; // Color del marcador
SDL_Rect rect; // Posición y dimensiones del marcador SDL_Rect rect; // Posición y dimensiones del marcador
scoreboard_modes_e mode[2]; // Modos en los que se puede encontrar el marcador
Uint32 ticks; // Variable donde almacenar el valor de SDL_GetTiks()
int counter; // Contador
SDL_Point offsetScoreP1Label; SDL_Point offsetScoreP1Label;
SDL_Point offsetScoreP1; SDL_Point offsetScoreP1;
@@ -68,6 +76,9 @@ private:
// Rellena la textura de fondo // Rellena la textura de fondo
void fillBackgroundTexture(); void fillBackgroundTexture();
// Actualiza el contador
void updateCounter();
public: public:
// Constructor // Constructor
Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options); Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options);
@@ -75,6 +86,9 @@ public:
// Destructor // Destructor
~Scoreboard(); ~Scoreboard();
// Actualiza la lógica del marcador
void update();
// Pinta el marcador // Pinta el marcador
void render(); void render();
@@ -83,28 +97,31 @@ public:
// Establece el valor de la variable // Establece el valor de la variable
void setScore2(int score); void setScore2(int score);
// Establece el valor de la variable // Establece el valor de la variable
void setMult1(float mult); void setMult1(float mult);
// Establece el valor de la variable // Establece el valor de la variable
void setMult2(float mult); void setMult2(float mult);
// Establece el valor de la variable // Establece el valor de la variable
void setStage(int stage); void setStage(int stage);
// Establece el valor de la variable // Establece el valor de la variable
void setHiScore(int hiScore); void setHiScore(int hiScore);
// Establece el valor de la variable // Establece el valor de la variable
void setPower(float power); void setPower(float power);
// Establece el valor de la variable // Establece el valor de la variable
void setHiScoreName(std::string name); void setHiScoreName(std::string name);
// Establece el valor de la variable // Establece el valor de la variable
void setColor(color_t color); void setColor(color_t color);
// Establece el valor de la variable // Establece el valor de la variable
void setPos(SDL_Rect rect); void setPos(SDL_Rect rect);
// Establece el modo del marcador
void setMode(int index, scoreboard_modes_e mode);
}; };