Compare commits
2 Commits
9886f314b5
...
5e5d7f5f27
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e5d7f5f27 | |||
| 1632441c31 |
@@ -126,9 +126,12 @@ void DefineButtons::checkInput()
|
|||||||
// Habilita el objeto
|
// Habilita el objeto
|
||||||
void DefineButtons::enable(int index)
|
void DefineButtons::enable(int index)
|
||||||
{
|
{
|
||||||
|
if (input->getNumControllers() > 0)
|
||||||
|
{
|
||||||
enabled = true;
|
enabled = true;
|
||||||
indexController = index;
|
indexController = index;
|
||||||
indexButton = 0;
|
indexButton = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si está habilitado
|
// Comprueba si está habilitado
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
if (mode[SCOREBOARD_LEFT_SIDE] == SCOREBOARD_MODE_PLAYING)
|
||||||
|
{ // PLAYER1 - SCORE
|
||||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
||||||
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
|
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)
|
||||||
|
{
|
||||||
|
if (counter % 10 < 8)
|
||||||
|
{
|
||||||
|
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, "Mode");
|
||||||
|
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, "Demo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PARTE DERECHA
|
||||||
|
if (mode[SCOREBOARD_RIGHT_SIDE] == SCOREBOARD_MODE_PLAYING)
|
||||||
|
{ // PLAYER2 - SCORE
|
||||||
textScoreBoard->writeCentered(offsetScoreP2Label.x, offsetScoreP2Label.y, lang->getText(54));
|
textScoreBoard->writeCentered(offsetScoreP2Label.x, offsetScoreP2Label.y, lang->getText(54));
|
||||||
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, updateScoreText(score2));
|
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, updateScoreText(score2));
|
||||||
|
|
||||||
// PLAYER2 - MULT
|
// PLAYER2 - MULT
|
||||||
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, lang->getText(55));
|
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, lang->getText(55));
|
||||||
textScoreBoard->writeCentered(offsetMultP2.x, offsetMultP2.y, std::to_string(mult2).substr(0, 3));
|
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));
|
||||||
@@ -251,3 +297,9 @@ void Scoreboard::recalculateAnchors()
|
|||||||
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;
|
||||||
|
}
|
||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -42,6 +47,9 @@ private:
|
|||||||
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();
|
||||||
|
|
||||||
@@ -107,4 +121,7 @@ public:
|
|||||||
|
|
||||||
// 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);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user