Compare commits

...

3 Commits

8 changed files with 98 additions and 87 deletions

View File

@@ -12,9 +12,9 @@ venetianSize 16
#SCOREBOARD
scoreboard.x 0
scoreboard.y 208
scoreboard.y 200
scoreboard.w 320
scoreboard.h 32
scoreboard.h 40
#TITLE
pressStart 160

View File

@@ -14,15 +14,9 @@
#define WIDTH 320
#define HEIGHT 240
// Marcador
const int SCOREBOARD_WIDTH = WIDTH;
const int SCOREBOARD_HEIGHT = 32;
const int SCOREBOARD_X = 0;
const int SCOREBOARD_Y = HEIGHT - SCOREBOARD_HEIGHT;
// Zona de juego
const SDL_Rect windowArea = {0, 0, WIDTH, HEIGHT};
const SDL_Rect playArea = {0, 0, WIDTH, HEIGHT - SCOREBOARD_HEIGHT};
const SDL_Rect playArea = {0, 0, WIDTH, 200};
const int PLAY_AREA_TOP = 0;
const int PLAY_AREA_BOTTOM = playArea.h;
const int PLAY_AREA_LEFT = 0;

View File

@@ -1,7 +1,7 @@
#include "define_buttons.h"
// Constructor
DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options)
DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options, section_t *section)
{
// Copia punteros a los objetos
this->renderer = renderer;
@@ -9,6 +9,7 @@ DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, p
this->text = text;
this->param = param;
this->options = options;
this->section = section;
// Inicializa variables
enabled = false;
@@ -109,6 +110,13 @@ void DefineButtons::checkInput()
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(&event))
{
// Evento de salida de la aplicación
if (event.type == SDL_QUIT)
{
section->name = SECTION_PROG_QUIT;
break;
}
if (event.type == SDL_CONTROLLERBUTTONDOWN)
doControllerButtonDown(&event.cbutton);
}
@@ -143,7 +151,7 @@ void DefineButtons::incIndexButton()
// Guarda los cambios en las opciones
saveBindingsToOptions();
//input->allActive(indexController);
input->allActive(indexController);
// Reinicia variables
indexButton = 0;

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL.h>
#include "common/input.h"
#include "common/text.h"
#include "const.h"
#ifndef DEFINE_BUTTONS_H
#define DEFINE_BUTTONS_H
@@ -26,6 +27,7 @@ private:
// Variables
options_t *options; // Variable con todas las variables de las opciones del programa
param_t *param; // Puntero con todos los parametros del programa
section_t *section; // Indicador para el bucle del titulo
bool enabled; // Indica si el objeto está habilitado
int x; // Posición donde dibujar el texto
int y; // Posición donde dibujar el texto
@@ -48,7 +50,7 @@ private:
public:
// Constructor
DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options);
DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, param_t *param, options_t *options, section_t *section);
// Destructor
~DefineButtons();

View File

@@ -2532,14 +2532,17 @@ void Game::update()
counter++;
// Incrementa el contador de la demo
if (demo.counter < TOTAL_DEMO_DATA)
if (demo.enabled)
{
demo.counter++;
}
else
{
section->name = SECTION_PROG_HI_SCORE_TABLE;
return;
if (demo.counter < TOTAL_DEMO_DATA)
{
demo.counter++;
}
else
{
section->name = SECTION_PROG_HI_SCORE_TABLE;
return;
}
}
#ifdef RECORDING
@@ -2653,7 +2656,7 @@ void Game::renderSeparator()
{
// Dibuja la linea que separa el marcador de la zona de juego
SDL_SetRenderDrawColor(renderer, separator.r, separator.g, separator.b, 255);
SDL_RenderDrawLine(renderer, SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_X + SCOREBOARD_WIDTH, SCOREBOARD_Y);
SDL_RenderDrawLine(renderer, param->scoreboard.x, param->scoreboard.y, param->scoreboard.x + param->scoreboard.w, param->scoreboard.y);
}
// Dibuja los elementos de la zona de juego en su textura

View File

