Modificado el fondo de hiscore_table
This commit is contained in:
@@ -49,7 +49,8 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3;
|
|||||||
#define SECTION_PROG_INTRO 1
|
#define SECTION_PROG_INTRO 1
|
||||||
#define SECTION_PROG_TITLE 2
|
#define SECTION_PROG_TITLE 2
|
||||||
#define SECTION_PROG_GAME 3
|
#define SECTION_PROG_GAME 3
|
||||||
#define SECTION_PROG_QUIT 4
|
#define SECTION_PROG_HI_SCORE_TABLE 4
|
||||||
|
#define SECTION_PROG_QUIT 5
|
||||||
|
|
||||||
// Subsecciones
|
// Subsecciones
|
||||||
#define SUBSECTION_GAME_PLAY_1P 0
|
#define SUBSECTION_GAME_PLAY_1P 0
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#include "hiscore_table.h"
|
#include "hiscore_table.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
const Uint8 SELF = 0;
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section)
|
HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section)
|
||||||
{
|
{
|
||||||
@@ -19,25 +17,40 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset,
|
|||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
|
|
||||||
|
// Fuente de texto para escribir
|
||||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight);
|
||||||
|
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
// Crea el objeto para dibujar el fondo
|
||||||
|
background = new Background(renderer, screen, asset, param);
|
||||||
|
background->setSrcDest(windowArea);
|
||||||
|
background->setDstDest(windowArea);
|
||||||
|
background->setCloudsSpeed(-0.5f);
|
||||||
|
background->setGradientNumber(1);
|
||||||
|
background->setTransition(0.8f);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section->name = SELF;
|
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
manualQuit = false;
|
manualQuit = false;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
counterEnd = 600;
|
counterEnd = 600;
|
||||||
|
viewArea = {0, 0, param->gameWidth, param->gameHeight};
|
||||||
|
|
||||||
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
|
fillTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
HiScoreTable::~HiScoreTable()
|
HiScoreTable::~HiScoreTable()
|
||||||
{
|
{
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
delete text;
|
||||||
|
delete eventHandler;
|
||||||
|
delete background;
|
||||||
|
|
||||||
SDL_DestroyTexture(backbuffer);
|
SDL_DestroyTexture(backbuffer);
|
||||||
}
|
}
|
||||||
@@ -57,6 +70,9 @@ void HiScoreTable::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el fondo
|
||||||
|
background->update();
|
||||||
|
|
||||||
if (mode == mhst_auto)
|
if (mode == mhst_auto)
|
||||||
{ // Modo automático
|
{ // Modo automático
|
||||||
counter++;
|
counter++;
|
||||||
@@ -80,20 +96,18 @@ void HiScoreTable::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta en pantalla
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
void HiScoreTable::render()
|
void HiScoreTable::fillTexture()
|
||||||
{
|
{
|
||||||
// Pinta en pantalla
|
|
||||||
SDL_Rect window = {0, 0, param->gameWidth, param->gameHeight};
|
|
||||||
|
|
||||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
||||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
||||||
const int spaceBetweenHeader = 32;
|
const int spaceBetweenHeader = 32;
|
||||||
const int spaceBetweenLines = text->getCharacterSize() * 1.8f;
|
const int spaceBetweenLines = text->getCharacterSize() * 1.8f;
|
||||||
|
|
||||||
// Pinta en el backbuffer el texto y los sprites
|
// Pinta en el backbuffer el texto y los sprites
|
||||||
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||||
SDL_SetRenderTarget(renderer, backbuffer);
|
SDL_SetRenderTarget(renderer, backbuffer);
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Escribe el texto: Mejores puntuaciones
|
// Escribe el texto: Mejores puntuaciones
|
||||||
@@ -122,26 +136,26 @@ void HiScoreTable::render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el destino de renderizado
|
// Cambia el destino de renderizado
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta en pantalla
|
||||||
|
void HiScoreTable::render()
|
||||||
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(bgColor);
|
screen->clean(bgColor);
|
||||||
|
|
||||||
|
// Pinta el fondo
|
||||||
|
background->render();
|
||||||
|
|
||||||
// Establece la ventana del backbuffer
|
// Establece la ventana del backbuffer
|
||||||
if (mode == mhst_auto)
|
viewArea.y = mode == mhst_auto ? std::max(8, param->gameHeight - counter + 100) : 0;
|
||||||
{
|
|
||||||
window.y = std::max(8, param->gameHeight - counter + 100);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
window.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copia el backbuffer al renderizador
|
// Copia el backbuffer al renderizador
|
||||||
SDL_RenderCopy(renderer, backbuffer, nullptr, &window);
|
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
@@ -208,7 +222,7 @@ void HiScoreTable::run(mode_hiScoreTable_e mode)
|
|||||||
{
|
{
|
||||||
this->mode = mode;
|
this->mode = mode;
|
||||||
|
|
||||||
while (section->name == SELF)
|
while (section->name == SECTION_PROG_HI_SCORE_TABLE)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
render();
|
render();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
#include "background.h"
|
||||||
|
|
||||||
#ifndef HISCORE_TABLE_H
|
#ifndef HISCORE_TABLE_H
|
||||||
#define HISCORE_TABLE_H
|
#define HISCORE_TABLE_H
|
||||||
@@ -30,10 +31,12 @@ private:
|
|||||||
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
SDL_Texture *backbuffer; // Textura para usar como backbuffer
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
Input *input; // Objeto pata gestionar la entrada
|
||||||
|
Background *background; // Objeto para dibujar el fondo del juego
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
Text *text; // Objeto para escribir texto
|
Text *text; // Objeto para escribir texto
|
||||||
options_t *options; // Opciones y parametros del programa
|
options_t *options; // Opciones y parametros del programa
|
||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
param_t *param; // Puntero con todos los parametros del programa
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint16 counter; // Contador
|
Uint16 counter; // Contador
|
||||||
@@ -42,7 +45,7 @@ private:
|
|||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
bool manualQuit; // Indica si se quiere salir del modo manual
|
bool manualQuit; // Indica si se quiere salir del modo manual
|
||||||
mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones
|
mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones
|
||||||
param_t *param; // Puntero con todos los parametros del programa
|
SDL_Rect viewArea; // Parte de la textura que se muestra en pantalla
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
@@ -59,6 +62,9 @@ private:
|
|||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
std::string scoreToString(Uint32 num);
|
std::string scoreToString(Uint32 num);
|
||||||
|
|
||||||
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
|
void fillTexture();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section);
|
HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section);
|
||||||
|
|||||||
Reference in New Issue
Block a user