Muntat a c++14 per a make_unique
Mes autos, const i constexpr perl codi Ara la classe Screen es un poc pitjor
This commit is contained in:
8
Makefile
8
Makefile
@@ -25,8 +25,8 @@ INCLUDES:= -I$(DIR_SOURCES)
|
||||
ifeq ($(OS),Windows_NT)
|
||||
FixPath = $(subst /,\,$1)
|
||||
SOURCES := source/*.cpp
|
||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS_DEBUG:= -std=c++11 -Wall
|
||||
CXXFLAGS:= -std=c++14 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows
|
||||
CXXFLAGS_DEBUG:= -std=c++14 -Wall
|
||||
LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32
|
||||
RM = del /Q
|
||||
MKD:= mkdir
|
||||
@@ -34,8 +34,8 @@ else
|
||||
FixPath = $1
|
||||
SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp')
|
||||
SOURCES := source/*.cpp
|
||||
CXXFLAGS:= -std=c++11 -Wall -Os -ffunction-sections -fdata-sections
|
||||
CXXFLAGS_DEBUG:= -std=c++11 -Wall
|
||||
CXXFLAGS:= -std=c++14 -Wall -Os -ffunction-sections -fdata-sections
|
||||
CXXFLAGS_DEBUG:= -std=c++14 -Wall
|
||||
LDFLAGS := -lSDL2
|
||||
RM = rm -f
|
||||
MKD:= mkdir -p
|
||||
|
||||
@@ -13,14 +13,13 @@ constexpr int BULLET_VELX_RIGHT = 2;
|
||||
// Constructor
|
||||
Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, Texture *texture)
|
||||
: posX(x), posY(y), width(BULLET_WIDTH), height(BULLET_HEIGHT), velX(0), velY(BULLET_VELY),
|
||||
kind(kind), owner(owner), playArea(playArea),
|
||||
sprite(std::unique_ptr<Sprite>(new Sprite(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture))) // Crear manualmente el std::unique_ptr
|
||||
kind(kind), owner(owner), playArea(playArea)
|
||||
{
|
||||
velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT
|
||||
: 0;
|
||||
velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT : 0;
|
||||
|
||||
auto spriteOffset = poweredUp ? 3 : 0;
|
||||
auto kindIndex = static_cast<int>(kind);
|
||||
sprite = std::make_unique<Sprite>(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture);
|
||||
sprite->setSpriteClip((kindIndex + spriteOffset) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
|
||||
collider.r = width / 2;
|
||||
|
||||
@@ -117,7 +117,7 @@ Director::~Director()
|
||||
|
||||
Asset::destroy();
|
||||
Input::destroy();
|
||||
Screen::destroy();
|
||||
//Screen::destroy();
|
||||
OnScreenHelp::destroy();
|
||||
|
||||
deleteSounds();
|
||||
@@ -275,7 +275,7 @@ bool Director::initSDL()
|
||||
#endif
|
||||
|
||||
// Establece el filtro de la textura
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options.video.filter).c_str()))
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Warning: texture filtering not enabled!\n";
|
||||
@@ -486,12 +486,6 @@ bool Director::setFileList()
|
||||
void Director::loadParams(std::string filepath)
|
||||
{
|
||||
loadParamsFromFile(filepath);
|
||||
|
||||
// Modifica las opciones desde el fichero de parametros
|
||||
options.video.window.width = options.video.window.size * param.game.width;
|
||||
options.video.window.height = options.video.window.size * param.game.height;
|
||||
options.video.gameWidth = param.game.width;
|
||||
options.video.gameHeight = param.game.height;
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
|
||||
@@ -52,12 +52,14 @@ Game::Game(int playerID, int currentStage, bool demo, JA_Music_t *music)
|
||||
difficulty = options.game.difficulty;
|
||||
|
||||
// Crea los objetos
|
||||
fade = new Fade(renderer);
|
||||
eventHandler = new SDL_Event();
|
||||
scoreboard = new Scoreboard(renderer);
|
||||
background = new Background(renderer);
|
||||
explosions = new Explosions();
|
||||
enemyFormations = new EnemyFormations();
|
||||
Scoreboard::init(renderer);
|
||||
scoreboard = Scoreboard::get();
|
||||
eventHandler = std::make_unique<SDL_Event>();
|
||||
fade = std::make_unique<Fade>(renderer);
|
||||
|
||||
background = std::make_unique<Background>(renderer);
|
||||
explosions = std::make_unique<Explosions>();
|
||||
enemyFormations = std::make_unique<EnemyFormations>();
|
||||
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
@@ -65,17 +67,17 @@ Game::Game(int playerID, int currentStage, bool demo, JA_Music_t *music)
|
||||
// Inicializa los vectores con los datos para la demo
|
||||
if (demo)
|
||||
{ // Aleatoriza la asignación del fichero
|
||||
const int index1 = rand() % 2;
|
||||
const int index2 = (index1 + 1) % 2;
|
||||
const auto index1 = rand() % 2;
|
||||
const auto index2 = (index1 + 1) % 2;
|
||||
loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile[index1]);
|
||||
loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]);
|
||||
}
|
||||
|
||||
background->setPos(param.game.playArea.rect);
|
||||
|
||||
n1000Sprite = new SmartSprite(gameTextTexture);
|
||||
n2500Sprite = new SmartSprite(gameTextTexture);
|
||||
n5000Sprite = new SmartSprite(gameTextTexture);
|
||||
n1000Sprite = std::make_unique<SmartSprite>(gameTextTexture.get());
|
||||
n2500Sprite = std::make_unique<SmartSprite>(gameTextTexture.get());
|
||||
n5000Sprite = std::make_unique<SmartSprite>(gameTextTexture.get());
|
||||
|
||||
explosions->addTexture(1, explosionsTextures[0], explosionsAnimations[0]);
|
||||
explosions->addTexture(2, explosionsTextures[1], explosionsAnimations[1]);
|
||||
@@ -92,9 +94,8 @@ Game::Game(int playerID, int currentStage, bool demo, JA_Music_t *music)
|
||||
Game::~Game()
|
||||
{
|
||||
// Guarda las puntuaciones en un fichero
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hiScoreTable);
|
||||
manager->saveToFile(asset->get("score.bin"));
|
||||
delete manager;
|
||||
#ifdef RECORDING
|
||||
saveDemoFile(asset->get("demo1.bin"));
|
||||
#endif
|
||||
@@ -105,17 +106,7 @@ Game::~Game()
|
||||
// Libera los recursos
|
||||
unloadMedia();
|
||||
|
||||
delete scoreboard;
|
||||
delete background;
|
||||
delete explosions;
|
||||
delete enemyFormations;
|
||||
|
||||
delete fade;
|
||||
delete eventHandler;
|
||||
|
||||
delete n1000Sprite;
|
||||
delete n2500Sprite;
|
||||
delete n5000Sprite;
|
||||
Scoreboard::destroy();
|
||||
|
||||
SDL_DestroyTexture(canvas);
|
||||
}
|
||||
@@ -163,7 +154,7 @@ void Game::init(int playerID)
|
||||
// Variables relacionadas con la dificultad
|
||||
switch (difficulty)
|
||||
{
|
||||
case DIFFICULTY_EASY:
|
||||
case gameDifficulty::EASY:
|
||||
{
|
||||
defaultEnemySpeed = BALLOON_SPEED_1;
|
||||
difficultyScoreMultiplier = 0.5f;
|
||||
@@ -172,7 +163,7 @@ void Game::init(int playerID)
|
||||
break;
|
||||
}
|
||||
|
||||
case DIFFICULTY_NORMAL:
|
||||
case gameDifficulty::NORMAL:
|
||||
{
|
||||
defaultEnemySpeed = BALLOON_SPEED_1;
|
||||
difficultyScoreMultiplier = 1.0f;
|
||||
@@ -181,7 +172,7 @@ void Game::init(int playerID)
|
||||
break;
|
||||
}
|
||||
|
||||
case DIFFICULTY_HARD:
|
||||
case gameDifficulty::HARD:
|
||||
{
|
||||
defaultEnemySpeed = BALLOON_SPEED_5;
|
||||
difficultyScoreMultiplier = 1.5f;
|
||||
@@ -312,10 +303,10 @@ void Game::init(int playerID)
|
||||
evaluateAndSetMenace();
|
||||
|
||||
// Inicializa el bitmap de 1000 puntos
|
||||
const int height = 15;
|
||||
const int sprite1Width = 35;
|
||||
const int sprite2Width = 38;
|
||||
const int sprite3Width = 39;
|
||||
constexpr int height = 15;
|
||||
constexpr int sprite1Width = 35;
|
||||
constexpr int sprite2Width = 38;
|
||||
constexpr int sprite3Width = 39;
|
||||
n1000Sprite->setPosX(0);
|
||||
n1000Sprite->setPosY(0);
|
||||
n1000Sprite->setWidth(sprite1Width);
|
||||
@@ -379,8 +370,8 @@ void Game::loadMedia()
|
||||
explosionsTextures.clear();
|
||||
|
||||
// Texturas
|
||||
bulletTexture = new Texture(renderer, asset->get("bullet.png"));
|
||||
gameTextTexture = new Texture(renderer, asset->get("game_text.png"));
|
||||
bulletTexture = std::make_unique<Texture>(renderer, asset->get("bullet.png"));
|
||||
gameTextTexture = std::make_unique<Texture>(renderer, asset->get("game_text.png"));
|
||||
|
||||
// Texturas - Globos
|
||||
Texture *balloon1Texture = new Texture(renderer, asset->get("balloon1.png"));
|
||||
@@ -566,9 +557,6 @@ void Game::loadMedia()
|
||||
void Game::unloadMedia()
|
||||
{
|
||||
// Texturas
|
||||
delete bulletTexture;
|
||||
delete gameTextTexture;
|
||||
|
||||
for (auto texture : player1Textures)
|
||||
{
|
||||
if (texture)
|
||||
@@ -1059,7 +1047,7 @@ void Game::setBalloonSpeed(float speed)
|
||||
void Game::incBalloonSpeed()
|
||||
{
|
||||
// La velocidad solo se incrementa en el modo normal
|
||||
if (difficulty == DIFFICULTY_NORMAL)
|
||||
if (difficulty == gameDifficulty::NORMAL)
|
||||
{
|
||||
if (enemySpeed == BALLOON_SPEED_1)
|
||||
{
|
||||
@@ -1089,7 +1077,7 @@ void Game::incBalloonSpeed()
|
||||
void Game::decBalloonSpeed()
|
||||
{
|
||||
// La velocidad solo se decrementa en el modo normal
|
||||
if (difficulty == DIFFICULTY_NORMAL)
|
||||
if (difficulty == gameDifficulty::NORMAL)
|
||||
{
|
||||
if (enemySpeed == BALLOON_SPEED_5)
|
||||
{
|
||||
@@ -1383,21 +1371,21 @@ void Game::checkPlayerItemCollision(Player *player)
|
||||
case ITEM_POINTS_1_DISK:
|
||||
player->addScore(1000);
|
||||
updateHiScore();
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n1000Sprite->getWidth() / 2), player->getPosY(), n1000Sprite);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n1000Sprite->getWidth() / 2), player->getPosY(), n1000Sprite.get());
|
||||
JA_PlaySound(itemPickUpSound);
|
||||
break;
|
||||
|
||||
case ITEM_POINTS_2_GAVINA:
|
||||
player->addScore(2500);
|
||||
updateHiScore();
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n2500Sprite->getWidth() / 2), player->getPosY(), n2500Sprite);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n2500Sprite->getWidth() / 2), player->getPosY(), n2500Sprite.get());
|
||||
JA_PlaySound(itemPickUpSound);
|
||||
break;
|
||||
|
||||
case ITEM_POINTS_3_PACMAR:
|
||||
player->addScore(5000);
|
||||
updateHiScore();
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite.get());
|
||||
JA_PlaySound(itemPickUpSound);
|
||||
break;
|
||||
|
||||
@@ -1411,7 +1399,7 @@ void Game::checkPlayerItemCollision(Player *player)
|
||||
{
|
||||
player->addScore(5000);
|
||||
updateHiScore();
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite);
|
||||
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (n5000Sprite->getWidth() / 2), player->getPosY(), n5000Sprite.get());
|
||||
}
|
||||
player->giveExtraHit();
|
||||
JA_PlaySound(itemPickUpSound);
|
||||
@@ -1517,7 +1505,7 @@ void Game::renderBullets()
|
||||
// Crea un objeto bala
|
||||
void Game::createBullet(int x, int y, BulletType kind, bool poweredUp, int owner)
|
||||
{
|
||||
Bullet *b = new Bullet(x, y, kind, poweredUp, owner, &(param.game.playArea.rect), bulletTexture);
|
||||
Bullet *b = new Bullet(x, y, kind, poweredUp, owner, &(param.game.playArea.rect), bulletTexture.get());
|
||||
bullets.push_back(b);
|
||||
}
|
||||
|
||||
@@ -2629,7 +2617,7 @@ bool Game::allPlayersAreNotPlaying()
|
||||
// Comprueba los eventos que hay en cola
|
||||
void Game::checkEvents()
|
||||
{
|
||||
while (SDL_PollEvent(eventHandler) != 0)
|
||||
while (SDL_PollEvent(eventHandler.get()) != 0)
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
@@ -2815,11 +2803,10 @@ void Game::pause(bool value)
|
||||
// Añade una puntuación a la tabla de records
|
||||
void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
{
|
||||
const hiScoreEntry_t entry = {trim(name), score};
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
const auto entry = (hiScoreEntry_t){trim(name), score};
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(&options.game.hiScoreTable);
|
||||
manager->add(entry);
|
||||
manager->saveToFile(asset->get("score.bin"));
|
||||
delete manager;
|
||||
}
|
||||
|
||||
// Comprueba el estado de los jugadores
|
||||
@@ -2860,7 +2847,6 @@ void Game::checkPlayersStatusPlaying()
|
||||
{
|
||||
const playerStatus nextPlayerStatus = IsEligibleForHighScore(player->getScore()) ? playerStatus::ENTERING_NAME : playerStatus::CONTINUE;
|
||||
demo.enabled ? player->setStatusPlaying(playerStatus::WAITING) : player->setStatusPlaying(nextPlayerStatus);
|
||||
// addScoreToScoreBoard(player->getName(), player->getScore());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector> // for vector
|
||||
#include "section.h" // for options_e
|
||||
#include "utils.h" // for demoKeys_t, color_t, hiScoreEntry_t
|
||||
#include <memory>
|
||||
class Asset; // lines 11-11
|
||||
class Background; // lines 12-12
|
||||
class Balloon; // lines 13-13
|
||||
@@ -110,9 +111,11 @@ private:
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Manejador de entrada
|
||||
Scoreboard *scoreboard; // Objeto para dibujar el marcador
|
||||
Background *background; // Objeto para dibujar el fondo del juego
|
||||
Explosions *explosions; // Objeto para dibujar explosiones
|
||||
EnemyFormations *enemyFormations; // Objeto para gestionar las oleadas enemigas
|
||||
|
||||
std::unique_ptr<Background> background; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Explosions> explosions; // Objeto para dibujar explosiones
|
||||
std::unique_ptr<EnemyFormations> enemyFormations; // Objeto para gestionar las oleadas enemigas
|
||||
|
||||
SDL_Texture *canvas; // Textura para dibujar la zona de juego
|
||||
|
||||
std::vector<Player *> players; // Vector con los jugadores
|
||||
@@ -121,7 +124,7 @@ private:
|
||||
std::vector<Item *> items; // Vector con los items
|
||||
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
|
||||
|
||||
Texture *bulletTexture; // Textura para las balas
|
||||
std::unique_ptr<Texture> bulletTexture; // Textura para las balas
|
||||
std::vector<Texture *> itemTextures; // Vector con las texturas de los items
|
||||
std::vector<Texture *> balloonTextures; // Vector con las texturas de los globos
|
||||
std::vector<Texture *> explosionsTextures; // Vector con las texturas de las explosiones
|
||||
@@ -129,7 +132,7 @@ private:
|
||||
std::vector<Texture *> player2Textures; // Vector con las texturas del jugador
|
||||
std::vector<std::vector<Texture *>> playerTextures; // Vector con todas las texturas de los jugadores;
|
||||
|
||||
Texture *gameTextTexture; // Textura para los sprites con textos
|
||||
std::unique_ptr<Texture> gameTextTexture; // Textura para los sprites con textos
|
||||
|
||||
std::vector<std::vector<std::string> *> itemAnimations; // Vector con las animaciones de los items
|
||||
std::vector<std::vector<std::string> *> playerAnimations; // Vector con las animaciones del jugador
|
||||
@@ -141,12 +144,12 @@ private:
|
||||
Text *textNokia2; // Otra fuente de texto para mensajes
|
||||
Text *textNokiaBig2; // Y la versión en grande
|
||||
|
||||
Fade *fade; // Objeto para renderizar fades
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
std::unique_ptr<Fade> fade; // Objeto para renderizar fades
|
||||
std::unique_ptr<SDL_Event> eventHandler; // Manejador de eventos
|
||||
|
||||
SmartSprite *n1000Sprite; // Sprite con el texto 1.000
|
||||
SmartSprite *n2500Sprite; // Sprite con el texto 2.500
|
||||
SmartSprite *n5000Sprite; // Sprite con el texto 5.000
|
||||
std::unique_ptr<SmartSprite> n1000Sprite; // Sprite con el texto 1.000
|
||||
std::unique_ptr<SmartSprite> n2500Sprite; // Sprite con el texto 2.500
|
||||
std::unique_ptr<SmartSprite> n5000Sprite; // Sprite con el texto 5.000
|
||||
|
||||
JA_Sound_t *balloonSound; // Sonido para la explosión del globo
|
||||
JA_Sound_t *bulletSound; // Sonido para los disparos
|
||||
@@ -192,7 +195,7 @@ private:
|
||||
bool coffeeMachineEnabled; // Indica si hay una máquina de café en el terreno de juego
|
||||
bool gameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||
int gameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||
int difficulty; // Dificultad del juego
|
||||
gameDifficulty difficulty; // Dificultad del juego
|
||||
float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||
color_t difficultyColor; // Color asociado a la dificultad
|
||||
int lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string> // for basic_string, char_traits, string
|
||||
#include "jail_audio.h" // for JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||
#include "options.h" // for options
|
||||
#include "param.h"
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
@@ -210,11 +211,11 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
}
|
||||
else if (options.notification.posH == pos_middle)
|
||||
{
|
||||
despH = ((options.video.gameWidth / 2) - (width / 2));
|
||||
despH = ((param.game.width / 2) - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
despH = options.video.gameWidth - width - paddingOut;
|
||||
despH = param.game.width - width - paddingOut;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
@@ -225,7 +226,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
}
|
||||
else
|
||||
{
|
||||
despV = options.video.gameHeight - height - paddingOut;
|
||||
despV = param.game.height - height - paddingOut;
|
||||
}
|
||||
|
||||
const int travelDist = height + paddingOut;
|
||||
|
||||
@@ -94,13 +94,13 @@ void OnScreenHelp::fillTexture()
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), texture);
|
||||
|
||||
// Crea el objeto para el texto
|
||||
std::unique_ptr<Text> text(new Text(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer()));
|
||||
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
|
||||
|
||||
// Crea la textura con los gráficos
|
||||
std::unique_ptr<Texture> controllersTexture(new Texture(Screen::get()->getRenderer(), Asset::get()->get("controllers.png")));
|
||||
auto controllersTexture = std::make_unique<Texture>(Screen::get()->getRenderer(), Asset::get()->get("controllers.png"));
|
||||
|
||||
// Crea el sprite para dibujar los gráficos
|
||||
std::unique_ptr<Sprite> sprite(new Sprite({0, 0, 16, 16}, controllersTexture.get()));
|
||||
auto sprite = std::make_unique<Sprite>((SDL_Rect){0, 0, 16, 16}, controllersTexture.get());
|
||||
|
||||
// Borra la textura
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0);
|
||||
@@ -140,11 +140,11 @@ void OnScreenHelp::fillTexture()
|
||||
// Define el ancho y alto de la textura
|
||||
void OnScreenHelp::setSize()
|
||||
{
|
||||
const int textSize = getLargestStringSize();
|
||||
const int width = PADDING.x + DESP.x + textSize + PADDING.x;
|
||||
const int height = PADDING.y + (7 * 18) + PADDING.y;
|
||||
const int x = 0;
|
||||
const int y = (param.game.height - height) / 2;
|
||||
const auto textSize = getLargestStringSize();
|
||||
const auto width = PADDING.x + DESP.x + textSize + PADDING.x;
|
||||
const auto height = PADDING.y + (7 * 18) + PADDING.y;
|
||||
const auto x = 0;
|
||||
const auto y = (param.game.height - height) / 2;
|
||||
|
||||
dest = (SDL_Rect){x, y, width, height};
|
||||
|
||||
@@ -167,14 +167,14 @@ void OnScreenHelp::toggleState()
|
||||
}
|
||||
|
||||
// Calcula la longitud en pixels del texto más largo
|
||||
int OnScreenHelp::getLargestStringSize() const
|
||||
auto OnScreenHelp::getLargestStringSize() -> int const
|
||||
{
|
||||
std::unique_ptr<Text> text(new Text(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer()));
|
||||
int size = 0;
|
||||
auto text = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Screen::get()->getRenderer());
|
||||
auto size = 0;
|
||||
|
||||
for (int i = 107; i <= 113; ++i)
|
||||
{
|
||||
const int textSize = text->lenght(lang::getText(i));
|
||||
const auto textSize = text->lenght(lang::getText(i));
|
||||
size = textSize > size ? textSize : size;
|
||||
}
|
||||
|
||||
@@ -196,14 +196,19 @@ void OnScreenHelp::updatePosition()
|
||||
switch (state)
|
||||
{
|
||||
case OnScreenHelpStatus::hidden:
|
||||
{
|
||||
index = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case OnScreenHelpStatus::showing:
|
||||
{
|
||||
index = path.size() - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case OnScreenHelpStatus::exitting:
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
index--;
|
||||
@@ -213,8 +218,10 @@ void OnScreenHelp::updatePosition()
|
||||
state = OnScreenHelpStatus::hidden;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case OnScreenHelpStatus::entering:
|
||||
{
|
||||
if (index < (int)path.size() - 1)
|
||||
{
|
||||
index++;
|
||||
@@ -224,6 +231,7 @@ void OnScreenHelp::updatePosition()
|
||||
state = OnScreenHelpStatus::showing;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
void setSize();
|
||||
|
||||
// Calcula la longitud en pixels del texto más largo
|
||||
int getLargestStringSize() const;
|
||||
auto getLargestStringSize() -> int const;
|
||||
|
||||
// Renderizara el boton y el texto
|
||||
void renderButton(Sprite *sprite, Text *text, const SDL_Rect &buttonClip, const SDL_Rect &buttonPos, int textId);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <vector> // for vector
|
||||
#include "input.h" // for inputs_e, INPUT_USE_ANY, INPUT_...
|
||||
#include "lang.h" // for lang_e
|
||||
#include "screen.h" // for SCREEN_FILTER_NEAREST, SCREEN_V...
|
||||
#include "screen.h" // for screenFilter::NEAREST, SCREEN_V...
|
||||
#include "utils.h" // for op_controller_t, options_t, op_...
|
||||
|
||||
// Variables
|
||||
@@ -21,23 +21,21 @@ void initOptions()
|
||||
{
|
||||
// Opciones de video
|
||||
#ifdef ANBERNIC
|
||||
options.video.mode = 0;
|
||||
options.video.mode = screenVideoMode::WINDOW;
|
||||
options.video.window.size = 3;
|
||||
#else
|
||||
options.video.mode = 0;
|
||||
options.video.mode = screenVideoMode::WINDOW;
|
||||
options.video.window.size = 2;
|
||||
#endif
|
||||
options.video.filter = SCREEN_FILTER_NEAREST;
|
||||
options.video.filter = screenFilter::NEAREST;
|
||||
options.video.vSync = true;
|
||||
options.video.integerScale = true;
|
||||
options.video.keepAspect = true;
|
||||
options.video.shaders = true;
|
||||
|
||||
// Opciones de las notificaciones
|
||||
options.notification.posV = pos_top;
|
||||
options.notification.posH = pos_left;
|
||||
options.notification.sound = false;
|
||||
options.notification.color = {48, 48, 48};
|
||||
options.notification.color = (color_t){48, 48, 48};
|
||||
|
||||
// Opciones de audio
|
||||
options.audio.music.enabled = true;
|
||||
@@ -46,7 +44,7 @@ void initOptions()
|
||||
options.audio.sound.volume = 64;
|
||||
|
||||
// Opciones de juego
|
||||
options.game.difficulty = DIFFICULTY_NORMAL;
|
||||
options.game.difficulty = gameDifficulty::NORMAL;
|
||||
options.game.language = lang::ba_BA;
|
||||
options.game.autofire = true;
|
||||
|
||||
@@ -135,12 +133,11 @@ bool loadOptionsFile(std::string filePath)
|
||||
}
|
||||
|
||||
// Normaliza los valores
|
||||
const bool a = options.video.mode == 0;
|
||||
const bool b = options.video.mode == SDL_WINDOW_FULLSCREEN;
|
||||
const bool c = options.video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
if (!(a || b || c))
|
||||
const bool a = options.video.mode == screenVideoMode::WINDOW;
|
||||
const bool b = options.video.mode == screenVideoMode::FULLSCREEN;
|
||||
if (!(a || b))
|
||||
{
|
||||
options.video.mode = SCREEN_VIDEO_MODE_WINDOW;
|
||||
options.video.mode = screenVideoMode::WINDOW;
|
||||
}
|
||||
|
||||
if (options.video.window.size < 1 || options.video.window.size > 4)
|
||||
@@ -175,29 +172,26 @@ bool saveOptionsFile(std::string filePath)
|
||||
#endif
|
||||
|
||||
// Opciones de video
|
||||
const auto valueVideoModeWinow = std::to_string(static_cast<int>(screenVideoMode::WINDOW));
|
||||
const auto valueVideoModeFullscreen = std::to_string(static_cast<int>(screenVideoMode::FULLSCREEN));
|
||||
const auto valueFilterNearest = std::to_string(static_cast<int>(screenFilter::NEAREST));
|
||||
const auto valueFilterLineal = std::to_string(static_cast<int>(screenFilter::LINEAL));
|
||||
|
||||
file << "## VIDEO\n";
|
||||
file << "## video.mode [0: window, 1: full screen]\n";
|
||||
file << "## video.filter [0: nearest, 1: lineal]\n";
|
||||
file << "## video.mode [" << valueVideoModeWinow << ": window, " << valueVideoModeFullscreen << ": fullscreen]\n";
|
||||
file << "## video.filter [" << valueFilterNearest << ": nearest, " << valueFilterLineal << ": lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
if (options.video.mode == SCREEN_VIDEO_MODE_WINDOW)
|
||||
{
|
||||
file << "video.mode=0\n";
|
||||
}
|
||||
|
||||
else if (options.video.mode == SCREEN_VIDEO_MODE_FULLSCREEN)
|
||||
{
|
||||
file << "video.mode=1\n";
|
||||
}
|
||||
const auto valueVideoMode = std::to_string(static_cast<int>(options.video.mode));
|
||||
file << "video.mode=" << valueVideoMode << "\n";
|
||||
|
||||
file << "video.window.size=" + std::to_string(options.video.window.size) + "\n";
|
||||
|
||||
options.video.filter == SCREEN_FILTER_NEAREST ? file << "video.filter=0\n" : file << "video.filter=1\n";
|
||||
const auto valueFilter = std::to_string(static_cast<int>(options.video.filter));
|
||||
file << "video.filter=" << valueFilter << "\n";
|
||||
|
||||
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
|
||||
file << "video.vSync=" + boolToString(options.video.vSync) + "\n";
|
||||
file << "video.integerScale=" + boolToString(options.video.integerScale) + "\n";
|
||||
file << "video.keepAspect=" + boolToString(options.video.keepAspect) + "\n";
|
||||
|
||||
// Opciones de notificaciones
|
||||
file << "\n\n## NOTIFICATION\n";
|
||||
@@ -243,13 +237,16 @@ bool saveOptionsFile(std::string filePath)
|
||||
file << "audio.sound.volume=" + std::to_string(options.audio.sound.volume) + "\n";
|
||||
|
||||
// Opciones del juego
|
||||
const auto valueDifficultyEasy = std::to_string(static_cast<int>(gameDifficulty::EASY));
|
||||
const auto valueDifficultyNormal = std::to_string(static_cast<int>(gameDifficulty::NORMAL));
|
||||
const auto valueDifficultyHard = std::to_string(static_cast<int>(gameDifficulty::HARD));
|
||||
file << "\n\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [0: easy, 1: normal, 2: hard]\n";
|
||||
file << "## game.difficulty [" << valueDifficultyEasy << ": easy, " << valueDifficultyNormal << ": normal, " << valueDifficultyHard << ": hard]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "game.language=" + std::to_string(options.game.language) + "\n";
|
||||
file << "game.difficulty=" + std::to_string(options.game.difficulty) + "\n";
|
||||
file << "game.difficulty=" + std::to_string(static_cast<int>(options.game.difficulty)) + "\n";
|
||||
file << "game.autofire=" + boolToString(options.game.autofire) + "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
@@ -289,7 +286,8 @@ bool setOptions(std::string var, std::string value)
|
||||
// Opciones de video
|
||||
if (var == "video.mode")
|
||||
{
|
||||
options.video.mode = value == std::to_string(SCREEN_VIDEO_MODE_WINDOW) ? SCREEN_VIDEO_MODE_WINDOW : SCREEN_VIDEO_MODE_FULLSCREEN;
|
||||
//options.video.mode = value == std::to_string(static_cast<int>(screenVideoMode::WINDOW)) ? screenVideoMode::WINDOW : screenVideoMode::FULLSCREEN;
|
||||
options.video.mode = static_cast<screenVideoMode>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "video.window.size")
|
||||
@@ -303,7 +301,8 @@ bool setOptions(std::string var, std::string value)
|
||||
|
||||
else if (var == "video.filter")
|
||||
{
|
||||
options.video.filter = value == std::to_string(SCREEN_FILTER_NEAREST) ? SCREEN_FILTER_NEAREST : SCREEN_FILTER_LINEAL;
|
||||
//options.video.filter = value == std::to_string(static_cast<int>(screenFilter::NEAREST)) ? screenFilter::NEAREST : screenFilter::LINEAL;
|
||||
options.video.filter = static_cast<screenFilter>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "video.shaders")
|
||||
@@ -316,16 +315,6 @@ bool setOptions(std::string var, std::string value)
|
||||
options.video.vSync = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.integerScale")
|
||||
{
|
||||
options.video.integerScale = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.keepAspect")
|
||||
{
|
||||
options.video.keepAspect = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de notificaciones
|
||||
else if (var == "notification.posH")
|
||||
{
|
||||
@@ -382,7 +371,7 @@ bool setOptions(std::string var, std::string value)
|
||||
|
||||
else if (var == "game.difficulty")
|
||||
{
|
||||
options.game.difficulty = std::stoi(value);
|
||||
options.game.difficulty = static_cast<gameDifficulty>(std::stoi(value));
|
||||
}
|
||||
|
||||
else if (var == "game.autofire")
|
||||
|
||||
@@ -9,13 +9,30 @@
|
||||
#include "text.h" // for Text
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
asset = Asset::get();
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Scoreboard *Scoreboard::scoreboard = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto scoreboard con esta función estática
|
||||
void Scoreboard::init(SDL_Renderer *renderer)
|
||||
{
|
||||
Scoreboard::scoreboard = new Scoreboard(renderer);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto scoreboard con esta función estática
|
||||
void Scoreboard::destroy()
|
||||
{
|
||||
delete Scoreboard::scoreboard;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto scoreboard y podemos trabajar con él
|
||||
Scoreboard *Scoreboard::get()
|
||||
{
|
||||
return Scoreboard::scoreboard;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(SDL_Renderer *renderer) : renderer(renderer)
|
||||
{
|
||||
// Inicializa punteros
|
||||
gamePowerMeterTexture = nullptr;
|
||||
powerMeterSprite = nullptr;
|
||||
@@ -47,9 +64,9 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||
recalculateAnchors();
|
||||
|
||||
// Crea objetos
|
||||
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
|
||||
powerMeterSprite = new Sprite(slot4_2.x - 20, slot4_2.y, 40, 7, gamePowerMeterTexture);
|
||||
textScoreBoard = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||
gamePowerMeterTexture = std::unique_ptr<Texture>(new Texture(renderer, Asset::get()->get("game_power_meter.png")));
|
||||
powerMeterSprite = std::unique_ptr<Sprite>(new Sprite(slot4_2.x - 20, slot4_2.y, 40, 7, gamePowerMeterTexture.get()));
|
||||
textScoreBoard = std::unique_ptr<Text>(new Text(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer));
|
||||
|
||||
// Crea la textura de fondo
|
||||
background = nullptr;
|
||||
@@ -64,14 +81,11 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
||||
|
||||
Scoreboard::~Scoreboard()
|
||||
{
|
||||
gamePowerMeterTexture->unload();
|
||||
delete gamePowerMeterTexture;
|
||||
delete powerMeterSprite;
|
||||
delete textScoreBoard;
|
||||
if (background)
|
||||
{
|
||||
SDL_DestroyTexture(background);
|
||||
}
|
||||
|
||||
for (auto texture : panelTexture)
|
||||
{
|
||||
if (texture)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for color_t
|
||||
#include <memory>
|
||||
class Asset;
|
||||
class Sprite;
|
||||
class Text;
|
||||
@@ -42,12 +43,16 @@ struct panel_t
|
||||
class Scoreboard
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto scoreboard privado para Don Melitón
|
||||
static Scoreboard *scoreboard;
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase
|
||||
Sprite *powerMeterSprite; // Sprite para el medidor de poder de la fase
|
||||
Text *textScoreBoard; // Fuente para el marcador del juego
|
||||
|
||||
std::unique_ptr<Texture> gamePowerMeterTexture; // Textura con el marcador de poder de la fase
|
||||
std::unique_ptr<Sprite> powerMeterSprite; // Sprite para el medidor de poder de la fase
|
||||
std::unique_ptr<Text> textScoreBoard; // Fuente para el marcador del juego
|
||||
|
||||
SDL_Texture *background; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture *> panelTexture; // Texturas para dibujar cada panel;
|
||||
|
||||
@@ -96,13 +101,24 @@ private:
|
||||
// Dibuja la linea que separa la zona de juego del marcador
|
||||
void renderSeparator();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados
|
||||
|
||||
// Constructor
|
||||
Scoreboard(SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Scoreboard();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto scoreboard con esta función estática
|
||||
static void init(SDL_Renderer *renderer);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto scoreboard con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto scoreboard y podemos trabajar con él
|
||||
static Scoreboard *get();
|
||||
|
||||
// Actualiza la lógica del marcador
|
||||
void update();
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "input.h" // for Input, inputs_e, INPUT_DO_NOT_ALLOW_REPEAT
|
||||
#include "notify.h" // for Notify
|
||||
#include "options.h" // for options
|
||||
#include "param.h"
|
||||
#include "on_screen_help.h"
|
||||
#include "global_inputs.h"
|
||||
|
||||
@@ -48,10 +49,8 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) : window(window), ren
|
||||
asset = Asset::get();
|
||||
|
||||
// Inicializa variables
|
||||
SDL_GetRendererOutputSize(renderer, &windowWidth, &windowHeight);
|
||||
gameCanvasWidth = options.video.gameWidth;
|
||||
gameCanvasHeight = options.video.gameHeight;
|
||||
dest = {0, 0, 0, 0};
|
||||
srcrect = {0, 0, param.game.width, param.game.height};
|
||||
dstrect = {0, 0, param.game.width, param.game.height};
|
||||
borderColor = {0, 0, 0};
|
||||
flashEffect.enabled = false;
|
||||
flashEffect.counter = 0;
|
||||
@@ -77,13 +76,13 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) : window(window), ren
|
||||
infoResolution = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, "", asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"));
|
||||
notify = std::make_unique<Notify>(renderer, "", asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"));
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
borderColor = {0x00, 0x00, 0x00};
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options.video.mode);
|
||||
@@ -95,7 +94,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) : window(window), ren
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
delete notify;
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
}
|
||||
|
||||
@@ -142,7 +140,7 @@ void Screen::blit()
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, nullptr);
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
@@ -156,12 +154,8 @@ void Screen::blit()
|
||||
// Vuelve a dejar el renderizador en modo normal
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Borra el contenido previo
|
||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||
SDL_RenderCopy(renderer, gameCanvas, &srcrect, nullptr);
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
@@ -170,17 +164,18 @@ void Screen::blit()
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
void Screen::setVideoMode(int videoMode)
|
||||
void Screen::setVideoMode(screenVideoMode videoMode)
|
||||
{
|
||||
options.video.mode = videoMode;
|
||||
#ifdef ARCADE
|
||||
videoMode = SCREEN_VIDEO_MODE_WINDOW;
|
||||
// videoMode = SCREEN_VIDEO_MODE_FULLSCREEN;
|
||||
options.video.mode = screenVideoMode::WINDOW;
|
||||
#endif
|
||||
|
||||
// Si está activo el modo ventana quita el borde
|
||||
if (videoMode == SCREEN_VIDEO_MODE_WINDOW)
|
||||
switch (options.video.mode)
|
||||
{
|
||||
// Aplica el modo de video
|
||||
case screenVideoMode::WINDOW:
|
||||
{
|
||||
// Cambia a modo de ventana
|
||||
SDL_SetWindowFullscreen(window, 0);
|
||||
|
||||
#ifdef ARCADE
|
||||
@@ -190,86 +185,29 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
#endif
|
||||
|
||||
windowWidth = gameCanvasWidth;
|
||||
windowHeight = gameCanvasHeight;
|
||||
dest = {0, 0, windowWidth, windowHeight};
|
||||
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_SetWindowSize(window, windowWidth * options.video.window.size, windowHeight * options.video.window.size);
|
||||
SDL_SetWindowSize(window, param.game.width * options.video.window.size, param.game.height * options.video.window.size);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Si está activo el modo de pantalla completa añade el borde
|
||||
else if (videoMode == SCREEN_VIDEO_MODE_FULLSCREEN)
|
||||
case screenVideoMode::FULLSCREEN:
|
||||
{
|
||||
// Aplica el modo de video
|
||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
#ifdef ARCADE
|
||||
/*SDL_DisplayMode DM;
|
||||
DM.w = 1024;
|
||||
DM.h = 600;
|
||||
DM.refresh_rate = 60;
|
||||
if (!SDL_SetWindowDisplayMode(window, &DM))
|
||||
{
|
||||
std::cout << SDL_GetError() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Changed windows display mode" << std::endl;
|
||||
}*/
|
||||
#endif
|
||||
|
||||
// Oculta el puntero
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
// Obten el alto y el ancho de la ventana
|
||||
// SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||
|
||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||
if (options.video.integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
|
||||
{
|
||||
scale++;
|
||||
break;
|
||||
}
|
||||
|
||||
dest.w = gameCanvasWidth * scale;
|
||||
dest.h = gameCanvasHeight * scale;
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else if (options.video.keepAspect)
|
||||
{
|
||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
||||
{
|
||||
dest.h = windowHeight;
|
||||
dest.w = (int)((windowHeight * ratio) + 0.5f);
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.w = windowWidth;
|
||||
dest.h = (int)((windowWidth / ratio) + 0.5f);
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// dest = {0, 0, windowWidth, windowHeight};
|
||||
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef NO_SHADERS
|
||||
// El renderizador pasa a tener el tamaño de la pantalla en fullscreen o del juego en modo ventana
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
#else
|
||||
// Reinicia los shaders
|
||||
if (options.video.shaders)
|
||||
{
|
||||
@@ -279,28 +217,14 @@ void Screen::setVideoMode(int videoMode)
|
||||
shader::init(window, gameCanvas, source.c_str());
|
||||
}
|
||||
|
||||
// Modifica el tamaño del renderizador
|
||||
else
|
||||
{
|
||||
// El renderizador pasa a tener el tamaño de la pantalla en fullscreen o del juego en modo ventana
|
||||
// SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
SDL_RenderSetLogicalSize(renderer, gameCanvasWidth, gameCanvasHeight);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Actualiza las opciones
|
||||
options.video.mode = videoMode;
|
||||
options.video.window.width = windowWidth;
|
||||
options.video.window.height = windowHeight;
|
||||
|
||||
// Actualiza variables
|
||||
shakeEffect.origin = dest.x;
|
||||
shakeEffect.origin = srcrect.x;
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
options.video.mode = options.video.mode == SCREEN_VIDEO_MODE_WINDOW ? SCREEN_VIDEO_MODE_FULLSCREEN : SCREEN_VIDEO_MODE_WINDOW;
|
||||
options.video.mode = options.video.mode == screenVideoMode::WINDOW ? screenVideoMode::FULLSCREEN : screenVideoMode::WINDOW;
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
@@ -308,7 +232,7 @@ void Screen::switchVideoMode()
|
||||
void Screen::setWindowSize(int size)
|
||||
{
|
||||
options.video.window.size = size;
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
setVideoMode(screenVideoMode::WINDOW);
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
@@ -316,7 +240,7 @@ void Screen::decWindowSize()
|
||||
{
|
||||
--options.video.window.size;
|
||||
options.video.window.size = std::max(options.video.window.size, 1);
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
setVideoMode(screenVideoMode::WINDOW);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
@@ -324,7 +248,7 @@ void Screen::incWindowSize()
|
||||
{
|
||||
++options.video.window.size;
|
||||
options.video.window.size = std::min(options.video.window.size, 4);
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
setVideoMode(screenVideoMode::WINDOW);
|
||||
}
|
||||
|
||||
// Cambia el color del borde
|
||||
@@ -356,7 +280,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options.video.mode == SCREEN_VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||
const std::string mode = options.video.mode == screenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||
showNotification(mode + " mode");
|
||||
return;
|
||||
}
|
||||
@@ -420,7 +344,7 @@ void Screen::shake()
|
||||
// Si ya hay un shake effect en marcha no se pilla el origen, solo se renuevan los contadores
|
||||
if (shakeEffect.remaining == 0)
|
||||
{
|
||||
shakeEffect.origin = dest.x;
|
||||
shakeEffect.origin = srcrect.x;
|
||||
}
|
||||
|
||||
shakeEffect.remaining = shakeEffect.lenght;
|
||||
@@ -439,14 +363,14 @@ void Screen::updateShake()
|
||||
else
|
||||
{
|
||||
shakeEffect.counter = shakeEffect.delay;
|
||||
const int desp = shakeEffect.remaining % 2 == 0 ? shakeEffect.desp * (-1) : shakeEffect.desp;
|
||||
dest.x = shakeEffect.origin + desp;
|
||||
const auto desp = shakeEffect.remaining % 2 == 0 ? shakeEffect.desp * (-1) : shakeEffect.desp;
|
||||
srcrect.x = shakeEffect.origin + desp;
|
||||
shakeEffect.remaining--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.x = shakeEffect.origin;
|
||||
srcrect.x = shakeEffect.origin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +458,7 @@ void Screen::displayInfo()
|
||||
{
|
||||
// FPS
|
||||
const std::string fpstext = std::to_string(fps) + " FPS";
|
||||
dbg_print(gameCanvasWidth - fpstext.length() * 8, 0, fpstext.c_str(), 255, 255, 0);
|
||||
dbg_print(param.game.width - fpstext.length() * 8, 0, fpstext.c_str(), 255, 255, 0);
|
||||
|
||||
// Resolution
|
||||
dbg_print(0, 0, infoResolution.c_str(), 255, 255, 0);
|
||||
|
||||
@@ -7,15 +7,22 @@
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <string> // for basic_string, string
|
||||
#include "utils.h" // for color_t
|
||||
#include <memory>
|
||||
class Asset;
|
||||
class Input;
|
||||
class Notify;
|
||||
|
||||
#define SCREEN_FILTER_NEAREST 0
|
||||
#define SCREEN_FILTER_LINEAL 1
|
||||
enum class screenFilter
|
||||
{
|
||||
NEAREST = 0,
|
||||
LINEAL = 1,
|
||||
};
|
||||
|
||||
#define SCREEN_VIDEO_MODE_WINDOW 0
|
||||
#define SCREEN_VIDEO_MODE_FULLSCREEN 1
|
||||
enum class screenVideoMode
|
||||
{
|
||||
WINDOW = 0,
|
||||
FULLSCREEN = 1,
|
||||
};
|
||||
|
||||
class Screen
|
||||
{
|
||||
@@ -28,15 +35,12 @@ private:
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con el listado de recursos
|
||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||
Notify *notify; // Pinta notificaciones en pantalla
|
||||
std::unique_ptr<Notify> notify; // Pinta notificaciones en pantalla
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
|
||||
// Variables
|
||||
int windowWidth; // Ancho de la pantalla o ventana
|
||||
int windowHeight; // Alto de la pantalla o ventana
|
||||
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
SDL_Rect srcrect; // Coordenadas de donde va a pillar la textura del juego para dibujarla
|
||||
SDL_Rect dstrect; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
bool attenuateEffect; // Indica si la pantalla ha de estar atenuada
|
||||
Uint32 fpsTicks; // Ticks para contar los frames por segundo
|
||||
@@ -81,7 +85,6 @@ private:
|
||||
// Muestra información por pantalla
|
||||
void displayInfo();
|
||||
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -116,7 +119,7 @@ public:
|
||||
void blit();
|
||||
|
||||
// Establece el modo de video
|
||||
void setVideoMode(int videoMode);
|
||||
void setVideoMode(screenVideoMode videoMode);
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void switchVideoMode();
|
||||
|
||||
@@ -2,19 +2,8 @@
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture)
|
||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture) : x(x), y(y), w(w), h(h), texture(texture)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
@@ -22,19 +11,8 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture)
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, Texture *texture)
|
||||
Sprite::Sprite(SDL_Rect rect, Texture *texture): x(rect.x), y(rect.y), w(rect.w), h(rect.h), texture(texture)
|
||||
{
|
||||
// Establece la posición X,Y del sprite
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
|
||||
// Establece el alto y el ancho del sprite
|
||||
w = rect.w;
|
||||
h = rect.h;
|
||||
|
||||
// Establece la textura donde están los gráficos para el sprite
|
||||
this->texture = texture;
|
||||
|
||||
// Establece el rectangulo de donde coger la imagen
|
||||
spriteClip = {0, 0, w, h};
|
||||
|
||||
@@ -58,25 +36,25 @@ void Sprite::render()
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosX()
|
||||
int Sprite::getPosX() const
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getPosY()
|
||||
int Sprite::getPosY() const
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getWidth()
|
||||
int Sprite::getWidth() const
|
||||
{
|
||||
return w;
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
int Sprite::getHeight()
|
||||
int Sprite::getHeight() const
|
||||
{
|
||||
return h;
|
||||
}
|
||||
@@ -122,7 +100,7 @@ void Sprite::setHeight(int h)
|
||||
}
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect Sprite::getSpriteClip()
|
||||
SDL_Rect Sprite::getSpriteClip() const
|
||||
{
|
||||
return spriteClip;
|
||||
}
|
||||
@@ -158,16 +136,15 @@ void Sprite::setEnabled(bool value)
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool Sprite::isEnabled()
|
||||
bool Sprite::isEnabled() const
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect Sprite::getRect()
|
||||
SDL_Rect Sprite::getRect() const
|
||||
{
|
||||
SDL_Rect rect = {x, y, w, h};
|
||||
return rect;
|
||||
return (SDL_Rect){x, y, w, h};
|
||||
}
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
|
||||
@@ -20,7 +20,7 @@ protected:
|
||||
public:
|
||||
// Constructor
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr);
|
||||
Sprite(SDL_Rect rect, Texture *texture);
|
||||
Sprite(SDL_Rect rect, Texture *texture = nullptr);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
@@ -29,16 +29,16 @@ public:
|
||||
void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX();
|
||||
int getPosX() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosY();
|
||||
int getPosY() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getWidth();
|
||||
int getWidth() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getHeight();
|
||||
int getHeight() const;
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Point p);
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
void setHeight(int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip();
|
||||
SDL_Rect getSpriteClip() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(SDL_Rect rect);
|
||||
@@ -81,10 +81,10 @@ public:
|
||||
void setEnabled(bool value);
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool isEnabled();
|
||||
bool isEnabled() const;
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
SDL_Rect getRect() const;
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
|
||||
@@ -10,11 +10,16 @@
|
||||
#include "input.h" // for inputs_e
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
enum class screenFilter;
|
||||
enum class screenVideoMode;
|
||||
|
||||
// Dificultad del juego
|
||||
#define DIFFICULTY_EASY 0
|
||||
#define DIFFICULTY_NORMAL 1
|
||||
#define DIFFICULTY_HARD 2
|
||||
enum class gameDifficulty
|
||||
{
|
||||
EASY = 0,
|
||||
NORMAL = 1,
|
||||
HARD = 2,
|
||||
};
|
||||
|
||||
// Tamaño de bloque
|
||||
#define BLOCK 8
|
||||
@@ -22,9 +27,7 @@ struct JA_Sound_t;
|
||||
// Estructura para definir un circulo
|
||||
struct circle_t
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int r;
|
||||
int x, y, r;
|
||||
};
|
||||
|
||||
// Estructura para definir una linea horizontal
|
||||
@@ -54,9 +57,7 @@ struct line_t
|
||||
// Estructura para definir un color
|
||||
struct color_t
|
||||
{
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
Uint8 r, g, b;
|
||||
};
|
||||
|
||||
// Posiciones de las notificaciones
|
||||
@@ -97,22 +98,16 @@ struct demoKeys_t
|
||||
// Estructura para las opciones de la ventana
|
||||
struct op_window_t
|
||||
{
|
||||
int width; // Ancho de la ventana
|
||||
int height; // Alto de la ventana
|
||||
int size; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||
};
|
||||
|
||||
// Estructura con opciones para el video
|
||||
struct op_video_t
|
||||
{
|
||||
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||
int gameHeight; // Alto de la resolucion nativa del juego
|
||||
op_window_t window; // Opciones para la ventana del programa
|
||||
Uint32 mode; // Contiene el valor del modo de pantalla completa
|
||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||
screenVideoMode mode; // Contiene el valor del modo de pantalla completa
|
||||
screenFilter filter; // Filtro usado para el escalado de la imagen
|
||||
bool vSync; // Indica si se quiere usar vsync o no
|
||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
bool shaders; // Indica si se van a usar shaders para los filtros de video
|
||||
};
|
||||
|
||||
@@ -140,7 +135,7 @@ struct op_audio_t
|
||||
// Estructura para las opciones del juego
|
||||
struct op_game_t
|
||||
{
|
||||
Uint8 difficulty; // Dificultad del juego
|
||||
gameDifficulty difficulty; // Dificultad del juego
|
||||
Uint8 language; // Idioma usado en el juego
|
||||
bool autofire; // Indica si el jugador ha de pulsar repetidamente para disparar o basta con mantener pulsado
|
||||
std::vector<hiScoreEntry_t> hiScoreTable; // Tabla con las mejores puntuaciones
|
||||
|
||||
Reference in New Issue
Block a user