Commitet pa gastar el Cppcheck
This commit is contained in:
@@ -117,11 +117,11 @@ Director::~Director()
|
|||||||
|
|
||||||
Asset::destroy();
|
Asset::destroy();
|
||||||
Input::destroy();
|
Input::destroy();
|
||||||
//Screen::destroy();
|
Screen::destroy();
|
||||||
OnScreenHelp::destroy();
|
OnScreenHelp::destroy();
|
||||||
|
|
||||||
deleteSounds();
|
sounds.clear();
|
||||||
deleteMusics();
|
musics.clear();
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
@@ -593,30 +593,10 @@ void Director::loadMusics()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera la memoria usada por los sonidos del juego
|
|
||||||
void Director::deleteSounds()
|
|
||||||
{
|
|
||||||
for (auto s : sounds)
|
|
||||||
{
|
|
||||||
JA_DeleteSound(s.file);
|
|
||||||
}
|
|
||||||
sounds.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Libera la memoria usada por las músicas del juego
|
|
||||||
void Director::deleteMusics()
|
|
||||||
{
|
|
||||||
for (auto m : musics)
|
|
||||||
{
|
|
||||||
JA_DeleteMusic(m.file);
|
|
||||||
}
|
|
||||||
musics.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ejecuta la sección con el logo
|
// Ejecuta la sección con el logo
|
||||||
void Director::runLogo()
|
void Director::runLogo()
|
||||||
{
|
{
|
||||||
Logo *logo = new Logo();
|
auto *logo = new Logo();
|
||||||
logo->run();
|
logo->run();
|
||||||
delete logo;
|
delete logo;
|
||||||
}
|
}
|
||||||
@@ -624,7 +604,7 @@ void Director::runLogo()
|
|||||||
// Ejecuta la sección con la secuencia de introducción
|
// Ejecuta la sección con la secuencia de introducción
|
||||||
void Director::runIntro()
|
void Director::runIntro()
|
||||||
{
|
{
|
||||||
Intro *intro = new Intro(getMusic(musics, "intro.ogg"));
|
auto *intro = new Intro(getMusic(musics, "intro.ogg"));
|
||||||
intro->run();
|
intro->run();
|
||||||
delete intro;
|
delete intro;
|
||||||
}
|
}
|
||||||
@@ -632,7 +612,7 @@ void Director::runIntro()
|
|||||||
// Ejecuta la sección con el titulo del juego
|
// Ejecuta la sección con el titulo del juego
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
Title *title = new Title(getMusic(musics, "title.ogg"));
|
auto *title = new Title(getMusic(musics, "title.ogg"));
|
||||||
title->run();
|
title->run();
|
||||||
delete title;
|
delete title;
|
||||||
}
|
}
|
||||||
@@ -640,9 +620,9 @@ void Director::runTitle()
|
|||||||
// Ejecuta la sección donde se juega al juego
|
// Ejecuta la sección donde se juega al juego
|
||||||
void Director::runGame()
|
void Director::runGame()
|
||||||
{
|
{
|
||||||
const int playerID = section::options == section::OPTIONS_GAME_PLAY_1P ? 1 : 2;
|
const auto playerID = section::options == section::OPTIONS_GAME_PLAY_1P ? 1 : 2;
|
||||||
const int currentStage = 0;
|
constexpr auto currentStage = 0;
|
||||||
Game *game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics, "playing.ogg"));
|
auto *game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics, "playing.ogg"));
|
||||||
game->run();
|
game->run();
|
||||||
delete game;
|
delete game;
|
||||||
}
|
}
|
||||||
@@ -650,7 +630,7 @@ void Director::runGame()
|
|||||||
// Ejecuta la sección donde se muestran las instrucciones
|
// Ejecuta la sección donde se muestran las instrucciones
|
||||||
void Director::runInstructions()
|
void Director::runInstructions()
|
||||||
{
|
{
|
||||||
Instructions *instructions = new Instructions(getMusic(musics, "title.ogg"));
|
auto *instructions = new Instructions(getMusic(musics, "title.ogg"));
|
||||||
instructions->run();
|
instructions->run();
|
||||||
delete instructions;
|
delete instructions;
|
||||||
}
|
}
|
||||||
@@ -658,7 +638,7 @@ void Director::runInstructions()
|
|||||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||||
void Director::runHiScoreTable()
|
void Director::runHiScoreTable()
|
||||||
{
|
{
|
||||||
HiScoreTable *hiScoreTable = new HiScoreTable(getMusic(musics, "title.ogg"));
|
auto *hiScoreTable = new HiScoreTable(getMusic(musics, "title.ogg"));
|
||||||
hiScoreTable->run();
|
hiScoreTable->run();
|
||||||
delete hiScoreTable;
|
delete hiScoreTable;
|
||||||
}
|
}
|
||||||
@@ -666,9 +646,9 @@ void Director::runHiScoreTable()
|
|||||||
// Ejecuta el juego en modo demo
|
// Ejecuta el juego en modo demo
|
||||||
void Director::runDemoGame()
|
void Director::runDemoGame()
|
||||||
{
|
{
|
||||||
const int playerID = (rand() % 2) + 1;
|
const auto playerID = (rand() % 2) + 1;
|
||||||
const int currentStage = 0;
|
constexpr auto currentStage = 0;
|
||||||
Game *game = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, nullptr);
|
auto *game = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, nullptr);
|
||||||
game->run();
|
game->run();
|
||||||
delete game;
|
delete game;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,12 +45,6 @@ private:
|
|||||||
// Carga las musicas del juego
|
// Carga las musicas del juego
|
||||||
void loadMusics();
|
void loadMusics();
|
||||||
|
|
||||||
// Libera la memoria usada por los sonidos del juego
|
|
||||||
void deleteSounds();
|
|
||||||
|
|
||||||
// Libera la memoria usada por las músicas del juego
|
|
||||||
void deleteMusics();
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void checkProgramArguments(int argc, char *argv[]);
|
void checkProgramArguments(int argc, char *argv[]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +1,36 @@
|
|||||||
#include "game_logo.h"
|
#include "game_logo.h"
|
||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
#include <string> // for basic_string
|
#include <string> // for basic_string
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "animated_sprite.h" // for AnimatedSprite
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_PlaySound
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "smart_sprite.h" // for SmartSprite
|
#include "smart_sprite.h" // for SmartSprite
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "utils.h" // for param_t, paramGame_t, paramTitle_t
|
#include "utils.h" // for param_t, paramGame_t, paramTitle_t
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameLogo::GameLogo(int x, int y)
|
GameLogo::GameLogo(int x, int y)
|
||||||
|
: x(x), y(y)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
screen = Screen::get();
|
|
||||||
renderer = screen->getRenderer();
|
|
||||||
asset = Asset::get();
|
|
||||||
this->x = x;
|
|
||||||
this->y = y;
|
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
dustTexture = new Texture(renderer, asset->get("title_dust.png"));
|
dustTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"));
|
||||||
coffeeTexture = new Texture(renderer, asset->get("title_coffee.png"));
|
coffeeTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"));
|
||||||
crisisTexture = new Texture(renderer, asset->get("title_crisis.png"));
|
crisisTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"));
|
||||||
arcadeEditionTexture = new Texture(renderer, asset->get("title_arcade_edition.png"));
|
arcadeEditionTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"));
|
||||||
|
|
||||||
coffeeBitmap = new SmartSprite(coffeeTexture);
|
coffeeSprite = std::make_unique<SmartSprite>(coffeeTexture.get());
|
||||||
crisisBitmap = new SmartSprite(crisisTexture);
|
crisisSprite = std::make_unique<SmartSprite>(crisisTexture.get());
|
||||||
arcadeEditionBitmap = new Sprite((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture);
|
|
||||||
dustBitmapL = new AnimatedSprite(dustTexture, asset->get("title_dust.ani"));
|
arcadeEditionSprite = std::make_unique<Sprite>((param.game.width - arcadeEditionTexture->getWidth()) / 2, param.title.arcadeEditionPosition, arcadeEditionTexture->getWidth(), arcadeEditionTexture->getHeight(), arcadeEditionTexture.get());
|
||||||
dustBitmapR = new AnimatedSprite(dustTexture, asset->get("title_dust.ani"));
|
|
||||||
|
dustLSprite = std::make_unique<AnimatedSprite>(dustTexture.get(), Asset::get()->get("title_dust.ani"));
|
||||||
|
dustRSprite = std::make_unique<AnimatedSprite>(dustTexture.get(), Asset::get()->get("title_dust.ani"));
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
crashSound = JA_LoadSound(asset->get("title.wav").c_str());
|
crashSound = JA_LoadSound(Asset::get()->get("title.wav").c_str());
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
init();
|
init();
|
||||||
@@ -43,28 +39,17 @@ GameLogo::GameLogo(int x, int y)
|
|||||||
// Destructor
|
// Destructor
|
||||||
GameLogo::~GameLogo()
|
GameLogo::~GameLogo()
|
||||||
{
|
{
|
||||||
delete dustTexture;
|
|
||||||
delete coffeeTexture;
|
|
||||||
delete crisisTexture;
|
|
||||||
delete arcadeEditionTexture;
|
|
||||||
|
|
||||||
delete coffeeBitmap;
|
|
||||||
delete crisisBitmap;
|
|
||||||
delete arcadeEditionBitmap;
|
|
||||||
delete dustBitmapL;
|
|
||||||
delete dustBitmapR;
|
|
||||||
|
|
||||||
JA_DeleteSound(crashSound);
|
JA_DeleteSound(crashSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
void GameLogo::init()
|
void GameLogo::init()
|
||||||
{
|
{
|
||||||
const int xp = x - coffeeBitmap->getWidth() / 2;
|
const auto xp = x - coffeeSprite->getWidth() / 2;
|
||||||
const int desp = getInitialVerticalDesp();
|
const auto desp = getInitialVerticalDesp();
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
status = disabled;
|
status = Status::DISABLED;
|
||||||
shake.desp = 1;
|
shake.desp = 1;
|
||||||
shake.delay = 2;
|
shake.delay = 2;
|
||||||
shake.lenght = 8;
|
shake.lenght = 8;
|
||||||
@@ -73,90 +58,89 @@ void GameLogo::init()
|
|||||||
shake.origin = xp;
|
shake.origin = xp;
|
||||||
|
|
||||||
// Inicializa el bitmap de 'Coffee'
|
// Inicializa el bitmap de 'Coffee'
|
||||||
coffeeBitmap->init();
|
coffeeSprite->init();
|
||||||
coffeeBitmap->setPosX(xp);
|
coffeeSprite->setPosX(xp);
|
||||||
coffeeBitmap->setPosY(y - coffeeTexture->getHeight() - desp);
|
coffeeSprite->setPosY(y - coffeeTexture->getHeight() - desp);
|
||||||
coffeeBitmap->setWidth(coffeeTexture->getWidth());
|
coffeeSprite->setWidth(coffeeTexture->getWidth());
|
||||||
coffeeBitmap->setHeight(coffeeTexture->getHeight());
|
coffeeSprite->setHeight(coffeeTexture->getHeight());
|
||||||
coffeeBitmap->setVelX(0.0f);
|
coffeeSprite->setVelX(0.0f);
|
||||||
coffeeBitmap->setVelY(2.5f);
|
coffeeSprite->setVelY(2.5f);
|
||||||
coffeeBitmap->setAccelX(0.0f);
|
coffeeSprite->setAccelX(0.0f);
|
||||||
coffeeBitmap->setAccelY(0.1f);
|
coffeeSprite->setAccelY(0.1f);
|
||||||
coffeeBitmap->setSpriteClip(0, 0, coffeeTexture->getWidth(), coffeeTexture->getHeight());
|
coffeeSprite->setSpriteClip(0, 0, coffeeTexture->getWidth(), coffeeTexture->getHeight());
|
||||||
coffeeBitmap->setEnabled(true);
|
coffeeSprite->setEnabled(true);
|
||||||
coffeeBitmap->setEnabledCounter(0);
|
coffeeSprite->setEnabledCounter(0);
|
||||||
coffeeBitmap->setDestX(xp);
|
coffeeSprite->setDestX(xp);
|
||||||
coffeeBitmap->setDestY(y - coffeeTexture->getHeight());
|
coffeeSprite->setDestY(y - coffeeTexture->getHeight());
|
||||||
|
|
||||||
// Inicializa el bitmap de 'Crisis'
|
// Inicializa el bitmap de 'Crisis'
|
||||||
crisisBitmap->init();
|
crisisSprite->init();
|
||||||
crisisBitmap->setPosX(xp + 15);
|
crisisSprite->setPosX(xp + 15);
|
||||||
crisisBitmap->setPosY(y + desp);
|
crisisSprite->setPosY(y + desp);
|
||||||
crisisBitmap->setWidth(crisisTexture->getWidth());
|
crisisSprite->setWidth(crisisTexture->getWidth());
|
||||||
crisisBitmap->setHeight(crisisTexture->getHeight());
|
crisisSprite->setHeight(crisisTexture->getHeight());
|
||||||
crisisBitmap->setVelX(0.0f);
|
crisisSprite->setVelX(0.0f);
|
||||||
crisisBitmap->setVelY(-2.5f);
|
crisisSprite->setVelY(-2.5f);
|
||||||
crisisBitmap->setAccelX(0.0f);
|
crisisSprite->setAccelX(0.0f);
|
||||||
crisisBitmap->setAccelY(-0.1f);
|
crisisSprite->setAccelY(-0.1f);
|
||||||
crisisBitmap->setSpriteClip(0, 0, crisisTexture->getWidth(), crisisTexture->getHeight());
|
crisisSprite->setSpriteClip(0, 0, crisisTexture->getWidth(), crisisTexture->getHeight());
|
||||||
crisisBitmap->setEnabled(true);
|
crisisSprite->setEnabled(true);
|
||||||
crisisBitmap->setEnabledCounter(0);
|
crisisSprite->setEnabledCounter(0);
|
||||||
crisisBitmap->setDestX(xp + 15);
|
crisisSprite->setDestX(xp + 15);
|
||||||
crisisBitmap->setDestY(y);
|
crisisSprite->setDestY(y);
|
||||||
|
|
||||||
// Inicializa el bitmap de 'DustRight'
|
// Inicializa el bitmap de 'DustRight'
|
||||||
dustBitmapR->resetAnimation();
|
dustRSprite->resetAnimation();
|
||||||
dustBitmapR->setPosX(coffeeBitmap->getPosX() + coffeeBitmap->getWidth());
|
dustRSprite->setPosX(coffeeSprite->getPosX() + coffeeSprite->getWidth());
|
||||||
dustBitmapR->setPosY(y);
|
dustRSprite->setPosY(y);
|
||||||
dustBitmapR->setWidth(16);
|
dustRSprite->setWidth(16);
|
||||||
dustBitmapR->setHeight(16);
|
dustRSprite->setHeight(16);
|
||||||
dustBitmapR->setFlip(SDL_FLIP_HORIZONTAL);
|
dustRSprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||||
|
|
||||||
// Inicializa el bitmap de 'DustLeft'
|
// Inicializa el bitmap de 'DustLeft'
|
||||||
dustBitmapL->resetAnimation();
|
dustLSprite->resetAnimation();
|
||||||
dustBitmapL->setPosX(coffeeBitmap->getPosX() - 16);
|
dustLSprite->setPosX(coffeeSprite->getPosX() - 16);
|
||||||
dustBitmapL->setPosY(y);
|
dustLSprite->setPosY(y);
|
||||||
dustBitmapL->setWidth(16);
|
dustLSprite->setWidth(16);
|
||||||
dustBitmapL->setHeight(16);
|
dustLSprite->setHeight(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta la clase en pantalla
|
// Pinta la clase en pantalla
|
||||||
void GameLogo::render()
|
void GameLogo::render()
|
||||||
{
|
{
|
||||||
// Dibuja el logo
|
// Dibuja el logo
|
||||||
coffeeBitmap->render();
|
coffeeSprite->render();
|
||||||
crisisBitmap->render();
|
crisisSprite->render();
|
||||||
|
|
||||||
if (status == finished)
|
if (status == Status::FINISHED)
|
||||||
arcadeEditionBitmap->render();
|
{
|
||||||
|
arcadeEditionSprite->render();
|
||||||
|
}
|
||||||
|
|
||||||
// Dibuja el polvillo del logo
|
// Dibuja el polvillo del logo
|
||||||
dustBitmapR->render();
|
dustRSprite->render();
|
||||||
dustBitmapL->render();
|
dustLSprite->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la lógica de la clase
|
// Actualiza la lógica de la clase
|
||||||
void GameLogo::update()
|
void GameLogo::update()
|
||||||
{
|
{
|
||||||
if (status == moving)
|
if (status == Status::MOVING)
|
||||||
{
|
{
|
||||||
coffeeBitmap->update();
|
coffeeSprite->update();
|
||||||
crisisBitmap->update();
|
crisisSprite->update();
|
||||||
|
|
||||||
// Si los objetos han llegado a su destino, cambiamos de Sección
|
// Si los objetos han llegado a su destino, cambiamos de Sección
|
||||||
if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished())
|
if (coffeeSprite->hasFinished() && crisisSprite->hasFinished())
|
||||||
{
|
{
|
||||||
status = shaking;
|
status = Status::SHAKING;
|
||||||
|
|
||||||
// Pantallazo blanco
|
|
||||||
//screen->flash(flashColor, 10);
|
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(crashSound);
|
JA_PlaySound(crashSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (status == shaking)
|
else if (status == Status::SHAKING)
|
||||||
{
|
{
|
||||||
// Agita el logo
|
// Agita el logo
|
||||||
if (shake.remaining > 0)
|
if (shake.remaining > 0)
|
||||||
@@ -168,27 +152,27 @@ void GameLogo::update()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
shake.counter = shake.delay;
|
shake.counter = shake.delay;
|
||||||
const int desp = shake.remaining % 2 == 0 ? shake.desp * (-1) : shake.desp;
|
const auto desp = shake.remaining % 2 == 0 ? shake.desp * (-1) : shake.desp;
|
||||||
coffeeBitmap->setPosX(shake.origin + desp);
|
coffeeSprite->setPosX(shake.origin + desp);
|
||||||
crisisBitmap->setPosX(shake.origin + desp + 15);
|
crisisSprite->setPosX(shake.origin + desp + 15);
|
||||||
shake.remaining--;
|
shake.remaining--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
coffeeBitmap->setPosX(shake.origin);
|
coffeeSprite->setPosX(shake.origin);
|
||||||
crisisBitmap->setPosX(shake.origin + 15);
|
crisisSprite->setPosX(shake.origin + 15);
|
||||||
status = finished;
|
status = Status::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
dustBitmapR->update();
|
dustRSprite->update();
|
||||||
dustBitmapL->update();
|
dustLSprite->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (status == finished)
|
else if (status == Status::FINISHED)
|
||||||
{
|
{
|
||||||
dustBitmapR->update();
|
dustRSprite->update();
|
||||||
dustBitmapL->update();
|
dustLSprite->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,13 +180,13 @@ void GameLogo::update()
|
|||||||
void GameLogo::enable()
|
void GameLogo::enable()
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
status = moving;
|
status = Status::MOVING;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si ha terminado la animación
|
// Indica si ha terminado la animación
|
||||||
bool GameLogo::hasFinished()
|
bool GameLogo::hasFinished() const
|
||||||
{
|
{
|
||||||
return (status == finished);
|
return status == Status::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
// Recarga las texturas
|
||||||
@@ -216,8 +200,8 @@ void GameLogo::reLoad()
|
|||||||
// Calcula el desplazamiento vertical inicial
|
// Calcula el desplazamiento vertical inicial
|
||||||
int GameLogo::getInitialVerticalDesp()
|
int GameLogo::getInitialVerticalDesp()
|
||||||
{
|
{
|
||||||
int despUp = y;
|
auto despUp = y;
|
||||||
int despDown = param.game.height - y;
|
auto despDown = param.game.height - y;
|
||||||
|
|
||||||
return std::max(despUp, despDown);
|
return std::max(despUp, despDown);
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
class AnimatedSprite;
|
#include <memory>
|
||||||
class Asset;
|
|
||||||
class Screen;
|
#include "texture.h"
|
||||||
class SmartSprite;
|
#include "animated_sprite.h"
|
||||||
class Sprite;
|
#include "smart_sprite.h"
|
||||||
class Texture;
|
#include "sprite.h"
|
||||||
|
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
// Clase GameLogo
|
// Clase GameLogo
|
||||||
@@ -14,22 +15,18 @@ class GameLogo
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
std::unique_ptr<Texture> dustTexture; // Textura con los graficos del polvo
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
std::unique_ptr<Texture> coffeeTexture; // Textura con los graficos de la palabra "COFFEE"
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
std::unique_ptr<Texture> crisisTexture; // Textura con los graficos de la plabra "CRISIS"
|
||||||
|
std::unique_ptr<Texture> arcadeEditionTexture; // Textura con los graficos de "Arcade Edition"
|
||||||
|
|
||||||
Texture *dustTexture; // Textura con los graficos del polvo
|
std::unique_ptr<AnimatedSprite> dustLSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||||
Texture *coffeeTexture; // Textura con los graficos de la palabra "COFFEE"
|
std::unique_ptr<AnimatedSprite> dustRSprite; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||||
Texture *crisisTexture; // Textura con los graficos de la plabra "CRISIS"
|
|
||||||
Texture *arcadeEditionTexture; // Textura con los graficos de "Arcade Edition"
|
|
||||||
|
|
||||||
AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
std::unique_ptr<SmartSprite> coffeeSprite; // Sprite con la palabra "COFFEE" para la pantalla de titulo
|
||||||
AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
std::unique_ptr<SmartSprite> crisisSprite; // Sprite con la palabra "CRISIS" para la pantalla de titulo
|
||||||
|
|
||||||
SmartSprite *coffeeBitmap; // Sprite con la palabra "COFFEE" para la pantalla de titulo
|
std::unique_ptr<Sprite> arcadeEditionSprite; // Sprite con los graficos de "Arcade Edition"
|
||||||
SmartSprite *crisisBitmap; // Sprite con la palabra "CRISIS" para la pantalla de titulo
|
|
||||||
|
|
||||||
Sprite *arcadeEditionBitmap; // Sprite con los graficos de "Arcade Edition"
|
|
||||||
|
|
||||||
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
||||||
|
|
||||||
@@ -37,15 +34,15 @@ private:
|
|||||||
int x; // Posición donde dibujar el logo
|
int x; // Posición donde dibujar el logo
|
||||||
int y; // Posición donde dibujar el logo
|
int y; // Posición donde dibujar el logo
|
||||||
|
|
||||||
enum status_e
|
enum class Status
|
||||||
{
|
{
|
||||||
disabled,
|
DISABLED,
|
||||||
moving,
|
MOVING,
|
||||||
shaking,
|
SHAKING,
|
||||||
finished
|
FINISHED,
|
||||||
} status; // Estado en el que se encuentra la clase
|
} status; // Estado en el que se encuentra la clase
|
||||||
|
|
||||||
struct shake_t
|
struct Shake
|
||||||
{
|
{
|
||||||
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||||
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||||
@@ -78,7 +75,7 @@ public:
|
|||||||
void enable();
|
void enable();
|
||||||
|
|
||||||
// Indica si ha terminado la animación
|
// Indica si ha terminado la animación
|
||||||
bool hasFinished();
|
bool hasFinished() const;
|
||||||
|
|
||||||
// Recarga las texturas
|
// Recarga las texturas
|
||||||
void reLoad();
|
void reLoad();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace globalInputs
|
|||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
const int numInputs = Input::get()->getNumControllers() + 1;
|
const auto numInputs = Input::get()->getNumControllers() + 1;
|
||||||
servicePressedCounter.reserve(numInputs);
|
servicePressedCounter.reserve(numInputs);
|
||||||
for (int i = 0; i < numInputs; ++i)
|
for (int i = 0; i < numInputs; ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,20 +5,21 @@
|
|||||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
|
||||||
#include <algorithm> // for max
|
#include <algorithm> // for max
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "background.h" // for Background
|
#include "background.h" // for Background
|
||||||
#include "global_inputs.h" // for globalInputs::check
|
#include "global_inputs.h" // for globalInputs::check
|
||||||
#include "input.h" // for Input
|
#include "input.h" // for Input
|
||||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "options.h" // for options
|
#include "options.h" // for options
|
||||||
#include "param.h" // for param
|
#include "param.h" // for param
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR
|
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR
|
||||||
#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t
|
#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable::HiScoreTable(JA_Music_t *music) : music(music)
|
HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||||
|
: music(music)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
renderer = Screen::get()->getRenderer();
|
renderer = Screen::get()->getRenderer();
|
||||||
@@ -74,7 +75,9 @@ void HiScoreTable::update()
|
|||||||
|
|
||||||
// Mantiene la música sonando
|
// Mantiene la música sonando
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
|
{
|
||||||
JA_PlayMusic(music);
|
JA_PlayMusic(music);
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza el objeto screen
|
// Actualiza el objeto screen
|
||||||
Screen::get()->update();
|
Screen::get()->update();
|
||||||
@@ -105,14 +108,14 @@ void HiScoreTable::update()
|
|||||||
void HiScoreTable::fillTexture()
|
void HiScoreTable::fillTexture()
|
||||||
{
|
{
|
||||||
// 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 maxNames = 10;
|
constexpr auto maxNames = 10;
|
||||||
const int spaceBetweenHeader = 32;
|
constexpr auto spaceBetweenHeader = 32;
|
||||||
const int spaceBetweenLines = text->getCharacterSize() * 2.0f;
|
const auto spaceBetweenLines = text->getCharacterSize() * 2.0f;
|
||||||
const int size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize();
|
const auto size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize();
|
||||||
const int firstLine = (param.game.height - size) / 2;
|
const auto firstLine = (param.game.height - size) / 2;
|
||||||
|
|
||||||
// Pinta en el backbuffer el texto y los sprites
|
// Pinta en el backbuffer el texto y los sprites
|
||||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
auto *temp = SDL_GetRenderTarget(renderer);
|
||||||
SDL_SetRenderTarget(renderer, backbuffer);
|
SDL_SetRenderTarget(renderer, backbuffer);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
@@ -123,16 +126,16 @@ void HiScoreTable::fillTexture()
|
|||||||
// Escribe los nombres de la tabla de puntuaciones
|
// Escribe los nombres de la tabla de puntuaciones
|
||||||
for (int i = 0; i < maxNames; ++i)
|
for (int i = 0; i < maxNames; ++i)
|
||||||
{
|
{
|
||||||
const int nameLenght = options.game.hiScoreTable[i].name.length();
|
const auto nameLenght = options.game.hiScoreTable[i].name.length();
|
||||||
const std::string score = format(options.game.hiScoreTable[i].score);
|
const auto score = format(options.game.hiScoreTable[i].score);
|
||||||
const int scoreLenght = score.size();
|
const auto scoreLenght = score.size();
|
||||||
const int numDots = 25 - nameLenght - scoreLenght;
|
const auto numDots = 25 - nameLenght - scoreLenght;
|
||||||
std::string dots = "";
|
std::string dots = "";
|
||||||
for (int j = 0; j < numDots; ++j)
|
for (int j = 0; j < (int)numDots; ++j)
|
||||||
{
|
{
|
||||||
dots = dots + ".";
|
dots = dots + ".";
|
||||||
}
|
}
|
||||||
const std::string line = options.game.hiScoreTable[i].name + dots + score;
|
const auto line = options.game.hiScoreTable[i].name + dots + score;
|
||||||
text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +161,7 @@ void HiScoreTable::render()
|
|||||||
// Copia el backbuffer al renderizador
|
// Copia el backbuffer al renderizador
|
||||||
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
|
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
|
||||||
|
|
||||||
|
// Renderiza el fade
|
||||||
fade->render();
|
fade->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
@@ -226,47 +230,6 @@ void HiScoreTable::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
|
||||||
std::string HiScoreTable::scoreToString(int num)
|
|
||||||
{
|
|
||||||
if ((num >= 0) && (num <= 9))
|
|
||||||
{
|
|
||||||
return ("000000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 10) && (num <= 99))
|
|
||||||
{
|
|
||||||
return ("00000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 100) && (num <= 999))
|
|
||||||
{
|
|
||||||
return ("0000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 1000) && (num <= 9999))
|
|
||||||
{
|
|
||||||
return ("000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 010000) && (num <= 99999))
|
|
||||||
{
|
|
||||||
return ("00" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 100000) && (num <= 999999))
|
|
||||||
{
|
|
||||||
return ("0" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 1000000) && (num <= 9999999))
|
|
||||||
{
|
|
||||||
return (std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestiona el fade
|
// Gestiona el fade
|
||||||
void HiScoreTable::updateFade()
|
void HiScoreTable::updateFade()
|
||||||
{
|
{
|
||||||
@@ -291,9 +254,9 @@ std::string HiScoreTable::format(int number)
|
|||||||
const std::string separator = ".";
|
const std::string separator = ".";
|
||||||
const std::string score = std::to_string(number);
|
const std::string score = std::to_string(number);
|
||||||
|
|
||||||
int index = (int)score.size() - 1;
|
auto index = (int)score.size() - 1;
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
int i = 0;
|
auto i = 0;
|
||||||
while (index >= 0)
|
while (index >= 0)
|
||||||
{
|
{
|
||||||
result = score.at(index) + result;
|
result = score.at(index) + result;
|
||||||
|
|||||||
@@ -60,9 +60,6 @@ private:
|
|||||||
// Convierte un entero a un string con separadores de miles
|
// Convierte un entero a un string con separadores de miles
|
||||||
std::string format(int number);
|
std::string format(int number);
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
|
||||||
std::string scoreToString(int num);
|
|
||||||
|
|
||||||
// Crea el contenido de la textura con la lista de puntuaciones
|
// Crea el contenido de la textura con la lista de puntuaciones
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
@@ -72,9 +69,6 @@ private:
|
|||||||
// Gestiona el fade
|
// Gestiona el fade
|
||||||
void updateFade();
|
void updateFade();
|
||||||
|
|
||||||
// Termina
|
|
||||||
void quit(section::options_e code);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
HiScoreTable(JA_Music_t *music);
|
HiScoreTable(JA_Music_t *music);
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ int main(int argc, char *argv[])
|
|||||||
Director *director = new Director(argc, argv);
|
Director *director = new Director(argc, argv);
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
const int exit = director->run();
|
const auto exit = director->run();
|
||||||
|
|
||||||
// Destruye el objeto Director
|
// Destruye el objeto Director
|
||||||
delete director;
|
delete director;
|
||||||
|
|
||||||
const std::string endType = exit == 0 ? "keyboard" : "controller";
|
const auto endType = exit == 0 ? "keyboard" : "controller";
|
||||||
std::cout << "\nGame end with " << endType << std::endl;
|
std::cout << "\nGame end with " << endType << std::endl;
|
||||||
|
|
||||||
return exit;
|
return exit;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void Notify::update()
|
|||||||
// Si la notificación anterior está "saliendo", no hagas nada
|
// Si la notificación anterior está "saliendo", no hagas nada
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
if (notifications[i - 1].state == ns_rising)
|
if (notifications[i - 1].status == NotificationStatus::RISING)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ void Notify::update()
|
|||||||
{
|
{
|
||||||
if (options.notification.sound)
|
if (options.notification.sound)
|
||||||
{
|
{
|
||||||
if (notifications[i].state == ns_rising)
|
if (notifications[i].status == NotificationStatus::RISING)
|
||||||
{ // Reproduce el sonido de la notificación
|
{ // Reproduce el sonido de la notificación
|
||||||
JA_PlaySound(sound);
|
JA_PlaySound(sound);
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ void Notify::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los estados
|
// Comprueba los estados
|
||||||
if (notifications[i].state == ns_rising)
|
if (notifications[i].status == NotificationStatus::RISING)
|
||||||
{
|
{
|
||||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
||||||
const int alpha = 255 * step;
|
const int alpha = 255 * step;
|
||||||
@@ -92,21 +92,21 @@ void Notify::update()
|
|||||||
|
|
||||||
if (notifications[i].rect.y == notifications[i].y)
|
if (notifications[i].rect.y == notifications[i].y)
|
||||||
{
|
{
|
||||||
notifications[i].state = ns_stay;
|
notifications[i].status = NotificationStatus::STAY;
|
||||||
notifications[i].texture->setAlpha(255);
|
notifications[i].texture->setAlpha(255);
|
||||||
notifications[i].counter = 0;
|
notifications[i].counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (notifications[i].state == ns_stay)
|
else if (notifications[i].status == NotificationStatus::STAY)
|
||||||
{
|
{
|
||||||
if (notifications[i].counter == waitTime)
|
if (notifications[i].counter == waitTime)
|
||||||
{
|
{
|
||||||
notifications[i].state = ns_vanishing;
|
notifications[i].status = NotificationStatus::VANISHING;
|
||||||
notifications[i].counter = 0;
|
notifications[i].counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (notifications[i].state == ns_vanishing)
|
else if (notifications[i].status == NotificationStatus::VANISHING)
|
||||||
{
|
{
|
||||||
|
|
||||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
||||||
@@ -124,7 +124,7 @@ void Notify::update()
|
|||||||
|
|
||||||
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
||||||
{
|
{
|
||||||
notifications[i].state = ns_finished;
|
notifications[i].status = NotificationStatus::FINISHED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ void Notify::clearFinishedNotifications()
|
|||||||
{
|
{
|
||||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
if (notifications[i].state == ns_finished)
|
if (notifications[i].status == NotificationStatus::FINISHED)
|
||||||
{
|
{
|
||||||
notifications.erase(notifications.begin() + i);
|
notifications.erase(notifications.begin() + i);
|
||||||
}
|
}
|
||||||
@@ -150,15 +150,7 @@ void Notify::clearFinishedNotifications()
|
|||||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
void Notify::showText(std::string text1, std::string text2, int icon)
|
||||||
{
|
{
|
||||||
// Cuenta el número de textos a mostrar
|
// Cuenta el número de textos a mostrar
|
||||||
int numTexts = 0;
|
const int numTexts = (text1 != "") + (text2 != "");
|
||||||
if (text1 != "")
|
|
||||||
{
|
|
||||||
numTexts++;
|
|
||||||
}
|
|
||||||
if (text2 != "")
|
|
||||||
{
|
|
||||||
numTexts++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si no hay texto, acaba
|
// Si no hay texto, acaba
|
||||||
if (numTexts == 0)
|
if (numTexts == 0)
|
||||||
@@ -179,17 +171,17 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
constexpr int iconSize = 16;
|
constexpr auto iconSize = 16;
|
||||||
constexpr int paddingOut = 1;
|
constexpr auto paddingOut = 1;
|
||||||
const int paddingIn = text->getCharacterSize() / 2;
|
const auto paddingIn = text->getCharacterSize() / 2;
|
||||||
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
const auto iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
|
||||||
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||||
const int width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
|
const auto width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
|
||||||
const int height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
|
const auto height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
|
||||||
const notification_shape_t shape = notification_shape_squared;
|
const auto shape = NotificationShape::SQUARED;
|
||||||
|
|
||||||
// Posición horizontal
|
// Posición horizontal
|
||||||
int despH = 0;
|
auto despH = 0;
|
||||||
if (options.notification.posH == pos_left)
|
if (options.notification.posH == pos_left)
|
||||||
{
|
{
|
||||||
despH = paddingOut;
|
despH = paddingOut;
|
||||||
@@ -204,20 +196,11 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Posición vertical
|
// Posición vertical
|
||||||
int despV = 0;
|
const int despV = (options.notification.posV == pos_top) ? paddingOut : (param.game.height - height - paddingOut);
|
||||||
if (options.notification.posV == pos_top)
|
|
||||||
{
|
|
||||||
despV = paddingOut;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
despV = param.game.height - height - paddingOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int travelDist = height + paddingOut;
|
|
||||||
|
|
||||||
// Offset
|
// Offset
|
||||||
int offset = 0;
|
const auto travelDist = height + paddingOut;
|
||||||
|
auto offset = 0;
|
||||||
if (options.notification.posV == pos_top)
|
if (options.notification.posV == pos_top)
|
||||||
{
|
{
|
||||||
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
||||||
@@ -227,18 +210,32 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
|
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura de fondo de la notificación
|
// Crea la notificacion
|
||||||
auto texture = std::make_unique<Texture>(renderer);
|
Notification n;
|
||||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
// Inicializa variables
|
||||||
|
n.y = offset;
|
||||||
|
n.travelDist = travelDist;
|
||||||
|
n.counter = 0;
|
||||||
|
n.status = NotificationStatus::RISING;
|
||||||
|
n.text1 = text1;
|
||||||
|
n.text2 = text2;
|
||||||
|
n.shape = shape;
|
||||||
|
auto yPos = offset + (options.notification.posV == pos_top ? -travelDist : travelDist);
|
||||||
|
n.rect = {despH, yPos, width, height};
|
||||||
|
|
||||||
|
// Crea la textura
|
||||||
|
n.texture = new Texture(renderer);
|
||||||
|
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||||
|
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Prepara para dibujar en la textura
|
// Prepara para dibujar en la textura
|
||||||
texture->setAsRenderTarget(renderer);
|
n.texture->setAsRenderTarget(renderer);
|
||||||
|
|
||||||
// Dibuja fondo de la notificación sobre la textura
|
// Dibuja el fondo de la notificación
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
if (shape == notification_shape_rounded)
|
if (shape == NotificationShape::ROUNDED)
|
||||||
{
|
{
|
||||||
rect = {4, 0, width - (4 * 2), height};
|
rect = {4, 0, width - (4 * 2), height};
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
@@ -253,7 +250,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (shape == notification_shape_squared)
|
else if (shape == NotificationShape::SQUARED)
|
||||||
{
|
{
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
}
|
}
|
||||||
@@ -283,28 +280,13 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
|||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Crea el sprite de la notificación
|
// Crea el sprite de la notificación
|
||||||
auto sprite = std::make_unique<Sprite>((SDL_Rect){despH, 50, width, height}, texture.get());
|
n.sprite = new Sprite(n.rect, n.texture);
|
||||||
|
|
||||||
// Crea la notificacion
|
|
||||||
notification_t n(std::move(texture), std::move(sprite));
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
n.y = offset;
|
|
||||||
n.travelDist = travelDist;
|
|
||||||
n.counter = 0;
|
|
||||||
n.state = ns_rising;
|
|
||||||
n.text1 = text1;
|
|
||||||
n.text2 = text2;
|
|
||||||
n.shape = shape;
|
|
||||||
const int yPos = offset + (options.notification.posV == pos_top ? -travelDist : travelDist);
|
|
||||||
n.rect = {despH, yPos, width, height};
|
|
||||||
n.sprite->setPos(n.rect);
|
|
||||||
|
|
||||||
// Deja la notificación invisible
|
// Deja la notificación invisible
|
||||||
n.texture->setAlpha(0);
|
n.texture->setAlpha(0);
|
||||||
|
|
||||||
// Añade la notificación a la lista
|
// Añade la notificación a la lista
|
||||||
notifications.push_back(std::move(n));
|
notifications.push_back(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
@@ -323,7 +305,7 @@ void Notify::clearNotifications()
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
for (int i = 0; i < (int)notifications.size(); ++i)
|
||||||
{
|
{
|
||||||
notifications[i].state = ns_finished;
|
notifications[i].status = NotificationStatus::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFinishedNotifications();
|
clearFinishedNotifications();
|
||||||
|
|||||||
@@ -14,72 +14,45 @@ struct JA_Sound_t;
|
|||||||
class Notify
|
class Notify
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
enum notification_state_e
|
enum class NotificationStatus
|
||||||
{
|
{
|
||||||
ns_rising,
|
RISING,
|
||||||
ns_stay,
|
STAY,
|
||||||
ns_vanishing,
|
VANISHING,
|
||||||
ns_finished
|
FINISHED,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum notification_position_e
|
enum class NotificationPosition
|
||||||
{
|
{
|
||||||
upperLeft,
|
UPPERLEFT,
|
||||||
upperCenter,
|
UPPERCENTER,
|
||||||
upperRight,
|
UPPERRIGHT,
|
||||||
middleLeft,
|
MIDDLELEFT,
|
||||||
middleRight,
|
MIDDLERIGHT,
|
||||||
bottomLeft,
|
BOTTOMLEFT,
|
||||||
bottomCenter,
|
BOTTOMCENTER,
|
||||||
bottomRight
|
BOTTOMRIGHT,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum notification_shape_t
|
enum class NotificationShape
|
||||||
{
|
{
|
||||||
notification_shape_rounded,
|
ROUNDED,
|
||||||
notification_shape_squared,
|
SQUARED,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct notification_t
|
struct Notification
|
||||||
{
|
{
|
||||||
std::unique_ptr<Texture> texture;
|
Texture *texture;
|
||||||
std::unique_ptr<Sprite> sprite;
|
Sprite *sprite;
|
||||||
std::string text1;
|
std::string text1;
|
||||||
std::string text2;
|
std::string text2;
|
||||||
int counter;
|
int counter;
|
||||||
notification_state_e state;
|
NotificationStatus status;
|
||||||
notification_position_e position;
|
NotificationPosition position;
|
||||||
|
NotificationShape shape;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
int y;
|
int y;
|
||||||
int travelDist;
|
int travelDist;
|
||||||
notification_shape_t shape;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
notification_t(std::unique_ptr<Texture> texture, std::unique_ptr<Sprite> sprite)
|
|
||||||
: texture(std::move(texture)), sprite(std::move(sprite)) {}
|
|
||||||
|
|
||||||
// Constructor de movimiento
|
|
||||||
notification_t(notification_t &&other) noexcept
|
|
||||||
: texture(std::move(other.texture)), sprite(std::move(other.sprite))
|
|
||||||
{
|
|
||||||
// Mover otros miembros si es necesario
|
|
||||||
}
|
|
||||||
|
|
||||||
// Operador de asignación por movimiento
|
|
||||||
notification_t &operator=(notification_t &&other) noexcept
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
texture = std::move(other.texture);
|
|
||||||
sprite = std::move(other.sprite);
|
|
||||||
// Mover otros miembros si es necesario
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deshabilitar el constructor de copia y operador de asignación por copia
|
|
||||||
notification_t(const notification_t &) = delete;
|
|
||||||
notification_t &operator=(const notification_t &) = delete;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
@@ -89,12 +62,12 @@ private:
|
|||||||
std::unique_ptr<Text> text; // Objeto para dibujar texto
|
std::unique_ptr<Text> text; // Objeto para dibujar texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
color_t bgColor; // Color de fondo de las notificaciones
|
color_t bgColor; // Color de fondo de las notificaciones
|
||||||
int waitTime; // Tiempo que se ve la notificación
|
int waitTime; // Tiempo que se ve la notificación
|
||||||
std::vector<notification_t> notifications; // La lista de notificaciones activas
|
std::vector<Notification> notifications; // La lista de notificaciones activas
|
||||||
JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
|
JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
|
||||||
bool stack; // Indica si las notificaciones se apilan
|
bool stack; // Indica si las notificaciones se apilan
|
||||||
bool hasIcons; // Indica si el notificador tiene textura para iconos
|
bool hasIcons; // Indica si el notificador tiene textura para iconos
|
||||||
|
|
||||||
// Elimina las notificaciones finalizadas
|
// Elimina las notificaciones finalizadas
|
||||||
void clearFinishedNotifications();
|
void clearFinishedNotifications();
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <math.h> // for roundf
|
#include <math.h> // for roundf
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "lang.h" // for getText
|
#include "lang.h" // for getText
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
@@ -96,44 +98,11 @@ Scoreboard::~Scoreboard()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
std::string Scoreboard::updateScoreText(Uint32 num)
|
std::string Scoreboard::updateScoreText(int num)
|
||||||
{
|
{
|
||||||
if ((num >= 0) && (num <= 9))
|
std::ostringstream oss;
|
||||||
{
|
oss << std::setw(8) << std::setfill('0') << num;
|
||||||
return ("000000" + std::to_string(num));
|
return oss.str();
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 10) && (num <= 99))
|
|
||||||
{
|
|
||||||
return ("00000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 100) && (num <= 999))
|
|
||||||
{
|
|
||||||
return ("0000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 1000) && (num <= 9999))
|
|
||||||
{
|
|
||||||
return ("000" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 010000) && (num <= 99999))
|
|
||||||
{
|
|
||||||
return ("00" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 100000) && (num <= 999999))
|
|
||||||
{
|
|
||||||
return ("0" + std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((num >= 1000000) && (num <= 9999999))
|
|
||||||
{
|
|
||||||
return (std::to_string(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (std::to_string(num));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ private:
|
|||||||
void recalculateAnchors();
|
void recalculateAnchors();
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
std::string updateScoreText(Uint32 num);
|
std::string updateScoreText(int num);
|
||||||
|
|
||||||
// Crea la textura de fondo
|
// Crea la textura de fondo
|
||||||
void createBackgroundTexture();
|
void createBackgroundTexture();
|
||||||
|
|||||||
Reference in New Issue
Block a user