Compare commits
14 Commits
2025-02-07
...
9c1b3c45b0
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c1b3c45b0 | |||
| 79b2917112 | |||
| c88a277cba | |||
| e0c10f83d6 | |||
| 72cb39da78 | |||
| 9f8d1fbcd7 | |||
| e523692e99 | |||
| 83bdd67cee | |||
| 66e5105c84 | |||
| f8449ea6d1 | |||
| f43d18e6f0 | |||
| a42141ebd7 | |||
| 29c85fecad | |||
| 04ff428aa0 |
@@ -3,6 +3,9 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(coffee_crisis_arcade_edition VERSION 0.01)
|
||||
|
||||
# Establece las políticas
|
||||
cmake_policy(SET CMP0072 NEW)
|
||||
|
||||
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
set(CMAKE_CXX_COMPILER "g++")
|
||||
|
||||
@@ -11,7 +11,7 @@ Coffee Crisis Arcade Edition és una versió ampliada i millorada del aclamat Co
|
||||
Defensa el teu cafè contra les bambolles gegants en aquest trepidant joc d'arcade! 🍵
|
||||
|
||||
<p align="center">
|
||||
<img src="https://php.sustancia.synology.me/images/ccae_title.png" alt="Títol" width="60%" />
|
||||
<img src="https://php.sustancia.synology.me/images/ccae/ccae_title.png" alt="Títol" width="60%" />
|
||||
</p>
|
||||
|
||||
## Controls
|
||||
@@ -25,8 +25,8 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
|
||||
> Nota: El joc suporta nomes un jugador amb teclat.
|
||||
|
||||
<p align="center">
|
||||
<img src="https://php.sustancia.synology.me/images/ccae1.png" alt="Joc" width="45%" />
|
||||
<img src="https://php.sustancia.synology.me/images/ccae3.png" alt="Joc" width="45%" />
|
||||
<img src="https://php.sustancia.synology.me/images/ccae/ccae1.png" alt="Joc" width="45%" />
|
||||
<img src="https://php.sustancia.synology.me/images/ccae/ccae3.png" alt="Joc" width="45%" />
|
||||
</p>
|
||||
|
||||
## Altres tecles
|
||||
@@ -44,7 +44,7 @@ El joc està optimitzat per a ser jugat amb un mando de jocs, encara que un dels
|
||||
| **F10** | Reset del joc |
|
||||
|
||||
<p align="center">
|
||||
<img src="https://php.sustancia.synology.me/images/ccae2.png" alt="Joc" width="50%" />
|
||||
<img src="https://php.sustancia.synology.me/images/ccae/ccae2.png" alt="Joc" width="50%" />
|
||||
</p>
|
||||
|
||||
## Com instal·lar i jugar
|
||||
|
||||
|
Before Width: | Height: | Size: 13 KiB |
BIN
data/gfx/intro/intro1.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
data/gfx/intro/intro2.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
data/gfx/intro/intro3.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
data/gfx/intro/intro4.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
data/gfx/intro/intro5.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
data/gfx/intro/intro6.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
@@ -371,4 +371,13 @@ GRAFICS DIBUIXATS PER
|
||||
MUSICA COMPOSADA PER
|
||||
|
||||
## 124 - CREDITS
|
||||
EFECTES DE SO
|
||||
EFECTES DE SO
|
||||
|
||||
## 125 - NOTIFICACIONES
|
||||
Torna a polsar per reiniciar
|
||||
|
||||
## 126 - NOTIFICACIONES
|
||||
Torna a polsar per canviar el idioma a
|
||||
|
||||
## 127 - NOTIFICACIONES
|
||||
Idioma canviat a
|
||||
@@ -371,4 +371,13 @@ PIXELART DRAWN BY
|
||||
MUSIC COMPOSED BY
|
||||
|
||||
## 124 - CREDITS
|
||||
SOUND EFFECTS
|
||||
SOUND EFFECTS
|
||||
|
||||
## 125 - NOTIFICACIONES
|
||||
Press again to reset
|
||||
|
||||
## 126 - NOTIFICACIONES
|
||||
Press again to change languaje to
|
||||
|
||||
## 127 - NOTIFICACIONES
|
||||
Language set to
|
||||
@@ -371,4 +371,13 @@ GRAFICOS DIBUJADOS POR
|
||||
MUSICA COMPUESTA POR
|
||||
|
||||
## 124 - CREDITS
|
||||
EFECTOS DE SONIDO
|
||||
EFECTOS DE SONIDO
|
||||
|
||||
## 125 - NOTIFICACIONES
|
||||
Vuelve a pulsar para reiniciar
|
||||
|
||||
## 126 - NOTIFICACIONES
|
||||
Vuelve a pulsar para cambiar el idioma a
|
||||
|
||||
## 127 - NOTIFICACIONES
|
||||
Idioma cambiado a
|
||||
@@ -56,13 +56,13 @@ private:
|
||||
~Asset() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(const std::string &executable_path);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Asset *get();
|
||||
|
||||
// Añade un elemento a la lista
|
||||
|
||||
@@ -101,6 +101,7 @@ void Director::init()
|
||||
dbg_init(renderer_);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
Screen::init(window_, renderer_);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
Resource::init();
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
@@ -316,12 +317,10 @@ bool Director::initSDL()
|
||||
std::cout << "Warning: texture filtering not enabled!\n";
|
||||
}
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||
{
|
||||
std::cout << "Warning: opengl not enabled!\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Crea la ventana
|
||||
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
|
||||
@@ -339,10 +338,8 @@ bool Director::initSDL()
|
||||
flags = SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
// La aceleración se activa según el define
|
||||
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
|
||||
#endif
|
||||
|
||||
renderer_ = SDL_CreateRenderer(window_, -1, flags);
|
||||
|
||||
@@ -477,7 +474,12 @@ void Director::setFileList()
|
||||
}
|
||||
|
||||
{ // Intro
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro1.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro2.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro3.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro4.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro5.png", AssetType::BITMAP);
|
||||
Asset::get()->add(prefix + "/data/gfx/intro/intro6.png", AssetType::BITMAP);
|
||||
}
|
||||
|
||||
{ // Logo
|
||||
@@ -553,7 +555,9 @@ void Director::setFileList()
|
||||
|
||||
// Si falta algun fichero, sale del programa
|
||||
if (!Asset::get()->check())
|
||||
{
|
||||
throw std::runtime_error("Falta algun fichero");
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
|
||||
@@ -13,7 +13,7 @@ EnterName::EnterName()
|
||||
void EnterName::init(const std::string &name)
|
||||
{
|
||||
// No se pasa ningún nombre
|
||||
if (name == "")
|
||||
if (name.empty())
|
||||
{
|
||||
name_ = "A";
|
||||
position_ = 0;
|
||||
@@ -24,7 +24,7 @@ void EnterName::init(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
position_ = name_.length();
|
||||
position_overflow_ = position_ >= NAME_LENGHT ? true : false;
|
||||
position_overflow_ = position_ >= MAX_NAME_LENGHT ? true : false;
|
||||
}
|
||||
|
||||
// Inicializa el vector de indices con el nombre y espacios
|
||||
@@ -42,15 +42,15 @@ void EnterName::incPosition()
|
||||
|
||||
++position_;
|
||||
|
||||
if (position_ >= NAME_LENGHT)
|
||||
if (position_ >= MAX_NAME_LENGHT)
|
||||
{
|
||||
position_ = NAME_LENGHT; // Mantenemos en el índice máximo válido.
|
||||
position_overflow_ = true; // Activamos el flag de overflow.
|
||||
position_ = MAX_NAME_LENGHT; // Mantenemos en el índice máximo válido.
|
||||
position_overflow_ = true; // Activamos el flag de overflow.
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copiamos el índice del carácter anterior si es posible.
|
||||
if (position_ > 0 && position_ < NAME_LENGHT)
|
||||
if (position_ > 0 && position_ < MAX_NAME_LENGHT)
|
||||
{
|
||||
character_index_[position_] = character_index_[position_ - 1];
|
||||
}
|
||||
@@ -71,7 +71,7 @@ void EnterName::decPosition()
|
||||
{
|
||||
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
|
||||
position_overflow_ = false;
|
||||
position_ = NAME_LENGHT - 1;
|
||||
position_ = MAX_NAME_LENGHT - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -80,7 +80,7 @@ void EnterName::decPosition()
|
||||
--position_;
|
||||
|
||||
// Limpiamos el carácter siguiente si el índice es válido.
|
||||
if (position_ + 1 < NAME_LENGHT)
|
||||
if (position_ + 1 < MAX_NAME_LENGHT)
|
||||
{
|
||||
character_index_[position_ + 1] = 0;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void EnterName::decPosition()
|
||||
}
|
||||
|
||||
// Si position_ es menor que NAME_LENGHT, aseguramos que el overflow esté desactivado.
|
||||
if (position_ < NAME_LENGHT)
|
||||
if (position_ < MAX_NAME_LENGHT)
|
||||
{
|
||||
position_overflow_ = false;
|
||||
}
|
||||
@@ -102,7 +102,6 @@ void EnterName::decPosition()
|
||||
updateNameFromCharacterIndex();
|
||||
}
|
||||
|
||||
|
||||
// Incrementa el índice
|
||||
void EnterName::incIndex()
|
||||
{
|
||||
@@ -126,7 +125,7 @@ void EnterName::decIndex()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
--character_index_[position_];
|
||||
if (character_index_[position_] < 0)
|
||||
{
|
||||
@@ -139,7 +138,7 @@ void EnterName::decIndex()
|
||||
void EnterName::updateNameFromCharacterIndex()
|
||||
{
|
||||
name_.clear();
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
for (int i = 0; i < MAX_NAME_LENGHT; ++i)
|
||||
{
|
||||
name_.push_back(character_list_[character_index_[i]]);
|
||||
}
|
||||
@@ -150,13 +149,13 @@ void EnterName::updateNameFromCharacterIndex()
|
||||
void EnterName::initCharacterIndex(const std::string &name)
|
||||
{
|
||||
// Rellena de espacios
|
||||
for (size_t i = 0; i < NAME_LENGHT; ++i)
|
||||
for (size_t i = 0; i < MAX_NAME_LENGHT; ++i)
|
||||
{
|
||||
character_index_[i] = 0;
|
||||
}
|
||||
|
||||
// Coloca los índices en función de los caracteres que forman el nombre
|
||||
for (size_t i = 0; i < name.substr(0, NAME_LENGHT).size(); ++i)
|
||||
for (size_t i = 0; i < name.substr(0, MAX_NAME_LENGHT).size(); ++i)
|
||||
{
|
||||
character_index_[i] = findIndex(name.at(i));
|
||||
}
|
||||
@@ -166,7 +165,11 @@ void EnterName::initCharacterIndex(const std::string &name)
|
||||
int EnterName::findIndex(char character) const
|
||||
{
|
||||
for (size_t i = 0; i < character_list_.size(); ++i)
|
||||
{
|
||||
if (character == character_list_.at(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string>
|
||||
#include "utils.h"
|
||||
|
||||
constexpr int NAME_LENGHT = 6;
|
||||
constexpr int MAX_NAME_LENGHT = 6;
|
||||
|
||||
/*
|
||||
Un array, "characterList", contiene la lista de caracteres
|
||||
@@ -17,11 +17,11 @@ constexpr int NAME_LENGHT = 6;
|
||||
class EnterName
|
||||
{
|
||||
private:
|
||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||
std::string name_; // Nombre introducido
|
||||
int position_ = 0; // Posición a editar del nombre
|
||||
bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite
|
||||
int character_index_[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
std::string character_list_; // Lista de todos los caracteres permitidos
|
||||
std::string name_; // Nombre introducido
|
||||
int position_ = 0; // Posición a editar del nombre
|
||||
bool position_overflow_ = false; // Indica si hemos incrementado la posición más allá del límite
|
||||
int character_index_[MAX_NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
|
||||
// Actualiza el nombre a partir de la lista de índices
|
||||
void updateNameFromCharacterIndex();
|
||||
|
||||
@@ -1268,9 +1268,11 @@ void Game::checkEvents()
|
||||
case SDLK_3: // Activa el modo para pasar el juego automaticamente
|
||||
{
|
||||
auto_pop_balloons_ = !auto_pop_balloons_;
|
||||
Notifier::get()->showText({"auto advance: " + boolToString(auto_pop_balloons_)});
|
||||
Notifier::get()->show({"auto advance: " + boolToString(auto_pop_balloons_)});
|
||||
if (auto_pop_balloons_)
|
||||
{
|
||||
balloon_manager_->destroyAllBalloons();
|
||||
}
|
||||
balloon_manager_->setDeployBalloons(!auto_pop_balloons_);
|
||||
break;
|
||||
}
|
||||
@@ -1555,7 +1557,7 @@ void Game::handlePlayersInput()
|
||||
// Gestiona la continuación del jugador.
|
||||
handlePlayerContinue(player);
|
||||
}
|
||||
else if (player->isEnteringName() || player->isEnteringNameGameCompleted())
|
||||
else if (player->isEnteringName() || player->isEnteringNameGameCompleted() || player->isShowingName())
|
||||
{
|
||||
// Gestiona la introducción del nombre del jugador.
|
||||
handleNameInput(player);
|
||||
@@ -1650,7 +1652,11 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
|
||||
input_->checkInput(InputType::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
|
||||
input_->checkInput(InputType::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
|
||||
{
|
||||
if (player->getEnterNamePositionOverflow())
|
||||
if (player->isShowingName())
|
||||
{
|
||||
player->setPlayingState(PlayerState::CONTINUE);
|
||||
}
|
||||
else if (player->getEnterNamePositionOverflow())
|
||||
{
|
||||
player->setInput(InputType::START);
|
||||
addScoreToScoreBoard(player);
|
||||
|
||||
@@ -21,9 +21,8 @@ namespace globalInputs
|
||||
// Termina
|
||||
void quit(section::Options code)
|
||||
{
|
||||
const std::string exit_code = "QUIT";
|
||||
auto code_found = stringInVector(Notifier::get()->getCodes(), exit_code);
|
||||
if (code_found)
|
||||
const std::string CODE = "QUIT";
|
||||
if (Notifier::get()->checkCode(CODE))
|
||||
{
|
||||
// Si la notificación de salir está activa, cambia de sección
|
||||
section::name = section::Name::QUIT;
|
||||
@@ -33,10 +32,10 @@ namespace globalInputs
|
||||
{
|
||||
// Si la notificación de salir no está activa, muestra la notificación
|
||||
#ifdef ARCADE
|
||||
const int index = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||
Notifier::get()->showText({lang::getText(index), std::string()}, -1, exit_code);
|
||||
const int INDEX = code == section::Options::QUIT_WITH_CONTROLLER ? 116 : 94;
|
||||
Notifier::get()->showText({lang::getText(INDEX), std::string()}, -1, CODE);
|
||||
#else
|
||||
Notifier::get()->showText({lang::getText(94), std::string()}, -1, exit_code);
|
||||
Notifier::get()->show({lang::getText(94), std::string()}, -1, CODE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -44,8 +43,16 @@ namespace globalInputs
|
||||
// Reinicia
|
||||
void reset()
|
||||
{
|
||||
section::name = section::Name::INIT;
|
||||
Notifier::get()->showText({"Reset"});
|
||||
const std::string CODE = "RESET";
|
||||
if (Notifier::get()->checkCode(CODE))
|
||||
{
|
||||
section::name = section::Name::INIT;
|
||||
Notifier::get()->show({"Reset"});
|
||||
}
|
||||
else
|
||||
{
|
||||
Notifier::get()->show({lang::getText(125), std::string()}, -1, CODE);
|
||||
}
|
||||
}
|
||||
|
||||
// Activa o desactiva el audio
|
||||
@@ -62,7 +69,7 @@ namespace globalInputs
|
||||
JA_SetMusicVolume(0);
|
||||
JA_SetSoundVolume(0);
|
||||
}
|
||||
Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||
Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)});
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
@@ -88,13 +95,13 @@ namespace globalInputs
|
||||
switch (code)
|
||||
{
|
||||
case lang::Code::ba_BA:
|
||||
return "ba_BA";
|
||||
return " \"ba_BA\"";
|
||||
break;
|
||||
case lang::Code::es_ES:
|
||||
return "es_ES";
|
||||
return " \"es_ES\"";
|
||||
break;
|
||||
default:
|
||||
return "en_UK";
|
||||
return " \"en_UK\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -102,18 +109,27 @@ namespace globalInputs
|
||||
// Cambia el idioma
|
||||
void changeLang()
|
||||
{
|
||||
options.game.language = lang::change(options.game.language);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
section::name = section::Name::INIT;
|
||||
section::options = section::Options::RELOAD;
|
||||
Notifier::get()->showText({getLangName(options.game.language)});
|
||||
const std::string CODE = "LANG";
|
||||
if (Notifier::get()->checkCode(CODE))
|
||||
{
|
||||
options.game.language = lang::getNextLangCode(options.game.language);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
section::name = section::Name::INIT;
|
||||
section::options = section::Options::RELOAD;
|
||||
Notifier::get()->show({lang::getText(127) + getLangName(options.game.language)});
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto NEXT = lang::getNextLangCode(options.game.language);
|
||||
Notifier::get()->show({lang::getText(126) + getLangName(NEXT), std::string()}, -1, CODE);
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el modo de disparo
|
||||
void toggleFireMode()
|
||||
{
|
||||
options.game.autofire = !options.game.autofire;
|
||||
Notifier::get()->showText({"Autofire " + boolToOnOff(options.game.autofire)});
|
||||
Notifier::get()->show({"Autofire " + boolToOnOff(options.game.autofire)});
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
@@ -127,7 +143,7 @@ namespace globalInputs
|
||||
{
|
||||
Screen::get()->toggleVideoMode();
|
||||
const std::string mode = options.video.mode == ScreenVideoMode::WINDOW ? "Window" : "Fullscreen";
|
||||
Notifier::get()->showText({mode + " mode"});
|
||||
Notifier::get()->show({mode + " mode"});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,7 +152,7 @@ namespace globalInputs
|
||||
{
|
||||
Screen::get()->decWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
Notifier::get()->showText({"Window size x" + size});
|
||||
Notifier::get()->show({"Window size x" + size});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,7 +161,7 @@ namespace globalInputs
|
||||
{
|
||||
Screen::get()->incWindowSize();
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
Notifier::get()->showText({"Window size x" + size});
|
||||
Notifier::get()->show({"Window size x" + size});
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -9,22 +9,22 @@
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||
#include <utility> // Para pair
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
// [SINGLETON]
|
||||
Input *Input::input_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto input con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Input::init(const std::string &game_controller_db_path)
|
||||
{
|
||||
Input::input_ = new Input(game_controller_db_path);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto input con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Input::destroy()
|
||||
{
|
||||
delete Input::input_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto input y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Input *Input::get()
|
||||
{
|
||||
return Input::input_;
|
||||
|
||||
@@ -64,7 +64,7 @@ enum class InputDeviceToUse : int
|
||||
class Input
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
||||
// [SINGLETON] Objeto privado
|
||||
static Input *input_;
|
||||
|
||||
struct KeyBindings
|
||||
@@ -109,13 +109,13 @@ private:
|
||||
~Input() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(const std::string &game_controller_db_path);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Input *get();
|
||||
|
||||
// Asigna inputs a teclas
|
||||
|
||||
164
source/intro.cpp
@@ -17,84 +17,89 @@
|
||||
#include "utils.h" // Para Zone, BLOCK, Color, bg_color
|
||||
#include "writer.h" // Para Writer
|
||||
#include "mouse.h"
|
||||
#include <array>
|
||||
|
||||
// Constructor
|
||||
Intro::Intro()
|
||||
: texture_(Resource::get()->getTexture("intro.png")),
|
||||
text_(Resource::get()->getText("04b_25_metal"))
|
||||
{
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::Name::INTRO;
|
||||
section::options = section::Options::NONE;
|
||||
|
||||
const std::array<std::string, 6> BITMAP_LIST = {
|
||||
"intro1.png",
|
||||
"intro2.png",
|
||||
"intro3.png",
|
||||
"intro4.png",
|
||||
"intro5.png",
|
||||
"intro6.png"};
|
||||
|
||||
auto texture = Resource::get()->getTexture(BITMAP_LIST.front());
|
||||
const int BITMAP_WIDTH = texture->getWidth();
|
||||
const int BITMAP_HEIGHT = texture->getHeight();
|
||||
|
||||
// Inicializa los bitmaps de la intro
|
||||
constexpr int totalBitmaps = 6;
|
||||
for (int i = 0; i < totalBitmaps; ++i)
|
||||
constexpr int TOTAL_BITMAPS = 6;
|
||||
for (int i = 0; i < TOTAL_BITMAPS; ++i)
|
||||
{
|
||||
auto ss = std::make_unique<SmartSprite>(texture_);
|
||||
ss->setWidth(128);
|
||||
ss->setHeight(96);
|
||||
auto ss = std::make_unique<SmartSprite>(Resource::get()->getTexture(BITMAP_LIST.at(i)));
|
||||
ss->setWidth(BITMAP_WIDTH);
|
||||
ss->setHeight(BITMAP_HEIGHT);
|
||||
ss->setSpriteClip(0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
|
||||
ss->setFinishedCounter(20);
|
||||
ss->setDestX(param.game.game_area.center_x - 64);
|
||||
ss->setDestY(param.game.game_area.first_quarter_y - 24);
|
||||
ss->setDestX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||
ss->setDestY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||
bitmaps_.push_back(std::move(ss));
|
||||
}
|
||||
|
||||
bitmaps_[0]->setPosX(-128);
|
||||
bitmaps_[0]->setPosY(param.game.game_area.first_quarter_y - 24);
|
||||
bitmaps_[0]->setVelX(0.0f);
|
||||
bitmaps_[0]->setVelY(0.0f);
|
||||
bitmaps_[0]->setAccelX(0.6f);
|
||||
bitmaps_[0]->setAccelY(0.0f);
|
||||
bitmaps_[0]->setSpriteClip(0, 0, 128, 96);
|
||||
bitmaps_.at(0)->setPosX(-BITMAP_WIDTH);
|
||||
bitmaps_.at(0)->setPosY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||
bitmaps_.at(0)->setVelX(0.0f);
|
||||
bitmaps_.at(0)->setVelY(0.0f);
|
||||
bitmaps_.at(0)->setAccelX(0.6f);
|
||||
bitmaps_.at(0)->setAccelY(0.0f);
|
||||
|
||||
bitmaps_[1]->setPosX(param.game.width);
|
||||
bitmaps_[1]->setPosY(param.game.game_area.first_quarter_y - 24);
|
||||
bitmaps_[1]->setVelX(-1.0f);
|
||||
bitmaps_[1]->setVelY(0.0f);
|
||||
bitmaps_[1]->setAccelX(-0.3f);
|
||||
bitmaps_[1]->setAccelY(0.0f);
|
||||
bitmaps_[1]->setSpriteClip(128, 0, 128, 96);
|
||||
bitmaps_.at(1)->setPosX(param.game.width);
|
||||
bitmaps_.at(1)->setPosY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||
bitmaps_.at(1)->setVelX(-1.0f);
|
||||
bitmaps_.at(1)->setVelY(0.0f);
|
||||
bitmaps_.at(1)->setAccelX(-0.3f);
|
||||
bitmaps_.at(1)->setAccelY(0.0f);
|
||||
|
||||
bitmaps_[2]->setPosX(param.game.game_area.center_x - 64);
|
||||
bitmaps_[2]->setPosY(-96);
|
||||
bitmaps_[2]->setVelX(0.0f);
|
||||
bitmaps_[2]->setVelY(3.0f);
|
||||
bitmaps_[2]->setAccelX(0.1f);
|
||||
bitmaps_[2]->setAccelY(0.3f);
|
||||
bitmaps_[2]->setSpriteClip(0, 96, 128, 96);
|
||||
bitmaps_[2]->setFinishedCounter(250);
|
||||
bitmaps_.at(2)->setPosX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||
bitmaps_.at(2)->setPosY(-BITMAP_HEIGHT);
|
||||
bitmaps_.at(2)->setVelX(0.0f);
|
||||
bitmaps_.at(2)->setVelY(3.0f);
|
||||
bitmaps_.at(2)->setAccelX(0.1f);
|
||||
bitmaps_.at(2)->setAccelY(0.3f);
|
||||
bitmaps_.at(2)->setFinishedCounter(250);
|
||||
|
||||
bitmaps_[3]->setPosX(param.game.game_area.center_x - 64);
|
||||
bitmaps_[3]->setPosY(param.game.height);
|
||||
bitmaps_[3]->setVelX(0.0f);
|
||||
bitmaps_[3]->setVelY(-0.7f);
|
||||
bitmaps_[3]->setAccelX(0.0f);
|
||||
bitmaps_[3]->setAccelY(0.0f);
|
||||
bitmaps_[3]->setSpriteClip(128, 96, 128, 96);
|
||||
bitmaps_.at(3)->setPosX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||
bitmaps_.at(3)->setPosY(param.game.height);
|
||||
bitmaps_.at(3)->setVelX(0.0f);
|
||||
bitmaps_.at(3)->setVelY(-0.7f);
|
||||
bitmaps_.at(3)->setAccelX(0.0f);
|
||||
bitmaps_.at(3)->setAccelY(0.0f);
|
||||
|
||||
bitmaps_[4]->setPosX(param.game.game_area.center_x - 64);
|
||||
bitmaps_[4]->setPosY(-96);
|
||||
bitmaps_[4]->setVelX(0.0f);
|
||||
bitmaps_[4]->setVelY(3.0f);
|
||||
bitmaps_[4]->setAccelX(0.1f);
|
||||
bitmaps_[4]->setAccelY(0.3f);
|
||||
bitmaps_[4]->setSpriteClip(0, 192, 128, 96);
|
||||
bitmaps_.at(4)->setPosX(param.game.game_area.center_x - (BITMAP_WIDTH / 2));
|
||||
bitmaps_.at(4)->setPosY(-BITMAP_HEIGHT);
|
||||
bitmaps_.at(4)->setVelX(0.0f);
|
||||
bitmaps_.at(4)->setVelY(3.0f);
|
||||
bitmaps_.at(4)->setAccelX(0.1f);
|
||||
bitmaps_.at(4)->setAccelY(0.3f);
|
||||
|
||||
bitmaps_[5]->setPosX(param.game.width);
|
||||
bitmaps_[5]->setPosY(param.game.game_area.first_quarter_y - 24);
|
||||
bitmaps_[5]->setVelX(-0.7f);
|
||||
bitmaps_[5]->setVelY(0.0f);
|
||||
bitmaps_[5]->setAccelX(0.0f);
|
||||
bitmaps_[5]->setAccelY(0.0f);
|
||||
bitmaps_[5]->setSpriteClip(128, 192, 128, 96);
|
||||
bitmaps_.at(5)->setPosX(param.game.width);
|
||||
bitmaps_.at(5)->setPosY(param.game.game_area.first_quarter_y - (BITMAP_HEIGHT / 4));
|
||||
bitmaps_.at(5)->setVelX(-0.7f);
|
||||
bitmaps_.at(5)->setVelY(0.0f);
|
||||
bitmaps_.at(5)->setAccelX(0.0f);
|
||||
bitmaps_.at(5)->setAccelY(0.0f);
|
||||
|
||||
// Inicializa los textos de la intro
|
||||
constexpr int totalTexts = 9;
|
||||
for (int i = 0; i < totalTexts; ++i)
|
||||
constexpr int TOTAL_TEXTS = 9;
|
||||
for (int i = 0; i < TOTAL_TEXTS; ++i)
|
||||
{
|
||||
auto w = std::make_unique<Writer>(text_);
|
||||
auto w = std::make_unique<Writer>(Resource::get()->getText("04b_25_metal"));
|
||||
w->setPosX(BLOCK * 0);
|
||||
w->setPosY(param.game.height - (BLOCK * 6));
|
||||
w->setKerning(-2);
|
||||
@@ -104,50 +109,45 @@ Intro::Intro()
|
||||
}
|
||||
|
||||
// Un dia qualsevol de l'any 2000
|
||||
texts_[0]->setCaption(lang::getText(27));
|
||||
texts_[0]->setSpeed(8);
|
||||
texts_.at(0)->setCaption(lang::getText(27));
|
||||
texts_.at(0)->setSpeed(8);
|
||||
|
||||
// Tot esta tranquil a la UPV
|
||||
texts_[1]->setCaption(lang::getText(28));
|
||||
texts_[1]->setSpeed(8);
|
||||
texts_.at(1)->setCaption(lang::getText(28));
|
||||
texts_.at(1)->setSpeed(8);
|
||||
|
||||
// Fins que un desaprensiu...
|
||||
texts_[2]->setCaption(lang::getText(29));
|
||||
texts_[2]->setSpeed(12);
|
||||
texts_.at(2)->setCaption(lang::getText(29));
|
||||
texts_.at(2)->setSpeed(12);
|
||||
|
||||
// HEY! ME ANE A FERME UN CORTAET...
|
||||
texts_[3]->setCaption(lang::getText(30));
|
||||
texts_[3]->setSpeed(8);
|
||||
texts_.at(3)->setCaption(lang::getText(30));
|
||||
texts_.at(3)->setSpeed(8);
|
||||
|
||||
// UAAAAAAAAAAAAA!!!
|
||||
texts_[4]->setCaption(lang::getText(31));
|
||||
texts_[4]->setSpeed(1);
|
||||
texts_.at(4)->setCaption(lang::getText(31));
|
||||
texts_.at(4)->setSpeed(1);
|
||||
|
||||
// Espera un moment...
|
||||
texts_[5]->setCaption(lang::getText(32));
|
||||
texts_[5]->setSpeed(16);
|
||||
texts_.at(5)->setCaption(lang::getText(32));
|
||||
texts_.at(5)->setSpeed(16);
|
||||
|
||||
// Si resulta que no tinc solt!
|
||||
texts_[6]->setCaption(lang::getText(33));
|
||||
texts_[6]->setSpeed(2);
|
||||
texts_.at(6)->setCaption(lang::getText(33));
|
||||
texts_.at(6)->setSpeed(2);
|
||||
|
||||
// MERDA DE MAQUINA!
|
||||
texts_[7]->setCaption(lang::getText(34));
|
||||
texts_[7]->setSpeed(3);
|
||||
texts_.at(7)->setCaption(lang::getText(34));
|
||||
texts_.at(7)->setSpeed(3);
|
||||
|
||||
// Blop... blop... blop...
|
||||
texts_[8]->setCaption(lang::getText(35));
|
||||
texts_[8]->setSpeed(16);
|
||||
texts_.at(8)->setCaption(lang::getText(35));
|
||||
texts_.at(8)->setSpeed(16);
|
||||
|
||||
for (auto &text : texts_)
|
||||
{
|
||||
text->center(param.game.game_area.center_x);
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
void Intro::reloadTextures()
|
||||
{
|
||||
texture_->reLoad();
|
||||
text_->reLoadTexture();
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
@@ -171,7 +171,7 @@ void Intro::checkEvents()
|
||||
{
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
// reloadTextures();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,6 @@ class Intro
|
||||
{
|
||||
private:
|
||||
// Objetos
|
||||
std::shared_ptr<Texture> texture_; // Textura con los graficos
|
||||
std::shared_ptr<Text> text_; // Textos de la intro
|
||||
|
||||
std::vector<std::unique_ptr<SmartSprite>> bitmaps_; // Vector con los sprites inteligentes para los dibujos de la intro
|
||||
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
|
||||
|
||||
@@ -43,9 +40,6 @@ private:
|
||||
// Actualiza las escenas de la intro
|
||||
void updateScenes();
|
||||
|
||||
// Recarga todas las texturas
|
||||
void reloadTextures();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro();
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef NO_SHADERS
|
||||
|
||||
#include "jail_shader.h"
|
||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
||||
#include <stdlib.h> // para NULL, free, malloc, exit
|
||||
@@ -247,5 +245,4 @@ namespace shader
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
#ifndef NO_SHADERS
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // para SDL_Texture
|
||||
@@ -44,5 +42,4 @@ namespace shader
|
||||
const char *vertexShader, const char *fragmentShader = nullptr);
|
||||
|
||||
void render();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -41,10 +41,10 @@ namespace lang
|
||||
return texts.at(index);
|
||||
}
|
||||
|
||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
||||
Code change(Code current_lang)
|
||||
// Obtiene el codigo del idioma del siguiente idioma
|
||||
Code getNextLangCode(Code lang)
|
||||
{
|
||||
auto index = static_cast<int>(current_lang);
|
||||
auto index = static_cast<int>(lang);
|
||||
index = (index + 1) % 3;
|
||||
return static_cast<Code>(index);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace lang
|
||||
// Obtiene la cadena de texto del indice
|
||||
std::string getText(int index);
|
||||
|
||||
// Cambia el idioma seleccionado al siguiente idioma disponible
|
||||
Code change(Code current_lang);
|
||||
// Obtiene el codigo del idioma del siguiente idioma
|
||||
Code getNextLangCode(Code lang);
|
||||
}
|
||||
220
source/logo.cpp
@@ -3,24 +3,24 @@
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // Para SDL_WINDOWEVENT_SIZE_CHANGED
|
||||
#include <utility> // Para move
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input
|
||||
#include "jail_audio.h" // Para JA_StopMusic
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, Zone
|
||||
#include <iostream>
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input
|
||||
#include "jail_audio.h" // Para JA_StopMusic
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para Color, Zone
|
||||
#include "mouse.h"
|
||||
|
||||
// Constructor
|
||||
Logo::Logo()
|
||||
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
|
||||
since_sprite_(std::make_unique<Sprite>(since_texture_)),
|
||||
jail_texture_(Resource::get()->getTexture("logo_jailgames.png")),
|
||||
ticks_(0)
|
||||
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
|
||||
{
|
||||
|
||||
// Inicializa variables
|
||||
@@ -114,7 +114,7 @@ void Logo::checkInput()
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Gestiona el logo de JAILGAME
|
||||
// Gestiona el logo de JAILGAMES
|
||||
void Logo::updateJAILGAMES()
|
||||
{
|
||||
if (counter_ == 30)
|
||||
@@ -147,6 +147,19 @@ void Logo::updateJAILGAMES()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
|
||||
{
|
||||
state_ = LogoState::RETROWEEKEND;
|
||||
ticks_start_ = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
|
||||
// Gestiona el logo de RETROWEEKEND
|
||||
void Logo::updateRETROWEEKEND()
|
||||
{
|
||||
section::name = section::Name::INTRO;
|
||||
}
|
||||
|
||||
// Gestiona el color de las texturas
|
||||
@@ -190,21 +203,24 @@ void Logo::update()
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
|
||||
// Gestiona el logo de JAILGAME
|
||||
updateJAILGAMES();
|
||||
|
||||
// Gestiona el color de las texturas
|
||||
updateTextureColors();
|
||||
|
||||
// Gestiona el contador y sus eventos
|
||||
counter_++;
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
|
||||
switch (state_)
|
||||
{
|
||||
section::name = section::Name::INTRO;
|
||||
case LogoState::JAILGAMES:
|
||||
updateJAILGAMES();
|
||||
updateTextureColors();
|
||||
break;
|
||||
|
||||
case LogoState::RETROWEEKEND:
|
||||
updateRETROWEEKEND();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Gestiona el contador
|
||||
counter_++;
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
@@ -213,24 +229,23 @@ void Logo::update()
|
||||
// Dibuja en pantalla
|
||||
void Logo::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean();
|
||||
|
||||
// Dibuja los sprites
|
||||
for (auto &sprite : jail_sprite_)
|
||||
switch (state_)
|
||||
{
|
||||
sprite->render();
|
||||
case LogoState::JAILGAMES:
|
||||
renderJAILGAMES();
|
||||
break;
|
||||
|
||||
case LogoState::RETROWEEKEND:
|
||||
renderRETROWEEKEND();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
|
||||
{
|
||||
since_sprite_->render();
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
@@ -247,4 +262,133 @@ void Logo::run()
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renderiza el logo de JAILGAMES
|
||||
void Logo::renderJAILGAMES()
|
||||
{
|
||||
// Dibuja los sprites
|
||||
for (auto &sprite : jail_sprite_)
|
||||
{
|
||||
sprite->render();
|
||||
}
|
||||
|
||||
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
|
||||
{
|
||||
since_sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Renderiza el logo de RETROWEEKEND
|
||||
void Logo::renderRETROWEEKEND()
|
||||
{
|
||||
// SDL_RenderCopy(Screen::get()->getRenderer(), mi_textura, nullptr, nullptr);
|
||||
|
||||
// SDL_RenderCopy(Screen::get()->getRenderer(), Resource::get()->getTexture("logo_retroweekend.png")->getSDLTexture(), nullptr, nullptr);
|
||||
// Dibujar y evaporar los píxeles
|
||||
renderAndEvaporate(Screen::get()->getRenderer(), pixels_);
|
||||
}
|
||||
|
||||
std::vector<Pixel> Logo::extractPixels(SDL_Texture *texture)
|
||||
{
|
||||
std::vector<Pixel> pixels;
|
||||
|
||||
// Obtener el formato y tamaño de la textura
|
||||
Uint32 format;
|
||||
int access, width, height;
|
||||
SDL_QueryTexture(texture, &format, &access, &width, &height);
|
||||
|
||||
// Imprimir el nombre del formato de la textura
|
||||
std::cout << "Texture format: " << SDL_GetPixelFormatName(format) << std::endl;
|
||||
|
||||
// Crear una superficie temporal para leer los píxeles
|
||||
SDL_Surface *temp_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, format);
|
||||
if (!temp_surface)
|
||||
{
|
||||
std::cout << "Error: SDL_CreateRGBSurfaceWithFormat failed - " << SDL_GetError() << std::endl;
|
||||
return pixels;
|
||||
}
|
||||
|
||||
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||
SDL_SetRenderTarget(renderer, nullptr); // Dibujar en pantalla principal
|
||||
SDL_RenderClear(renderer); // Limpiar pantalla
|
||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer); // Mostrar en pantalla
|
||||
|
||||
std::cout << "Se ha dibujado la textura en pantalla." << std::endl;
|
||||
|
||||
if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0)
|
||||
{
|
||||
std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl;
|
||||
SDL_FreeSurface(temp_surface);
|
||||
return pixels;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "SDL_RenderReadPixels se ejecutó correctamente." << std::endl;
|
||||
}
|
||||
|
||||
// Leer los píxeles de la textura
|
||||
if (SDL_RenderReadPixels(Screen::get()->getRenderer(), nullptr, format, temp_surface->pixels, temp_surface->pitch) != 0)
|
||||
{
|
||||
std::cout << "Error: SDL_RenderReadPixels failed - " << SDL_GetError() << std::endl;
|
||||
SDL_FreeSurface(temp_surface);
|
||||
return pixels;
|
||||
}
|
||||
|
||||
// Extraer los píxeles y almacenarlos en el vector
|
||||
SDL_PixelFormat *pixel_format = SDL_AllocFormat(format);
|
||||
Uint8 r, g, b, a;
|
||||
/*for (int y = 0; y < height; ++y)
|
||||
{
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x];
|
||||
SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a);
|
||||
if (a > 0)
|
||||
{
|
||||
pixels.push_back({x, y, r, g, b, a});
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
Uint32 pixel_value = ((Uint32 *)temp_surface->pixels)[y * (temp_surface->pitch / 4) + x];
|
||||
SDL_GetRGBA(pixel_value, pixel_format, &r, &g, &b, &a);
|
||||
|
||||
// Imprimir algunos píxeles para depuración
|
||||
if (x < 5 && y < 5)
|
||||
{
|
||||
std::cout << "Pixel (" << x << "," << y << ") - RGBA("
|
||||
<< (int)r << "," << (int)g << "," << (int)b << "," << (int)a << ")" << std::endl;
|
||||
}
|
||||
|
||||
// No filtrar por alfa por ahora
|
||||
pixels.push_back({x, y, r, g, b, a});
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Cantidad de píxeles a renderizar: " << pixels.size() << std::endl;
|
||||
|
||||
// Liberar recursos
|
||||
SDL_FreeFormat(pixel_format);
|
||||
SDL_FreeSurface(temp_surface);
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
void Logo::renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels)
|
||||
{
|
||||
for (auto &pixel : pixels)
|
||||
{
|
||||
// Establecer el color para el píxel actual
|
||||
SDL_SetRenderDrawColor(renderer, pixel.r, pixel.g, pixel.b, pixel.a);
|
||||
// Dibujar el píxel
|
||||
SDL_RenderDrawPoint(renderer, pixel.x, pixel.y);
|
||||
// Evaporar el píxel
|
||||
// pixel.evaporate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <vector> // Para vector
|
||||
#include <SDL2/SDL.h>
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <vector> // Para vector
|
||||
class Sprite;
|
||||
class Texture; // lines 9-9
|
||||
struct Color;
|
||||
@@ -16,10 +17,31 @@ struct Color;
|
||||
ZX Spectrum
|
||||
*/
|
||||
|
||||
struct Pixel
|
||||
{
|
||||
int x, y; // Coordenadas del píxel
|
||||
Uint8 r, g, b, a; // Color del píxel
|
||||
|
||||
// Método para ascender y desvanecerse
|
||||
void evaporate()
|
||||
{
|
||||
y -= 1; // Asciende hacia arriba
|
||||
a = (a > 5) ? a - 5 : 0; // Desvanece el alfa (transparencia)
|
||||
// Añadir movimiento zig-zag aleatorio
|
||||
x += (rand() % 3 - 1); // Movimiento horizontal aleatorio (-1, 0, 1)
|
||||
}
|
||||
};
|
||||
|
||||
// Clase Logo
|
||||
class Logo
|
||||
{
|
||||
private:
|
||||
enum class LogoState
|
||||
{
|
||||
JAILGAMES,
|
||||
RETROWEEKEND,
|
||||
};
|
||||
|
||||
// Constantes
|
||||
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
|
||||
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
|
||||
@@ -34,10 +56,13 @@ private:
|
||||
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||
|
||||
// Variables
|
||||
std::vector<Color> color_; // Vector con los colores para el fade
|
||||
int counter_; // Contador
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
SDL_Point dest_; // Posición X donde dibujar el logo
|
||||
std::vector<Color> color_; // Vector con los colores para el fade
|
||||
int counter_; // Contador
|
||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
SDL_Point dest_; // Posición X donde dibujar el logo
|
||||
LogoState state_ = LogoState::JAILGAMES; // El estado indica qué logo se está procesando
|
||||
Uint32 ticks_start_ = 0; // Almacena el valor actual de los ticks de SDL
|
||||
std::vector<Pixel> pixels_; // Vector con los pixels que forman el logo de "RETROWEEKEND"
|
||||
|
||||
// Actualiza las variables
|
||||
void update();
|
||||
@@ -51,15 +76,28 @@ private:
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
|
||||
// Gestiona el logo de JAILGAME
|
||||
// Gestiona el logo de JAILGAMES
|
||||
void updateJAILGAMES();
|
||||
|
||||
// Gestiona el logo de RETROWEEKEND
|
||||
void updateRETROWEEKEND();
|
||||
|
||||
// Renderiza el logo de JAILGAMES
|
||||
void renderJAILGAMES();
|
||||
|
||||
// Renderiza el logo de RETROWEEKEND
|
||||
void renderRETROWEEKEND();
|
||||
|
||||
// Gestiona el color de las texturas
|
||||
void updateTextureColors();
|
||||
|
||||
// Recarga todas las texturas
|
||||
void reloadTextures();
|
||||
|
||||
std::vector<Pixel> extractPixels(SDL_Texture *texture);
|
||||
|
||||
void renderAndEvaporate(SDL_Renderer *renderer, std::vector<Pixel> &pixels);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Logo();
|
||||
|
||||
@@ -28,7 +28,7 @@ MovingSprite::MovingSprite(std::shared_ptr<Texture> texture)
|
||||
rotate_(Rotate()),
|
||||
zoom_w_(1.0f),
|
||||
zoom_h_(1.0f),
|
||||
flip_(SDL_FLIP_NONE) { Sprite::clear(); }
|
||||
flip_(SDL_FLIP_NONE) {Sprite::clear(); }
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
@@ -73,46 +73,7 @@ void MovingSprite::update()
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void MovingSprite::render()
|
||||
{
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomW(float value)
|
||||
{
|
||||
zoom_w_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setZoomH(float value)
|
||||
{
|
||||
zoom_h_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAngle(double value)
|
||||
{
|
||||
rotate_.angle = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotatingCenter(SDL_Point *point)
|
||||
{
|
||||
rotate_.center = point;
|
||||
}
|
||||
|
||||
// Incrementa el valor del ángulo
|
||||
void MovingSprite::updateAngle()
|
||||
{
|
||||
rotate_.angle += rotate_.amount;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool MovingSprite::isRotating() const
|
||||
{
|
||||
return rotate_.enabled;
|
||||
}
|
||||
void MovingSprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_w_, zoom_h_, rotate_.angle, rotate_.center, flip_); }
|
||||
|
||||
// Establece la rotacion
|
||||
void MovingSprite::rotate()
|
||||
@@ -135,43 +96,6 @@ void MovingSprite::setRotate(bool enable)
|
||||
rotate_.counter = 0;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateSpeed(int value)
|
||||
{
|
||||
rotate_.speed = std::max(1, value);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setRotateAmount(double value)
|
||||
{
|
||||
rotate_.amount = value;
|
||||
}
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void MovingSprite::switchRotate()
|
||||
{
|
||||
rotate_.amount *= -1;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||
{
|
||||
flip_ = flip;
|
||||
}
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void MovingSprite::flip()
|
||||
{
|
||||
flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip MovingSprite::getFlip()
|
||||
{
|
||||
return flip_;
|
||||
}
|
||||
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void MovingSprite::setPos(SDL_Rect rect)
|
||||
{
|
||||
@@ -203,28 +127,4 @@ void MovingSprite::setPosY(float value)
|
||||
{
|
||||
y_ = value;
|
||||
pos_.y = static_cast<int>(y_);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelX(float value)
|
||||
{
|
||||
vx_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setVelY(float value)
|
||||
{
|
||||
vy_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelX(float value)
|
||||
{
|
||||
ax_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setAccelY(float value)
|
||||
{
|
||||
ay_ = value;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <algorithm>
|
||||
#include "sprite.h" // Para Sprite
|
||||
class Texture; // lines 8-8
|
||||
|
||||
@@ -38,7 +39,7 @@ protected:
|
||||
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
||||
|
||||
// Incrementa el valor del ángulo
|
||||
void updateAngle();
|
||||
void updateAngle() { rotate_.angle += rotate_.amount; }
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
@@ -73,40 +74,40 @@ public:
|
||||
float getAccelY() const { return ay_; }
|
||||
|
||||
// Establece la variable
|
||||
void setVelX(float value);
|
||||
void setVelY(float value);
|
||||
void setAccelX(float value);
|
||||
void setAccelY(float value);
|
||||
void setVelX(float value) { vx_ = value; }
|
||||
void setVelY(float value) { vy_ = value; }
|
||||
void setAccelX(float value) { ax_ = value; }
|
||||
void setAccelY(float value) { ay_ = value; }
|
||||
|
||||
// Obten el valor de la variable
|
||||
bool isRotating() const;
|
||||
bool isRotating() const { return rotate_.enabled; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value);
|
||||
void setZoomH(float value);
|
||||
void setZoomW(float value) { zoom_w_ = value; }
|
||||
void setZoomH(float value) { zoom_h_ = value; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
void setRotatingCenter(SDL_Point *point);
|
||||
void setAngle(double value) { rotate_.angle = value; }
|
||||
void setRotatingCenter(SDL_Point *point) { rotate_.center = point; }
|
||||
|
||||
// Activa o desactiva el efecto de rotación
|
||||
void setRotate(bool enable);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(int value);
|
||||
void setRotateAmount(double value);
|
||||
void setRotateSpeed(int value) { rotate_.speed = std::max(1, value); }
|
||||
void setRotateAmount(double value) { rotate_.amount = value; }
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
void switchRotate() { rotate_.amount *= -1; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFlip(SDL_RendererFlip flip);
|
||||
void setFlip(SDL_RendererFlip flip) { flip_ = flip; }
|
||||
|
||||
// Gira el sprite horizontalmente
|
||||
void flip();
|
||||
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; }
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
SDL_RendererFlip getFlip() { return flip_; }
|
||||
|
||||
// Establece la posición y_ el tamaño del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
@@ -12,22 +12,22 @@
|
||||
#include "texture.h" // Para Texture
|
||||
#include "resource.h"
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
// [SINGLETON]
|
||||
Notifier *Notifier::notifier_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Notifier::init(const std::string &icon_file, std::shared_ptr<Text> text)
|
||||
{
|
||||
Notifier::notifier_ = new Notifier(icon_file, text);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Notifier::destroy()
|
||||
{
|
||||
delete Notifier::notifier_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Notifier *Notifier::get()
|
||||
{
|
||||
return Notifier::notifier_;
|
||||
@@ -153,7 +153,7 @@ void Notifier::clearFinishedNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::showText(std::vector<std::string> texts, int icon, const std::string &code)
|
||||
void Notifier::show(std::vector<std::string> texts, int icon, const std::string &code)
|
||||
{
|
||||
// Si no hay texto, acaba
|
||||
if (texts.empty())
|
||||
@@ -164,7 +164,7 @@ void Notifier::showText(std::vector<std::string> texts, int icon, const std::str
|
||||
// Si las notificaciones no se apilan, elimina las anteriores
|
||||
if (!stack_)
|
||||
{
|
||||
clearNotifications();
|
||||
clearAllNotifications();
|
||||
}
|
||||
|
||||
// Elimina las cadenas vacías
|
||||
@@ -298,7 +298,7 @@ void Notifier::showText(std::vector<std::string> texts, int icon, const std::str
|
||||
bool Notifier::isActive() { return !notifications_.empty(); }
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void Notifier::clearNotifications()
|
||||
void Notifier::clearAllNotifications()
|
||||
{
|
||||
for (auto ¬ification : notifications_)
|
||||
{
|
||||
@@ -317,4 +317,10 @@ std::vector<std::string> Notifier::getCodes()
|
||||
codes.emplace_back(notification.code);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
// Comprueba si hay alguna notificacion con un código
|
||||
bool Notifier::checkCode(std::string code)
|
||||
{
|
||||
return stringInVector(getCodes(), code);
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class Texture; // lines 11-11
|
||||
class Notifier
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto notifier privado para Don Melitón
|
||||
// [SINGLETON] Objeto notifier
|
||||
static Notifier *notifier_;
|
||||
|
||||
enum class NotificationStatus
|
||||
@@ -66,7 +66,7 @@ private:
|
||||
void clearFinishedNotifications();
|
||||
|
||||
// Finaliza y elimnina todas las notificaciones activas
|
||||
void clearNotifications();
|
||||
void clearAllNotifications();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera
|
||||
|
||||
@@ -77,13 +77,13 @@ private:
|
||||
~Notifier() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto notifier con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(const std::string &icon_file, std::shared_ptr<Text> text);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto notifier con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto notifier y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Notifier *get();
|
||||
|
||||
// Dibuja las notificaciones por pantalla
|
||||
@@ -93,11 +93,14 @@ public:
|
||||
void update();
|
||||
|
||||
// Muestra una notificación de texto por pantalla
|
||||
void showText(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
|
||||
void show(std::vector<std::string> texts, int icon = -1, const std::string &code = std::string());
|
||||
|
||||
// Indica si hay notificaciones activas
|
||||
bool isActive();
|
||||
|
||||
// Obtiene los códigos de las notificaciones
|
||||
std::vector<std::string> getCodes();
|
||||
|
||||
// Comprueba si hay alguna notificacion con un código
|
||||
bool checkCode(std::string code);
|
||||
};
|
||||
|
||||
@@ -149,6 +149,11 @@ void Player::setInputEnteringName(InputType input)
|
||||
break;
|
||||
case InputType::START:
|
||||
last_enter_name_ = getRecordName();
|
||||
if (last_enter_name_.empty())
|
||||
{
|
||||
const std::array<std::string, 8> NAMES = {"BAL1", "TABE", "DOC", "MON", "SAM1", "JORDI", "JDES", "PEPE"};
|
||||
last_enter_name_ = NAMES.at(rand() % NAMES.size());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -166,9 +171,9 @@ void Player::move()
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el jugador abandona el area de juego por los laterales, restaura su posición
|
||||
const float min_x = play_area_.x - 5;
|
||||
const float max_x = play_area_.w + 5 - WIDTH_;
|
||||
pos_x_ = std::clamp(pos_x_, min_x, max_x);
|
||||
const float MIN_X = play_area_.x - 5;
|
||||
const float MAX_X = play_area_.w + 5 - WIDTH_;
|
||||
pos_x_ = std::clamp(pos_x_, MIN_X, MAX_X);
|
||||
|
||||
shiftSprite();
|
||||
break;
|
||||
@@ -176,12 +181,12 @@ void Player::move()
|
||||
case PlayerState::DYING:
|
||||
{
|
||||
// Si el cadaver abandona el area de juego por los laterales lo hace rebotar
|
||||
const int x = player_sprite_->getPosX();
|
||||
const int min_x = play_area_.x;
|
||||
const int max_x = play_area_.x + play_area_.w - WIDTH_;
|
||||
if ((x < min_x) || (x > max_x))
|
||||
const int X = player_sprite_->getPosX();
|
||||
const int MIN_X = play_area_.x;
|
||||
const int MAX_X = play_area_.x + play_area_.w - WIDTH_;
|
||||
if ((X < MIN_X) || (X > MAX_X))
|
||||
{
|
||||
player_sprite_->setPosX(std::clamp(x, min_x, max_x));
|
||||
player_sprite_->setPosX(std::clamp(X, MIN_X, MAX_X));
|
||||
player_sprite_->setVelX(-player_sprite_->getVelX());
|
||||
playRandomBubbleSound();
|
||||
}
|
||||
@@ -287,7 +292,6 @@ void Player::move()
|
||||
{
|
||||
pos_x_ = param.game.game_area.rect.w - WIDTH_;
|
||||
vel_x_ *= -1;
|
||||
// setInputPlaying(InputType::LEFT);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -297,7 +301,6 @@ void Player::move()
|
||||
{
|
||||
pos_x_ = param.game.game_area.rect.x;
|
||||
vel_x_ *= -1;
|
||||
// setInputPlaying(InputType::RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,17 +359,20 @@ void Player::setAnimation()
|
||||
|
||||
// Establece la animación a partir de las cadenas
|
||||
if (firing_state_ == PlayerState::FIRING_NONE)
|
||||
{ // No esta disparando
|
||||
{
|
||||
// No esta disparando
|
||||
player_sprite_->setCurrentAnimation(a_walking);
|
||||
player_sprite_->setFlip(flip_walk);
|
||||
}
|
||||
else if (isCooling())
|
||||
{ // Acaba de disparar
|
||||
{
|
||||
// Acaba de disparar
|
||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_cooling + "-cooldown");
|
||||
player_sprite_->setFlip(flip_cooling);
|
||||
}
|
||||
else
|
||||
{ // Está disparando
|
||||
{
|
||||
// Está disparando
|
||||
player_sprite_->setCurrentAnimation(a_walking + "-" + a_firing);
|
||||
// Si dispara de lado, invierte el sprite segun hacia donde dispara
|
||||
// Si dispara recto, invierte el sprite segun hacia donde camina
|
||||
|
||||
@@ -208,6 +208,7 @@ public:
|
||||
bool isContinue() const { return playing_state_ == PlayerState::CONTINUE; }
|
||||
bool isDying() const { return playing_state_ == PlayerState::DYING; }
|
||||
bool isEnteringName() const { return playing_state_ == PlayerState::ENTERING_NAME; }
|
||||
bool isShowingName() const { return playing_state_ == PlayerState::SHOWING_NAME; }
|
||||
bool isEnteringNameGameCompleted() const { return playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED; }
|
||||
bool isLeavingScreen() const { return playing_state_ == PlayerState::LEAVING_SCREEN; }
|
||||
bool isGameOver() const { return playing_state_ == PlayerState::GAME_OVER; }
|
||||
|
||||
@@ -263,7 +263,7 @@ void Scoreboard::fillPanelTextures()
|
||||
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
|
||||
|
||||
// Recorre todos los slots de letras del nombre
|
||||
for (size_t j = 0; j < NAME_LENGHT; ++j)
|
||||
for (size_t j = 0; j < MAX_NAME_LENGHT; ++j)
|
||||
{
|
||||
// Selecciona el color
|
||||
const Color color = j < selector_pos_[i] ? orange_soft_color.lighten() : Color(0xFF, 0xFF, 0xEB);
|
||||
@@ -380,7 +380,7 @@ void Scoreboard::recalculateAnchors()
|
||||
slot4_4_ = {col, row4};
|
||||
|
||||
// Primer cuadrado para poner el nombre de record
|
||||
const int enter_name_lenght = text_scoreboard_->lenght(std::string(NAME_LENGHT, 'A'));
|
||||
const int enter_name_lenght = text_scoreboard_->lenght(std::string(MAX_NAME_LENGHT, 'A'));
|
||||
enter_name_pos_.x = col - (enter_name_lenght / 2);
|
||||
enter_name_pos_.y = row4;
|
||||
|
||||
|
||||
@@ -15,27 +15,24 @@
|
||||
#include "on_screen_help.h" // Para OnScreenHelp
|
||||
#include "options.h" // Para Options, OptionsVideo, options, Options...
|
||||
#include "mouse.h"
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
#include "jail_shader.h" // para init, render
|
||||
#endif
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
// [SINGLETON]
|
||||
Screen *Screen::screen_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
||||
{
|
||||
Screen::screen_ = new Screen(window, renderer);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Screen::destroy()
|
||||
{
|
||||
delete Screen::screen_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Screen *Screen::get()
|
||||
{
|
||||
return Screen::screen_;
|
||||
@@ -105,11 +102,6 @@ void Screen::renderScreen()
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
clean();
|
||||
|
||||
#ifdef NO_SHADERS
|
||||
// Actualiza la pantalla con el contenido del buffer de renderizado
|
||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer_);
|
||||
#else
|
||||
if (options.video.shaders)
|
||||
{
|
||||
// Aplica shaders y renderiza el contenido
|
||||
@@ -121,7 +113,6 @@ void Screen::renderScreen()
|
||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer_);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
@@ -174,13 +165,11 @@ void Screen::setVideoMode(ScreenVideoMode videoMode)
|
||||
// Reinicia los shaders
|
||||
if (options.video.shaders)
|
||||
{
|
||||
#ifndef NO_SHADERS
|
||||
const std::string glsl_file = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
|
||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
shader::init(window_, game_canvas_, source.c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,7 +337,7 @@ void Screen::toggleShaders()
|
||||
options.video.shaders = !options.video.shaders;
|
||||
setVideoMode(options.video.mode);
|
||||
const std::string value = options.video.shaders ? "on" : "off";
|
||||
Notifier::get()->showText({"Shaders " + value});
|
||||
Notifier::get()->show({"Shaders " + value});
|
||||
}
|
||||
|
||||
// Activa / desactiva la información de debug
|
||||
@@ -363,12 +352,6 @@ void Screen::attenuate(bool value)
|
||||
attenuate_effect_ = value;
|
||||
}
|
||||
|
||||
// Obtiene el puntero al renderizador
|
||||
SDL_Renderer *Screen::getRenderer()
|
||||
{
|
||||
return renderer_;
|
||||
}
|
||||
|
||||
// Calcula los frames por segundo
|
||||
void Screen::updateFPS()
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ enum class ScreenVideoMode : int
|
||||
class Screen
|
||||
{
|
||||
private:
|
||||
// [SINGLETON] Objeto screen privado para Don Melitón
|
||||
// [SINGLETON] Objeto privado
|
||||
static Screen *screen_;
|
||||
|
||||
// Objetos y punteros
|
||||
@@ -110,14 +110,9 @@ private:
|
||||
// Calcula la nueva posición de la ventana a partir de la antigua al cambiarla de tamaño
|
||||
SDL_Point getNewPosition();
|
||||
|
||||
// Actualiza la pantalla con el contenido del game_canvas_
|
||||
void presentGameCanvas();
|
||||
|
||||
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
|
||||
void renderScreen();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera
|
||||
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||
|
||||
@@ -125,13 +120,13 @@ private:
|
||||
~Screen();
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(SDL_Window *window, SDL_Renderer *renderer);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Screen *get();
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
@@ -182,6 +177,6 @@ public:
|
||||
// Atenua la pantalla
|
||||
void attenuate(bool value);
|
||||
|
||||
// Obtiene el puntero al renderizador
|
||||
SDL_Renderer *getRenderer();
|
||||
// Getters
|
||||
SDL_Renderer *getRenderer() { return renderer_; }
|
||||
};
|
||||
@@ -2,10 +2,6 @@
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
class Texture; // lines 2-2
|
||||
|
||||
// Constructor
|
||||
SmartSprite::SmartSprite(std::shared_ptr<Texture> texture)
|
||||
: AnimatedSprite(texture) {}
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void SmartSprite::update()
|
||||
{
|
||||
@@ -17,22 +13,13 @@ void SmartSprite::update()
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setFinishedCounter(int value)
|
||||
// Dibuja el sprite
|
||||
void SmartSprite::render()
|
||||
{
|
||||
finished_counter_ = value;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setDestX(int x)
|
||||
{
|
||||
dest_x_ = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setDestY(int y)
|
||||
{
|
||||
dest_y_ = y;
|
||||
if (enabled_)
|
||||
{
|
||||
MovingSprite::render();
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el movimiento
|
||||
@@ -114,22 +101,4 @@ void SmartSprite::checkFinished()
|
||||
--finished_counter_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool SmartSprite::isOnDestination() const
|
||||
{
|
||||
return on_destination_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool SmartSprite::hasFinished() const
|
||||
{
|
||||
return finished_;
|
||||
}
|
||||
|
||||
// Habilita el objeto
|
||||
void SmartSprite::setEnabled(bool value)
|
||||
{
|
||||
enabled_ = value;
|
||||
}
|
||||
@@ -24,7 +24,8 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit SmartSprite(std::shared_ptr<Texture> texture);
|
||||
explicit SmartSprite(std::shared_ptr<Texture> texture)
|
||||
: AnimatedSprite(texture) {}
|
||||
|
||||
// Destructor
|
||||
~SmartSprite() = default;
|
||||
@@ -32,27 +33,18 @@ public:
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void update() override;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setFinishedCounter(int value);
|
||||
// Dibuja el sprite
|
||||
void render() override;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setDestX(int x);
|
||||
// Getters
|
||||
int getDestX() const { return dest_x_; }
|
||||
int getDestY() const { return dest_y_; }
|
||||
bool isOnDestination() const { return on_destination_; }
|
||||
bool hasFinished() const { return finished_; }
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setDestY(int y);
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getDestX() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getDestY() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isOnDestination() const;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool hasFinished() const;
|
||||
|
||||
// Habilita el objeto
|
||||
void setEnabled(bool value);
|
||||
// Setters
|
||||
void setFinishedCounter(int value) { finished_counter_ = value; }
|
||||
void setDestX(int x) { dest_x_ = x; }
|
||||
void setDestY(int y) { dest_y_ = y; }
|
||||
void setEnabled(bool value) { enabled_ = value; }
|
||||
};
|
||||
@@ -375,7 +375,7 @@ void Title::swapKeyboard()
|
||||
{
|
||||
swapOptionsKeyboard();
|
||||
std::string text = lang::getText(100) + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + lang::getText(69);
|
||||
Notifier::get()->showText({text});
|
||||
Notifier::get()->show({text});
|
||||
}
|
||||
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
@@ -404,5 +404,5 @@ void Title::showControllers()
|
||||
}
|
||||
|
||||
// Muestra la notificación
|
||||
Notifier::get()->showText({text.at(0), text.at(1)});
|
||||
Notifier::get()->show({text.at(0), text.at(1)});
|
||||
}
|
||||
|
||||
@@ -32,20 +32,20 @@ const Color green_sky_color = Color(0X00, 0X79, 0X6B);
|
||||
// Obtiene un color del vector de colores imitando al Coche Fantástico
|
||||
Color getColorLikeKnightRider(const std::vector<Color> &colors, int counter_)
|
||||
{
|
||||
int cycle_length = colors.size() * 2 - 2;
|
||||
size_t n = counter_ % cycle_length;
|
||||
int cycle_length = colors.size() * 2 - 2;
|
||||
size_t n = counter_ % cycle_length;
|
||||
|
||||
size_t index;
|
||||
if (n < colors.size())
|
||||
{
|
||||
index = n; // Avanza: 0,1,2,3
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1
|
||||
}
|
||||
size_t index;
|
||||
if (n < colors.size())
|
||||
{
|
||||
index = n; // Avanza: 0,1,2,3
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 2 * (colors.size() - 1) - n; // Retrocede: 2,1
|
||||
}
|
||||
|
||||
return colors[index];
|
||||
return colors[index];
|
||||
}
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
@@ -339,4 +339,4 @@ std::string getPath(const std::string &full_path)
|
||||
{
|
||||
std::filesystem::path path(full_path);
|
||||
return path.parent_path().string();
|
||||
}
|
||||
}
|
||||