@@ -20,32 +20,10 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
power = 0;
hiScoreName = "";
color = {0, 0, 0};
rect = {0, 0, 256, 32};
rect = {0, 0, 320, 40};
const int left = 45;
const int right = rect.w - left;
const int center = rect.w / 2;
const int desp = 7;
const int line1 = 2;
const int line2 = line1 + desp;
const int line3 = line2 + desp;
const int line4 = line3 + desp;
offsetScoreP1Label = {left, line1};
offsetScoreP1 = {left, line2};
offsetScoreP2Label = {right, line1};
offsetScoreP2 = {right, line2};
offsetHiScoreLabel = {center, line3};
offsetHiScore = {center, line4};
offsetMultP1Label = {left, line3};
offsetMultP1 = {left, line4};
offsetMultP2Label = {right, line3};
offsetMultP2 = {right, line4};
offsetStage = {center, line1};
offsetPowerMeter = {center, line2};
// Recalcula las anclas de los elementos
recalculateAnchors();
// Crea objetos
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
@@ -167,30 +145,8 @@ void Scoreboard::setPos(SDL_Rect rect)
{
this->rect = rect;
const int left = rect.w / 6;
const int right = rect.w - left;
const int center = rect.w / 2;
const int desp = 7;
const int line1 = 2;
const int line2 = line1 + desp;
const int line3 = line2 + desp;
const int line4 = line3 + desp;
offsetScoreP1Label = {left, line1};
offsetScoreP1 = {left, line2};
offsetScoreP2Label = {right, line1};
offsetScoreP2 = {right, line2};
offsetHiScoreLabel = {center, line3};
offsetHiScore = {center, line4};
offsetMultP1Label = {left, line3};
offsetMultP1 = {left, line4};
offsetMultP2Label = {right, line3};
offsetMultP2 = {right, line4};
offsetStage = {center, line1};
offsetPowerMeter = {center, line2};
// Recalcula las anclas de los elementos
recalculateAnchors();
powerMeterSprite->setPosX(offsetPowerMeter.x - 20);
powerMeterSprite->setPosY(offsetPowerMeter.y);
@@ -247,4 +203,41 @@ void Scoreboard::fillBackgroundTexture()
// Deja el renderizador apuntando donde estaba
SDL_SetRenderTarget(renderer, temp);
}
// Recalcula las anclas de los elementos
void Scoreboard::recalculateAnchors()
{
// Constantes para definir las zonas del marcador: 4 filas y 3 columnas
const int rowSize = rect.h / 4;
const int textHeight = 7;
const int row1 = (rowSize * 0) + (textHeight / 2);
const int row2 = (rowSize * 1) + (textHeight / 2) - 1;
const int row3 = (rowSize * 2) + (textHeight / 2) - 2;
const int row4 = (rowSize * 3) + (textHeight / 2) - 3;
const int halfColSize = rect.w / 6;
const int col1 = halfColSize;
const int col2 = halfColSize * 3;
const int col3 = halfColSize * 5;
// Primera fila
offsetScoreP1Label = {col1, row1};
offsetStage = {col2, row1};
offsetScoreP2Label = {col3, row1};
// Segunda fila
offsetScoreP1 = {col1, row2};
offsetPowerMeter = {col2, row2};
offsetScoreP2 = {col3, row2};
// Tercera fila
offsetMultP1Label = {col1, row3};
offsetHiScoreLabel = {col2, row3};
offsetMultP2Label = {col3, row3};
// Cuarta fila
offsetMultP1 = {col1, row4};
offsetHiScore = {col2, row4};
offsetMultP2 = {col3, row4};
}

View File

@@ -43,7 +43,7 @@ private:
SDL_Point offsetScoreP1;
SDL_Point offsetScoreP2Label;
SDL_Point offsetScoreP2;
SDL_Point offsetMultP1Label;
SDL_Point offsetMultP1;
SDL_Point offsetMultP2Label;
@@ -55,6 +55,15 @@ private:
SDL_Point offsetStage;
SDL_Point offsetPowerMeter;
// Recalcula las anclas de los elementos
void recalculateAnchors();
// Transforma un valor numérico en una cadena de 6 cifras
std::string updateScoreText(Uint32 num);
// Rellena la textura de fondo
void fillBackgroundTexture();
public:
// Constructor
Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options);
@@ -75,13 +84,6 @@ public:
void setHiScoreName(std::string name);
void setColor(color_t color);
void setPos(SDL_Rect rect);
private:
// Transforma un valor numérico en una cadena de 6 cifras
std::string updateScoreText(Uint32 num);
// Rellena la textura de fondo
void fillBackgroundTexture();
};
#endif

View File

@@ -36,7 +36,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
gameLogo = new GameLogo(renderer, screen, asset, param, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20);
gameLogo->enable();
defineButtons = new DefineButtons(renderer, input, text2, param, options);
defineButtons = new DefineButtons(renderer, input, text2, param, options, section);
// Inicializa los valores
init();
@@ -220,10 +220,22 @@ void Title::checkEvents()
break;
}
// Recarga las texturas
else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
{
reLoadTextures();
}
// Comprueba en el primer mando el botón de salir del programa
else if (eventHandler->type == SDL_CONTROLLERBUTTONDOWN)
{
if ((SDL_GameControllerButton)eventHandler->cbutton.which == 0)
if ((SDL_GameControllerButton)eventHandler->cbutton.button == input->getControllerBinding(0, input_exit))
{
section->name = SECTION_PROG_QUIT;
break;
}
}
}
}
}
@@ -241,17 +253,14 @@ void Title::checkInput()
fade->activate();
postFade = index;
}
}
// Comprueba el teclado para salir
if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT))
{
section->name = SECTION_PROG_QUIT;
}
// Comprueba el teclado para salir
if (input->checkInput(input_exit, DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
section->name = SECTION_PROG_QUIT;
}
// Comprueba si se ha pulsado la tecla 1 o 2 para definir los controladores
if (!defineButtons->isEnabled())
{
// Comprueba si se ha pulsado la tecla 1 o 2 para definir los controladores
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
if (keyStates[SDL_SCANCODE_1] != 0)