canvi de pc
This commit is contained in:
@@ -255,7 +255,7 @@ void Credits::updateCounter()
|
|||||||
void Credits::update()
|
void Credits::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ private:
|
|||||||
bool counter_enabled_ = true; // Indica si esta activo el contador
|
bool counter_enabled_ = true; // Indica si esta activo el contador
|
||||||
int sub_counter_ = 0; // Contador secundario
|
int sub_counter_ = 0; // Contador secundario
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
std::vector<captions_t> texts_; // Vector con los textos
|
std::vector<captions_t> texts_; // Vector con los textos
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
// Textos
|
// Textos
|
||||||
constexpr const char *WINDOW_CAPTION = "JailDoctor's Dilemma";
|
constexpr const char *WINDOW_CAPTION = "JailDoctor's Dilemma";
|
||||||
constexpr const char *TEXT_COPYRIGHT = "@2022 JailDesigner";
|
constexpr const char *TEXT_COPYRIGHT = "@2022 JailDesigner";
|
||||||
constexpr const char *VERSION = "0.7";
|
constexpr const char *VERSION = "1.09";
|
||||||
|
|
||||||
|
// Velocidad del juego
|
||||||
|
constexpr Uint32 GAME_SPEED = 1000 / 60;
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Tamaño de bloque
|
||||||
constexpr int BLOCK = 8;
|
constexpr int BLOCK = 8;
|
||||||
|
|||||||
121
source/demo.cpp
121
source/demo.cpp
@@ -19,43 +19,42 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Demo::Demo()
|
Demo::Demo()
|
||||||
: screen(Screen::get()),
|
: screen_(Screen::get()),
|
||||||
renderer(Screen::get()->getRenderer()),
|
renderer_(Screen::get()->getRenderer()),
|
||||||
resource(Resource::get()),
|
resource_(Resource::get()),
|
||||||
asset(Asset::get()),
|
asset_(Asset::get()),
|
||||||
input(Input::get()),
|
input_(Input::get()),
|
||||||
debug(Debug::get())
|
debug_(Debug::get())
|
||||||
{
|
{
|
||||||
// Inicia algunas variables
|
// Inicia algunas variables
|
||||||
board.ini_clock = SDL_GetTicks();
|
board_.ini_clock = SDL_GetTicks();
|
||||||
rooms.push_back("04.room");
|
rooms_.push_back("04.room");
|
||||||
rooms.push_back("54.room");
|
rooms_.push_back("54.room");
|
||||||
rooms.push_back("20.room");
|
rooms_.push_back("20.room");
|
||||||
rooms.push_back("09.room");
|
rooms_.push_back("09.room");
|
||||||
rooms.push_back("05.room");
|
rooms_.push_back("05.room");
|
||||||
rooms.push_back("11.room");
|
rooms_.push_back("11.room");
|
||||||
rooms.push_back("31.room");
|
rooms_.push_back("31.room");
|
||||||
rooms.push_back("44.room");
|
rooms_.push_back("44.room");
|
||||||
|
|
||||||
roomIndex = 0;
|
room_index_ = 0;
|
||||||
currentRoom = rooms[roomIndex];
|
current_room_ = rooms_[room_index_];
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
ItemTracker::init();
|
ItemTracker::init();
|
||||||
scoreboard = std::make_shared<Scoreboard>(&board);
|
scoreboard_ = std::make_shared<Scoreboard>(&board_);
|
||||||
room = std::make_shared<Room>(resource->getRoom(currentRoom), &board.items, false);
|
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, false);
|
||||||
text = resource->getText("smb2");
|
text_ = resource_->getText("smb2");
|
||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
counter = 0;
|
counter_ = 0;
|
||||||
roomTime = 400;
|
room_time_ = 400;
|
||||||
ticks = 0;
|
ticks_ = 0;
|
||||||
ticksSpeed = 15;
|
board_.lives = 9;
|
||||||
board.lives = 9;
|
board_.items = 0;
|
||||||
board.items = 0;
|
board_.rooms = 1;
|
||||||
board.rooms = 1;
|
board_.jail_is_open = false;
|
||||||
board.jail_is_open = false;
|
board_.music = true;
|
||||||
board.music = true;
|
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
|
|
||||||
options.section.section = Section::DEMO;
|
options.section.section = Section::DEMO;
|
||||||
@@ -99,21 +98,21 @@ void Demo::run()
|
|||||||
void Demo::update()
|
void Demo::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
// Actualiza los objetos
|
// Actualiza los objetos
|
||||||
room->update();
|
room_->update();
|
||||||
scoreboard->update();
|
scoreboard_->update();
|
||||||
screen->updateFX();
|
screen_->updateFX();
|
||||||
checkRoomChange();
|
checkRoomChange();
|
||||||
|
|
||||||
screen->update();
|
screen_->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,18 +120,18 @@ void Demo::update()
|
|||||||
void Demo::render()
|
void Demo::render()
|
||||||
{
|
{
|
||||||
// Prepara para dibujar el frame
|
// Prepara para dibujar el frame
|
||||||
screen->start();
|
screen_->start();
|
||||||
|
|
||||||
// Dibuja los elementos del juego en orden
|
// Dibuja los elementos del juego en orden
|
||||||
room->renderMap();
|
room_->renderMap();
|
||||||
room->renderEnemies();
|
room_->renderEnemies();
|
||||||
room->renderItems();
|
room_->renderItems();
|
||||||
renderRoomName();
|
renderRoomName();
|
||||||
scoreboard->render();
|
scoreboard_->render();
|
||||||
screen->renderFX();
|
screen_->renderFX();
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
screen->render();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
@@ -141,10 +140,10 @@ void Demo::renderRoomName()
|
|||||||
// Texto en el centro de la pantalla
|
// Texto en el centro de la pantalla
|
||||||
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
|
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
|
||||||
Color color = stringToColor(options.video.palette, "white");
|
Color color = stringToColor(options.video.palette, "white");
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room->getName(), 1, room->getBGColor());
|
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, 16 * 8 + 4, room_->getName(), 1, room_->getBGColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
@@ -154,9 +153,9 @@ void Demo::reLoadTextures()
|
|||||||
{
|
{
|
||||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||||
}
|
}
|
||||||
room->reLoadTexture();
|
room_->reLoadTexture();
|
||||||
scoreboard->reLoadTexture();
|
scoreboard_->reLoadTexture();
|
||||||
text->reLoadTexture();
|
text_->reLoadTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
@@ -172,8 +171,8 @@ void Demo::switchPalette()
|
|||||||
options.video.palette = Palette::ZXSPECTRUM;
|
options.video.palette = Palette::ZXSPECTRUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
room->reLoadPalette();
|
room_->reLoadPalette();
|
||||||
scoreboard->reLoadPalette();
|
scoreboard_->reLoadPalette();
|
||||||
|
|
||||||
// Pone el color del marcador en función del color del borde de la habitación
|
// Pone el color del marcador en función del color del borde de la habitación
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
@@ -186,10 +185,10 @@ bool Demo::changeRoom(std::string file)
|
|||||||
if (file != "0")
|
if (file != "0")
|
||||||
{
|
{
|
||||||
// Verifica que exista el fichero que se va a cargar
|
// Verifica que exista el fichero que se va a cargar
|
||||||
if (asset->get(file) != "")
|
if (asset_->get(file) != "")
|
||||||
{
|
{
|
||||||
// Crea un objeto habitación a partir del fichero
|
// Crea un objeto habitación a partir del fichero
|
||||||
room = std::make_shared<Room>(resource->getRoom(file), &board.items, false);
|
room_ = std::make_shared<Room>(resource_->getRoom(file), &board_.items, false);
|
||||||
|
|
||||||
// Pone el color del marcador en función del color del borde de la habitación
|
// Pone el color del marcador en función del color del borde de la habitación
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
@@ -204,19 +203,19 @@ bool Demo::changeRoom(std::string file)
|
|||||||
// Comprueba si se ha de cambiar de habitación
|
// Comprueba si se ha de cambiar de habitación
|
||||||
void Demo::checkRoomChange()
|
void Demo::checkRoomChange()
|
||||||
{
|
{
|
||||||
counter++;
|
counter_++;
|
||||||
if (counter == roomTime)
|
if (counter_ == room_time_)
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter_ = 0;
|
||||||
roomIndex++;
|
room_index_++;
|
||||||
if (roomIndex == (int)rooms.size())
|
if (room_index_ == (int)rooms_.size())
|
||||||
{
|
{
|
||||||
options.section.section = Section::LOGO;
|
options.section.section = Section::LOGO;
|
||||||
options.section.subsection = Subsection::LOGO_TO_TITLE;
|
options.section.subsection = Subsection::LOGO_TO_TITLE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
changeRoom(rooms[roomIndex]);
|
changeRoom(rooms_[room_index_]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,13 +224,13 @@ void Demo::checkRoomChange()
|
|||||||
void Demo::setScoreBoardColor()
|
void Demo::setScoreBoardColor()
|
||||||
{
|
{
|
||||||
// Obtiene el color del borde
|
// Obtiene el color del borde
|
||||||
const Color color = room->getBorderColor();
|
const Color color = room_->getBorderColor();
|
||||||
|
|
||||||
// Si el color es negro lo cambia a blanco
|
// Si el color es negro lo cambia a blanco
|
||||||
const Color black_color = stringToColor(options.video.palette, "black");
|
const Color black_color = stringToColor(options.video.palette, "black");
|
||||||
board.color = colorAreEqual(color, black_color) ? stringToColor(options.video.palette, "white") : color;
|
board_.color = colorAreEqual(color, black_color) ? stringToColor(options.video.palette, "white") : color;
|
||||||
|
|
||||||
// Si el color es negro brillante lo cambia a blanco
|
// Si el color es negro brillante lo cambia a blanco
|
||||||
const Color bright_blac_color = stringToColor(options.video.palette, "bright_black");
|
const Color bright_blac_color = stringToColor(options.video.palette, "bright_black");
|
||||||
board.color = colorAreEqual(color, bright_blac_color) ? stringToColor(options.video.palette, "white") : color;
|
board_.color = colorAreEqual(color, bright_blac_color) ? stringToColor(options.video.palette, "white") : color;
|
||||||
}
|
}
|
||||||
@@ -19,25 +19,24 @@ class Demo
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen; // Objeto encargado de manejar el renderizador
|
Screen *screen_; // Objeto encargado de manejar el renderizador
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
Debug *debug; // Objeto para gestionar la información de debug
|
Debug *debug_; // Objeto para gestionar la información de debug
|
||||||
std::shared_ptr<Room> room; // Objeto encargado de gestionar cada habitación del juego
|
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
|
||||||
std::shared_ptr<Text> text; // Objeto para los textos del juego
|
std::shared_ptr<Text> text_; // Objeto para los textos del juego
|
||||||
std::shared_ptr<Scoreboard> scoreboard; // Objeto encargado de gestionar el marcador
|
std::shared_ptr<Scoreboard> scoreboard_; // Objeto encargado de gestionar el marcador
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
std::string current_room_; // Fichero de la habitación actual
|
||||||
std::string currentRoom; // Fichero de la habitación actual
|
ScoreboardData board_; // Estructura con los datos del marcador
|
||||||
ScoreboardData board; // Estructura con los datos del marcador
|
int counter_; // Contador para el modo demo
|
||||||
int counter; // Contador para el modo demo
|
int room_time_; // Tiempo que se muestra cada habitacion
|
||||||
int roomTime; // Tiempo que se muestra cada habitacion
|
int room_index_; // Indice para el vector de habitaciones
|
||||||
int roomIndex; // Indice para el vector de habitaciones
|
std::vector<std::string> rooms_; // Listado con los mapas de la demo
|
||||||
std::vector<std::string> rooms; // Listado con los mapas de la demo
|
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ Director::Director(int argc, const char *argv[])
|
|||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||||
initInput();
|
initInput();
|
||||||
Debug::init();
|
Debug::init();
|
||||||
title_music_ = Resource::get()->getMusic("title.ogg");
|
|
||||||
Cheevos::init(Asset::get()->get("cheevos.bin"));
|
Cheevos::init(Asset::get()->get("cheevos.bin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,10 +745,6 @@ void Director::runLoadingScreen()
|
|||||||
// Ejecuta la seccion de juego con el titulo y los menus
|
// Ejecuta la seccion de juego con el titulo y los menus
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
|
||||||
{
|
|
||||||
JA_PlayMusic(title_music_);
|
|
||||||
}
|
|
||||||
auto title = std::make_unique<Title>();
|
auto title = std::make_unique<Title>();
|
||||||
title->run();
|
title->run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ private:
|
|||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
JA_Music_t *title_music_; // Musica del titulo
|
|
||||||
std::string executable_path_; // Path del ejecutable
|
std::string executable_path_; // Path del ejecutable
|
||||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,46 @@
|
|||||||
#include "ending.h"
|
#include "ending.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <algorithm> // for min
|
#include <algorithm> // for min
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "input.h" // for Input
|
#include "input.h" // for Input
|
||||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "text.h" // for Text, TEXT_STROKE
|
#include "text.h" // for Text, TEXT_STROKE
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor, Palette
|
#include "utils.h" // for Color, stringToColor, Palette
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending::Ending()
|
Ending::Ending()
|
||||||
: screen(Screen::get()),
|
: screen_(Screen::get()),
|
||||||
renderer(Screen::get()->getRenderer()),
|
renderer_(Screen::get()->getRenderer()),
|
||||||
resource(Resource::get()),
|
resource_(Resource::get()),
|
||||||
asset(Asset::get()),
|
asset_(Asset::get()),
|
||||||
input(Input::get())
|
input_(Input::get())
|
||||||
{
|
{
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
text = resource->getText("smb2");
|
text_ = resource_->getText("smb2");
|
||||||
music = resource->getMusic("ending1.ogg");
|
music = resource_->getMusic("ending1.ogg");
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter = -1;
|
counter_ = -1;
|
||||||
preCounter = 0;
|
pre_counter_ = 0;
|
||||||
coverCounter = 0;
|
cover_counter_ = 0;
|
||||||
options.section.section = Section::ENDING;
|
options.section.section = Section::ENDING;
|
||||||
options.section.subsection = Subsection::NONE;
|
options.section.subsection = Subsection::NONE;
|
||||||
ticks = 0;
|
ticks_ = 0;
|
||||||
ticksSpeed = 15;
|
current_scene_ = 0;
|
||||||
scene = 0;
|
|
||||||
|
|
||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
iniTexts();
|
iniTexts();
|
||||||
@@ -53,18 +52,18 @@ Ending::Ending()
|
|||||||
iniScenes();
|
iniScenes();
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options.video.palette, "black"));
|
screen_->setBorderColor(stringToColor(options.video.palette, "black"));
|
||||||
|
|
||||||
// Crea la textura para cubrir el rexto
|
// Crea la textura para cubrir el rexto
|
||||||
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
|
cover_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
|
||||||
if (coverTexture == nullptr)
|
if (cover_texture_ == nullptr)
|
||||||
{
|
{
|
||||||
if (options.console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(cover_texture_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Rellena la textura para la cortinilla
|
// Rellena la textura para la cortinilla
|
||||||
fillCoverTexture();
|
fillCoverTexture();
|
||||||
@@ -74,17 +73,17 @@ Ending::Ending()
|
|||||||
Ending::~Ending()
|
Ending::~Ending()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
SDL_DestroyTexture(coverTexture);
|
SDL_DestroyTexture(cover_texture_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
void Ending::update()
|
void Ending::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -101,7 +100,7 @@ void Ending::update()
|
|||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
screen->update();
|
screen_->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,22 +108,22 @@ void Ending::update()
|
|||||||
void Ending::render()
|
void Ending::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen_->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(stringToColor(options.video.palette, "black"));
|
screen_->clean(stringToColor(options.video.palette, "black"));
|
||||||
|
|
||||||
// Dibuja las imagenes de la escena
|
// Dibuja las imagenes de la escena
|
||||||
spritePics[scene].sprite->render();
|
sprite_pics_[current_scene_].sprite->render();
|
||||||
spritePics[scene].coverSprite->render();
|
sprite_pics_[current_scene_].cover_sprite->render();
|
||||||
|
|
||||||
// Dibuja los textos de la escena
|
// Dibuja los textos de la escena
|
||||||
for (auto ti : scenes[scene].textIndex)
|
for (auto ti : scenes_[current_scene_].text_index)
|
||||||
{
|
{
|
||||||
if (counter > ti.trigger)
|
if (counter_ > ti.trigger)
|
||||||
{
|
{
|
||||||
spriteTexts[ti.index].sprite->render();
|
sprite_texts_[ti.index].sprite->render();
|
||||||
spriteTexts[ti.index].coverSprite->render();
|
sprite_texts_[ti.index].cover_sprite->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +131,7 @@ void Ending::render()
|
|||||||
renderCoverTexture();
|
renderCoverTexture();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->render();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
@@ -155,7 +154,7 @@ void Ending::checkInput()
|
|||||||
void Ending::iniTexts()
|
void Ending::iniTexts()
|
||||||
{
|
{
|
||||||
// Vector con los textos
|
// Vector con los textos
|
||||||
std::vector<textAndPos_t> texts;
|
std::vector<TextAndPosition> texts;
|
||||||
|
|
||||||
// Escena #0
|
// Escena #0
|
||||||
texts.push_back({"HE FINALLY MANAGED", 32});
|
texts.push_back({"HE FINALLY MANAGED", 32});
|
||||||
@@ -187,66 +186,66 @@ void Ending::iniTexts()
|
|||||||
texts.push_back({"WERE BORN...", 158});
|
texts.push_back({"WERE BORN...", 158});
|
||||||
|
|
||||||
// Crea los sprites
|
// Crea los sprites
|
||||||
spriteTexts.clear();
|
sprite_texts_.clear();
|
||||||
|
|
||||||
for (auto t : texts)
|
for (auto t : texts)
|
||||||
{
|
{
|
||||||
endingTexture_t st;
|
EndingTexture st;
|
||||||
const int width = text->lenght(t.caption, 1) + 2 + 2;
|
const int width = text_->lenght(t.caption, 1) + 2 + 2;
|
||||||
const int height = text->getCharacterSize() + 2 + 2;
|
const int height = text_->getCharacterSize() + 2 + 2;
|
||||||
Color c = stringToColor(options.video.palette, "black");
|
Color c = stringToColor(options.video.palette, "black");
|
||||||
|
|
||||||
// Crea la texture
|
// Crea la texture
|
||||||
st.texture = std::make_shared<Texture>(renderer);
|
st.texture = std::make_shared<Texture>(renderer_);
|
||||||
st.texture->createBlank(width, height);
|
st.texture->createBlank(width, height);
|
||||||
st.texture->setAsRenderTarget(renderer);
|
st.texture->setAsRenderTarget(renderer_);
|
||||||
st.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
st.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
text->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, c, 2, c);
|
text_->writeDX(TEXT_STROKE, 2, 2, t.caption, 1, c, 2, c);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
st.sprite = std::make_shared<Sprite>(st.texture, 0, 0, st.texture->getWidth(), st.texture->getHeight());
|
st.sprite = std::make_shared<Sprite>(st.texture, 0, 0, st.texture->getWidth(), st.texture->getHeight());
|
||||||
st.sprite->setPosition((GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos);
|
st.sprite->setPosition((GAMECANVAS_WIDTH - st.texture->getWidth()) / 2, t.pos);
|
||||||
|
|
||||||
// Crea la coverTexture
|
// Crea la coverTexture
|
||||||
st.coverTexture = std::make_shared<Texture>(renderer);
|
st.cover_texture = std::make_shared<Texture>(renderer_);
|
||||||
st.coverTexture->createBlank(width, height + 8);
|
st.cover_texture->createBlank(width, height + 8);
|
||||||
st.coverTexture->setAsRenderTarget(renderer);
|
st.cover_texture->setAsRenderTarget(renderer_);
|
||||||
st.coverTexture->setBlendMode(SDL_BLENDMODE_BLEND);
|
st.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Rellena la coverTexture con color transparente
|
// Rellena la coverTexture con color transparente
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
c = stringToColor(options.video.palette, "black");
|
c = stringToColor(options.video.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||||
for (int i = 0; i < width; i += 2)
|
for (int i = 0; i < width; i += 2)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawPoint(renderer, i, 0);
|
SDL_RenderDrawPoint(renderer_, i, 0);
|
||||||
SDL_RenderDrawPoint(renderer, i, 2);
|
SDL_RenderDrawPoint(renderer_, i, 2);
|
||||||
SDL_RenderDrawPoint(renderer, i, 4);
|
SDL_RenderDrawPoint(renderer_, i, 4);
|
||||||
SDL_RenderDrawPoint(renderer, i, 6);
|
SDL_RenderDrawPoint(renderer_, i, 6);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 5);
|
SDL_RenderDrawPoint(renderer_, i + 1, 5);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 7);
|
SDL_RenderDrawPoint(renderer_, i + 1, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 8, width, height};
|
SDL_Rect rect = {0, 8, width, height};
|
||||||
c = stringToColor(options.video.palette, "black");
|
c = stringToColor(options.video.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
st.coverSprite = std::make_shared<Sprite>(st.coverTexture, 0, 0, st.coverTexture->getWidth(), st.coverTexture->getHeight() - 8);
|
st.cover_sprite = std::make_shared<Sprite>(st.cover_texture, 0, 0, st.cover_texture->getWidth(), st.cover_texture->getHeight() - 8);
|
||||||
st.coverSprite->setPosition((GAMECANVAS_WIDTH - st.coverTexture->getWidth()) / 2, t.pos);
|
st.cover_sprite->setPosition((GAMECANVAS_WIDTH - st.cover_texture->getWidth()) / 2, t.pos);
|
||||||
st.coverSprite->setClip(0, 8, -1, -1);
|
st.cover_sprite->setClip(0, 8, -1, -1);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
st.clipDesp = 8;
|
st.clip_desp = 8;
|
||||||
st.clipHeight = height;
|
st.clip_height = height;
|
||||||
|
|
||||||
spriteTexts.push_back(st);
|
sprite_texts_.push_back(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +253,7 @@ void Ending::iniTexts()
|
|||||||
void Ending::iniPics()
|
void Ending::iniPics()
|
||||||
{
|
{
|
||||||
// Vector con las rutas y la posición
|
// Vector con las rutas y la posición
|
||||||
std::vector<textAndPos_t> pics;
|
std::vector<TextAndPosition> pics;
|
||||||
|
|
||||||
if (options.video.palette == Palette::ZXSPECTRUM)
|
if (options.video.palette == Palette::ZXSPECTRUM)
|
||||||
{
|
{
|
||||||
@@ -274,14 +273,14 @@ void Ending::iniPics()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea los sprites
|
// Crea los sprites
|
||||||
spritePics.clear();
|
sprite_pics_.clear();
|
||||||
|
|
||||||
for (auto p : pics)
|
for (auto p : pics)
|
||||||
{
|
{
|
||||||
endingTexture_t sp;
|
EndingTexture sp;
|
||||||
|
|
||||||
// Crea la texture
|
// Crea la texture
|
||||||
sp.texture = resource->getTexture(p.caption);
|
sp.texture = resource_->getTexture(p.caption);
|
||||||
const int width = sp.texture->getWidth();
|
const int width = sp.texture->getWidth();
|
||||||
const int height = sp.texture->getHeight();
|
const int height = sp.texture->getHeight();
|
||||||
|
|
||||||
@@ -290,45 +289,45 @@ void Ending::iniPics()
|
|||||||
sp.sprite->setPosition((GAMECANVAS_WIDTH - width) / 2, p.pos);
|
sp.sprite->setPosition((GAMECANVAS_WIDTH - width) / 2, p.pos);
|
||||||
|
|
||||||
// Crea la coverTexture
|
// Crea la coverTexture
|
||||||
sp.coverTexture = std::make_shared<Texture>(renderer);
|
sp.cover_texture = std::make_shared<Texture>(renderer_);
|
||||||
sp.coverTexture->createBlank(width, height + 8);
|
sp.cover_texture->createBlank(width, height + 8);
|
||||||
sp.coverTexture->setAsRenderTarget(renderer);
|
sp.cover_texture->setAsRenderTarget(renderer_);
|
||||||
sp.coverTexture->setBlendMode(SDL_BLENDMODE_BLEND);
|
sp.cover_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Rellena la coverTexture con color transparente
|
// Rellena la coverTexture con color transparente
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
Color c = stringToColor(options.video.palette, "black");
|
Color c = stringToColor(options.video.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||||
for (int i = 0; i < width; i += 2)
|
for (int i = 0; i < width; i += 2)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawPoint(renderer, i, 0);
|
SDL_RenderDrawPoint(renderer_, i, 0);
|
||||||
SDL_RenderDrawPoint(renderer, i, 2);
|
SDL_RenderDrawPoint(renderer_, i, 2);
|
||||||
SDL_RenderDrawPoint(renderer, i, 4);
|
SDL_RenderDrawPoint(renderer_, i, 4);
|
||||||
SDL_RenderDrawPoint(renderer, i, 6);
|
SDL_RenderDrawPoint(renderer_, i, 6);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 5);
|
SDL_RenderDrawPoint(renderer_, i + 1, 5);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 7);
|
SDL_RenderDrawPoint(renderer_, i + 1, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 8, width, height};
|
SDL_Rect rect = {0, 8, width, height};
|
||||||
c = stringToColor(options.video.palette, "black");
|
c = stringToColor(options.video.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
sp.coverSprite = std::make_shared<Sprite>(sp.coverTexture, 0, 0, sp.coverTexture->getWidth(), sp.coverTexture->getHeight() - 8);
|
sp.cover_sprite = std::make_shared<Sprite>(sp.cover_texture, 0, 0, sp.cover_texture->getWidth(), sp.cover_texture->getHeight() - 8);
|
||||||
sp.coverSprite->setPosition((GAMECANVAS_WIDTH - sp.coverTexture->getWidth()) / 2, p.pos);
|
sp.cover_sprite->setPosition((GAMECANVAS_WIDTH - sp.cover_texture->getWidth()) / 2, p.pos);
|
||||||
sp.coverSprite->setClip(0, 8, -1, -1);
|
sp.cover_sprite->setClip(0, 8, -1, -1);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
sp.clipDesp = 8;
|
sp.clip_desp = 8;
|
||||||
sp.clipHeight = height;
|
sp.clip_height = height;
|
||||||
|
|
||||||
spritePics.push_back(sp);
|
sprite_pics_.push_back(sp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,79 +339,79 @@ void Ending::iniScenes()
|
|||||||
const int lapse = 80;
|
const int lapse = 80;
|
||||||
|
|
||||||
// Crea el contenedor
|
// Crea el contenedor
|
||||||
scene_t sc;
|
SceneData sc;
|
||||||
|
|
||||||
// Inicializa el vector
|
// Inicializa el vector
|
||||||
scenes.clear();
|
scenes_.clear();
|
||||||
|
|
||||||
// Crea la escena #0
|
// Crea la escena #0
|
||||||
sc.counterEnd = 1000;
|
sc.counter_end = 1000;
|
||||||
sc.pictureIndex = 0;
|
sc.picture_index = 0;
|
||||||
sc.textIndex.clear();
|
sc.text_index.clear();
|
||||||
trigger = 85 * 2;
|
trigger = 85 * 2;
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({0, trigger});
|
sc.text_index.push_back({0, trigger});
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({1, trigger});
|
sc.text_index.push_back({1, trigger});
|
||||||
trigger += lapse * 3;
|
trigger += lapse * 3;
|
||||||
sc.textIndex.push_back({2, trigger});
|
sc.text_index.push_back({2, trigger});
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({3, trigger});
|
sc.text_index.push_back({3, trigger});
|
||||||
scenes.push_back(sc);
|
scenes_.push_back(sc);
|
||||||
|
|
||||||
// Crea la escena #1
|
// Crea la escena #1
|
||||||
sc.counterEnd = 1400;
|
sc.counter_end = 1400;
|
||||||
sc.pictureIndex = 1;
|
sc.picture_index = 1;
|
||||||
sc.textIndex.clear();
|
sc.text_index.clear();
|
||||||
trigger = 140 * 2;
|
trigger = 140 * 2;
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({4, trigger});
|
sc.text_index.push_back({4, trigger});
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({5, trigger});
|
sc.text_index.push_back({5, trigger});
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({6, trigger});
|
sc.text_index.push_back({6, trigger});
|
||||||
trigger += lapse * 3;
|
trigger += lapse * 3;
|
||||||
sc.textIndex.push_back({7, trigger});
|
sc.text_index.push_back({7, trigger});
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({8, trigger});
|
sc.text_index.push_back({8, trigger});
|
||||||
trigger += lapse * 3;
|
trigger += lapse * 3;
|
||||||
sc.textIndex.push_back({9, trigger});
|
sc.text_index.push_back({9, trigger});
|
||||||
scenes.push_back(sc);
|
scenes_.push_back(sc);
|
||||||
|
|
||||||
// Crea la escena #2
|
// Crea la escena #2
|
||||||
sc.counterEnd = 1000;
|
sc.counter_end = 1000;
|
||||||
sc.pictureIndex = 2;
|
sc.picture_index = 2;
|
||||||
sc.textIndex.clear();
|
sc.text_index.clear();
|
||||||
trigger = 148 / 2;
|
trigger = 148 / 2;
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({10, trigger});
|
sc.text_index.push_back({10, trigger});
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({11, trigger});
|
sc.text_index.push_back({11, trigger});
|
||||||
scenes.push_back(sc);
|
scenes_.push_back(sc);
|
||||||
|
|
||||||
// Crea la escena #3
|
// Crea la escena #3
|
||||||
sc.counterEnd = 800;
|
sc.counter_end = 800;
|
||||||
sc.pictureIndex = 3;
|
sc.picture_index = 3;
|
||||||
sc.textIndex.clear();
|
sc.text_index.clear();
|
||||||
trigger = 87 / 2;
|
trigger = 87 / 2;
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({12, trigger});
|
sc.text_index.push_back({12, trigger});
|
||||||
trigger += lapse / 2;
|
trigger += lapse / 2;
|
||||||
sc.textIndex.push_back({13, trigger});
|
sc.text_index.push_back({13, trigger});
|
||||||
scenes.push_back(sc);
|
scenes_.push_back(sc);
|
||||||
|
|
||||||
// Crea la escena #4
|
// Crea la escena #4
|
||||||
sc.counterEnd = 1000;
|
sc.counter_end = 1000;
|
||||||
sc.pictureIndex = 4;
|
sc.picture_index = 4;
|
||||||
sc.textIndex.clear();
|
sc.text_index.clear();
|
||||||
trigger = 91 * 2;
|
trigger = 91 * 2;
|
||||||
trigger += lapse;
|
trigger += lapse;
|
||||||
sc.textIndex.push_back({14, trigger});
|
sc.text_index.push_back({14, trigger});
|
||||||
trigger += lapse * 2;
|
trigger += lapse * 2;
|
||||||
sc.textIndex.push_back({15, trigger});
|
sc.text_index.push_back({15, trigger});
|
||||||
trigger += lapse * 3;
|
trigger += lapse * 3;
|
||||||
sc.textIndex.push_back({16, trigger});
|
sc.text_index.push_back({16, trigger});
|
||||||
scenes.push_back(sc);
|
scenes_.push_back(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
@@ -435,80 +434,80 @@ void Ending::run()
|
|||||||
void Ending::updateCounters()
|
void Ending::updateCounters()
|
||||||
{
|
{
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
if (preCounter < 200)
|
if (pre_counter_ < 200)
|
||||||
{
|
{
|
||||||
preCounter++;
|
pre_counter_++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
counter++;
|
counter_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter > scenes[scene].counterEnd - 100)
|
if (counter_ > scenes_[current_scene_].counter_end - 100)
|
||||||
{
|
{
|
||||||
coverCounter++;
|
cover_counter_++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las cortinillas de los elementos
|
// Actualiza las cortinillas de los elementos
|
||||||
void Ending::updateSpriteCovers()
|
void Ending::updateSpriteCovers()
|
||||||
{ // Actualiza la cortinilla de los textos
|
{ // Actualiza la cortinilla de los textos
|
||||||
if (counter % 4 == 0)
|
if (counter_ % 4 == 0)
|
||||||
{
|
{
|
||||||
for (auto ti : scenes[scene].textIndex)
|
for (auto ti : scenes_[current_scene_].text_index)
|
||||||
{
|
{
|
||||||
if (counter > ti.trigger)
|
if (counter_ > ti.trigger)
|
||||||
{
|
{
|
||||||
if (spriteTexts[ti.index].clipDesp > 0)
|
if (sprite_texts_[ti.index].clip_desp > 0)
|
||||||
{
|
{
|
||||||
spriteTexts[ti.index].clipDesp -= 2;
|
sprite_texts_[ti.index].clip_desp -= 2;
|
||||||
}
|
}
|
||||||
else if (spriteTexts[ti.index].clipHeight > 0)
|
else if (sprite_texts_[ti.index].clip_height > 0)
|
||||||
{
|
{
|
||||||
spriteTexts[ti.index].clipHeight -= 2;
|
sprite_texts_[ti.index].clip_height -= 2;
|
||||||
spriteTexts[ti.index].coverSprite->setY(spriteTexts[ti.index].coverSprite->getY() + 2);
|
sprite_texts_[ti.index].cover_sprite->setY(sprite_texts_[ti.index].cover_sprite->getY() + 2);
|
||||||
}
|
}
|
||||||
spriteTexts[ti.index].coverSprite->setClip(0, spriteTexts[ti.index].clipDesp, spriteTexts[ti.index].coverSprite->getWidth(), spriteTexts[ti.index].clipHeight);
|
sprite_texts_[ti.index].cover_sprite->setClip(0, sprite_texts_[ti.index].clip_desp, sprite_texts_[ti.index].cover_sprite->getWidth(), sprite_texts_[ti.index].clip_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la cortinilla de las imagenes
|
// Actualiza la cortinilla de las imagenes
|
||||||
if (counter % 2 == 0)
|
if (counter_ % 2 == 0)
|
||||||
{
|
{
|
||||||
if (spritePics[scene].clipDesp > 0)
|
if (sprite_pics_[current_scene_].clip_desp > 0)
|
||||||
{
|
{
|
||||||
spritePics[scene].clipDesp -= 2;
|
sprite_pics_[current_scene_].clip_desp -= 2;
|
||||||
}
|
}
|
||||||
else if (spritePics[scene].clipHeight > 0)
|
else if (sprite_pics_[current_scene_].clip_height > 0)
|
||||||
{
|
{
|
||||||
spritePics[scene].clipHeight -= 2;
|
sprite_pics_[current_scene_].clip_height -= 2;
|
||||||
if (spritePics[scene].clipHeight < 0)
|
if (sprite_pics_[current_scene_].clip_height < 0)
|
||||||
{
|
{
|
||||||
spritePics[scene].clipHeight = 0;
|
sprite_pics_[current_scene_].clip_height = 0;
|
||||||
}
|
}
|
||||||
spritePics[scene].coverSprite->setY(spritePics[scene].coverSprite->getY() + 2);
|
sprite_pics_[current_scene_].cover_sprite->setY(sprite_pics_[current_scene_].cover_sprite->getY() + 2);
|
||||||
}
|
}
|
||||||
spritePics[scene].coverSprite->setClip(0, spritePics[scene].clipDesp, spritePics[scene].coverSprite->getWidth(), spritePics[scene].clipHeight);
|
sprite_pics_[current_scene_].cover_sprite->setClip(0, sprite_pics_[current_scene_].clip_desp, sprite_pics_[current_scene_].cover_sprite->getWidth(), sprite_pics_[current_scene_].clip_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si se ha de cambiar de escena
|
// Comprueba si se ha de cambiar de escena
|
||||||
void Ending::checkChangeScene()
|
void Ending::checkChangeScene()
|
||||||
{
|
{
|
||||||
if (counter > scenes[scene].counterEnd)
|
if (counter_ > scenes_[current_scene_].counter_end)
|
||||||
{
|
{
|
||||||
scene++;
|
current_scene_++;
|
||||||
counter = 0;
|
counter_ = 0;
|
||||||
coverCounter = 0;
|
cover_counter_ = 0;
|
||||||
if (scene == 5)
|
if (current_scene_ == 5)
|
||||||
{
|
{
|
||||||
// Termina el bucle
|
// Termina el bucle
|
||||||
options.section.section = Section::ENDING2;
|
options.section.section = Section::ENDING2;
|
||||||
|
|
||||||
// Mantiene los valores anteriores
|
// Mantiene los valores anteriores
|
||||||
scene = 4;
|
current_scene_ = 4;
|
||||||
coverCounter = 100;
|
cover_counter_ = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -517,49 +516,49 @@ void Ending::checkChangeScene()
|
|||||||
void Ending::fillCoverTexture()
|
void Ending::fillCoverTexture()
|
||||||
{
|
{
|
||||||
// Rellena la textura que cubre el texto con color transparente
|
// Rellena la textura que cubre el texto con color transparente
|
||||||
SDL_SetRenderTarget(renderer, coverTexture);
|
SDL_SetRenderTarget(renderer_, cover_texture_);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
const Color color = stringToColor(options.video.palette, "black");
|
const Color color = stringToColor(options.video.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
for (int i = 0; i < 256; i += 2)
|
for (int i = 0; i < 256; i += 2)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawPoint(renderer, i + 0, GAMECANVAS_HEIGHT + 0);
|
SDL_RenderDrawPoint(renderer_, i + 0, GAMECANVAS_HEIGHT + 0);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, GAMECANVAS_HEIGHT + 1);
|
SDL_RenderDrawPoint(renderer_, i + 1, GAMECANVAS_HEIGHT + 1);
|
||||||
SDL_RenderDrawPoint(renderer, i + 0, GAMECANVAS_HEIGHT + 2);
|
SDL_RenderDrawPoint(renderer_, i + 0, GAMECANVAS_HEIGHT + 2);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, GAMECANVAS_HEIGHT + 3);
|
SDL_RenderDrawPoint(renderer_, i + 1, GAMECANVAS_HEIGHT + 3);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i, GAMECANVAS_HEIGHT + 4);
|
SDL_RenderDrawPoint(renderer_, i, GAMECANVAS_HEIGHT + 4);
|
||||||
SDL_RenderDrawPoint(renderer, i, GAMECANVAS_HEIGHT + 6);
|
SDL_RenderDrawPoint(renderer_, i, GAMECANVAS_HEIGHT + 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT};
|
SDL_Rect rect = {0, 0, 256, GAMECANVAS_HEIGHT};
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja la cortinilla de cambio de escena
|
// Dibuja la cortinilla de cambio de escena
|
||||||
void Ending::renderCoverTexture()
|
void Ending::renderCoverTexture()
|
||||||
{
|
{
|
||||||
if (coverCounter > 0)
|
if (cover_counter_ > 0)
|
||||||
{ // Dibuja la textura que cubre el texto
|
{ // Dibuja la textura que cubre el texto
|
||||||
const int offset = std::min(coverCounter, 100);
|
const int offset = std::min(cover_counter_, 100);
|
||||||
SDL_Rect srcRect = {0, 200 - (coverCounter * 2), 256, offset * 2};
|
SDL_Rect srcRect = {0, 200 - (cover_counter_ * 2), 256, offset * 2};
|
||||||
SDL_Rect dstRect = {0, 0, 256, offset * 2};
|
SDL_Rect dstRect = {0, 0, 256, offset * 2};
|
||||||
SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
|
SDL_RenderCopy(renderer_, cover_texture_, &srcRect, &dstRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
void Ending::updateMusicVolume()
|
void Ending::updateMusicVolume()
|
||||||
{
|
{
|
||||||
if (scene == 4 && coverCounter > 0)
|
if (current_scene_ == 4 && cover_counter_ > 0)
|
||||||
{
|
{
|
||||||
const float step = (100.0f - coverCounter) / 100.0f;
|
const float step = (100.0f - cover_counter_) / 100.0f;
|
||||||
const int volume = 128 * step;
|
const int volume = 128 * step;
|
||||||
JA_SetVolume(volume);
|
JA_SetVolume(volume);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
class Asset; // lines 9-9
|
class Asset; // lines 9-9
|
||||||
class Input; // lines 10-10
|
class Input; // lines 10-10
|
||||||
class Resource; // lines 11-11
|
class Resource; // lines 11-11
|
||||||
class Screen; // lines 12-12
|
class Screen; // lines 12-12
|
||||||
class Sprite; // lines 13-13
|
class Sprite; // lines 13-13
|
||||||
class Text; // lines 14-14
|
class Text; // lines 14-14
|
||||||
class Texture; // lines 15-15
|
class Texture; // lines 15-15
|
||||||
struct JA_Music_t; // lines 16-16
|
struct JA_Music_t; // lines 16-16
|
||||||
|
|
||||||
class Ending
|
class Ending
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Estructuras
|
// Estructuras
|
||||||
struct endingTexture_t // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
|
struct EndingTexture // Estructura con dos texturas y sprites, uno para mostrar y el otro hace de cortinilla
|
||||||
{
|
{
|
||||||
std::shared_ptr<Texture> texture; // Textura a mostrar
|
std::shared_ptr<Texture> texture; // Textura a mostrar
|
||||||
std::shared_ptr<Sprite> sprite; // Sprite para mostrar la textura
|
std::shared_ptr<Sprite> sprite; // Sprite para mostrar la textura
|
||||||
std::shared_ptr<Texture> coverTexture; // Textura que cubre a la otra textura
|
std::shared_ptr<Texture> cover_texture; // Textura que cubre a la otra textura
|
||||||
std::shared_ptr<Sprite> coverSprite; // Sprite para mostrar la textura que cubre a la otra textura
|
std::shared_ptr<Sprite> cover_sprite; // Sprite para mostrar la textura que cubre a la otra textura
|
||||||
int clipDesp; // Desplazamiento del spriteClip de la textura de cobertura
|
int clip_desp; // Desplazamiento del spriteClip de la textura de cobertura
|
||||||
int clipHeight; // Altura del spriteClip de la textura de cobertura
|
int clip_height; // Altura del spriteClip de la textura de cobertura
|
||||||
};
|
};
|
||||||
|
|
||||||
struct textAndPos_t // Estructura con un texto y su posición en el eje Y
|
struct TextAndPosition // Estructura con un texto y su posición en el eje Y
|
||||||
{
|
{
|
||||||
std::string caption; // Texto
|
std::string caption; // Texto
|
||||||
int pos; // Posición
|
int pos; // Posición
|
||||||
@@ -40,32 +40,31 @@ private:
|
|||||||
int trigger;
|
int trigger;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct scene_t // Estructura para crear cada una de las escenas del final
|
struct SceneData // Estructura para crear cada una de las escenas del final
|
||||||
{
|
{
|
||||||
std::vector<asdhk> textIndex; // Indices del vector de textos a mostrar y su disparador
|
std::vector<asdhk> text_index; // Indices del vector de textos a mostrar y su disparador
|
||||||
int pictureIndex; // Indice del vector de imagenes a mostrar
|
int picture_index; // Indice del vector de imagenes a mostrar
|
||||||
int counterEnd; // Valor del contador en el que finaliza la escena
|
int counter_end; // Valor del contador en el que finaliza la escena
|
||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
std::shared_ptr<Text> text; // Objeto para escribir texto en pantalla
|
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
|
||||||
SDL_Texture *coverTexture; // Textura para cubrir el texto
|
SDL_Texture *cover_texture_; // Textura para cubrir el texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int counter; // Contador
|
int counter_; // Contador
|
||||||
int preCounter; // Contador previo
|
int pre_counter_; // Contador previo
|
||||||
int coverCounter; // Contador para la cortinilla
|
int cover_counter_; // Contador para la cortinilla
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
std::vector<EndingTexture> sprite_texts_; // Vector con los sprites de texto con su cortinilla
|
||||||
std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
|
std::vector<EndingTexture> sprite_pics_; // Vector con los sprites de texto con su cortinilla
|
||||||
std::vector<endingTexture_t> spritePics; // Vector con los sprites de texto con su cortinilla
|
int current_scene_; // Escena actual
|
||||||
int scene; // Escena actual
|
std::vector<SceneData> scenes_; // Vector con los textos e imagenes de cada escena
|
||||||
std::vector<scene_t> scenes; // Vector con los textos e imagenes de cada escena
|
|
||||||
JA_Music_t *music; // Musica que suena durante el final
|
JA_Music_t *music; // Musica que suena durante el final
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
|
|||||||
@@ -1,60 +1,57 @@
|
|||||||
#include "ending2.h"
|
#include "ending2.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <algorithm> // for max, min, replace
|
#include <algorithm> // for max, min, replace
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "animated_sprite.h" // for AnimatedSprite
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X
|
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "input.h" // for Input
|
#include "input.h" // for Input
|
||||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
||||||
#include "moving_sprite.h" // for MovingSprite
|
#include "moving_sprite.h" // for MovingSprite
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for Text
|
#include "text.h" // for Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor
|
#include "utils.h" // for Color, stringToColor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending2::Ending2()
|
Ending2::Ending2()
|
||||||
: screen(Screen::get()),
|
: screen_(Screen::get()),
|
||||||
renderer(Screen::get()->getRenderer()),
|
renderer_(Screen::get()->getRenderer()),
|
||||||
resource(Resource::get()),
|
resource_(Resource::get()),
|
||||||
asset(Asset::get()),
|
asset_(Asset::get()),
|
||||||
input(Input::get())
|
input_(Input::get())
|
||||||
{
|
{
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
text = resource->getText("smb2");
|
text_ = resource_->getText("smb2");
|
||||||
music = resource->getMusic("ending2.ogg");
|
music_ = resource_->getMusic("ending2.ogg");
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counterEnabled = false;
|
counter_enabled_ = false;
|
||||||
preCounter = 0;
|
pre_counter_ = 0;
|
||||||
postCounter = 0;
|
post_counter_ = 0;
|
||||||
postCounterEnabled = false;
|
post_counter_enabled_ = false;
|
||||||
options.section.section = Section::ENDING2;
|
options.section.section = Section::ENDING2;
|
||||||
options.section.subsection = Subsection::NONE;
|
options.section.subsection = Subsection::NONE;
|
||||||
ticks = 0;
|
ticks_ = 0;
|
||||||
ticksSpeed = 15;
|
dist_sprite_text_ = 8;
|
||||||
distSpriteText = 8;
|
dist_sprite_sprite_ = 0;
|
||||||
distSpriteSprite = 0;
|
sprite_desp_speed_ = -0.2f;
|
||||||
despSpeed = -0.2f;
|
|
||||||
firstCol = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16);
|
|
||||||
secondCol = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16);
|
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
const std::vector<std::string> color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
for (auto color : color_list)
|
for (auto color : color_list)
|
||||||
{
|
{
|
||||||
colors.push_back(stringToColor(options.video.palette, color));
|
colors_.push_back(stringToColor(options.video.palette, color));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options.video.palette, "black"));
|
screen_->setBorderColor(stringToColor(options.video.palette, "black"));
|
||||||
|
|
||||||
// Inicializa la lista de sprites
|
// Inicializa la lista de sprites
|
||||||
iniSpriteList();
|
iniSpriteList();
|
||||||
@@ -76,10 +73,10 @@ Ending2::Ending2()
|
|||||||
void Ending2::update()
|
void Ending2::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -87,7 +84,7 @@ void Ending2::update()
|
|||||||
// Actualiza los contadores
|
// Actualiza los contadores
|
||||||
updateCounters();
|
updateCounters();
|
||||||
|
|
||||||
if (counterEnabled)
|
if (counter_enabled_)
|
||||||
{
|
{
|
||||||
// Actualiza los sprites
|
// Actualiza los sprites
|
||||||
updateSprites();
|
updateSprites();
|
||||||
@@ -105,7 +102,7 @@ void Ending2::update()
|
|||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
screen->update();
|
screen_->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +110,10 @@ void Ending2::update()
|
|||||||
void Ending2::render()
|
void Ending2::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen_->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(stringToColor(options.video.palette, "black"));
|
screen_->clean(stringToColor(options.video.palette, "black"));
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
renderSprites();
|
renderSprites();
|
||||||
@@ -127,7 +124,7 @@ void Ending2::render()
|
|||||||
// Dibuja los sprites con el texto del final
|
// Dibuja los sprites con el texto del final
|
||||||
renderTexts();
|
renderTexts();
|
||||||
|
|
||||||
const std::string txt = std::to_string(postCounter);
|
const std::string txt = std::to_string(post_counter_);
|
||||||
// text->write(0, 192 - 8, txt);
|
// text->write(0, 192 - 8, txt);
|
||||||
|
|
||||||
// Dibuja la cuadricula
|
// Dibuja la cuadricula
|
||||||
@@ -147,24 +144,24 @@ void Ending2::render()
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Dibuja una trama arriba y abajo
|
// Dibuja una trama arriba y abajo
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0xFF);
|
||||||
for (int i = 0; i < 256; i += 2)
|
for (int i = 0; i < 256; i += 2)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawPoint(renderer, i + 0, 0);
|
SDL_RenderDrawPoint(renderer_, i + 0, 0);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 1);
|
SDL_RenderDrawPoint(renderer_, i + 1, 1);
|
||||||
SDL_RenderDrawPoint(renderer, i + 0, 2);
|
SDL_RenderDrawPoint(renderer_, i + 0, 2);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 3);
|
SDL_RenderDrawPoint(renderer_, i + 1, 3);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i, 4);
|
SDL_RenderDrawPoint(renderer_, i, 4);
|
||||||
SDL_RenderDrawPoint(renderer, i, 6);
|
SDL_RenderDrawPoint(renderer_, i, 6);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i + 0, 191);
|
SDL_RenderDrawPoint(renderer_, i + 0, 191);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 190);
|
SDL_RenderDrawPoint(renderer_, i + 1, 190);
|
||||||
SDL_RenderDrawPoint(renderer, i + 0, 189);
|
SDL_RenderDrawPoint(renderer_, i + 0, 189);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 188);
|
SDL_RenderDrawPoint(renderer_, i + 1, 188);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i, 187);
|
SDL_RenderDrawPoint(renderer_, i, 187);
|
||||||
SDL_RenderDrawPoint(renderer, i, 185);
|
SDL_RenderDrawPoint(renderer_, i, 185);
|
||||||
}
|
}
|
||||||
// SDL_RenderDrawLine(renderer, 0, 1, 255, 1);
|
// SDL_RenderDrawLine(renderer, 0, 1, 255, 1);
|
||||||
// SDL_RenderDrawLine(renderer, 0, 3, 255, 3);
|
// SDL_RenderDrawLine(renderer, 0, 3, 255, 3);
|
||||||
@@ -173,7 +170,7 @@ void Ending2::render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->render();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
@@ -195,7 +192,7 @@ void Ending2::checkInput()
|
|||||||
// Bucle principal
|
// Bucle principal
|
||||||
void Ending2::run()
|
void Ending2::run()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music);
|
JA_PlayMusic(music_);
|
||||||
|
|
||||||
while (options.section.section == Section::ENDING2)
|
while (options.section.section == Section::ENDING2)
|
||||||
{
|
{
|
||||||
@@ -212,21 +209,21 @@ void Ending2::run()
|
|||||||
void Ending2::updateCounters()
|
void Ending2::updateCounters()
|
||||||
{
|
{
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
if (preCounter < 200)
|
if (pre_counter_ < 200)
|
||||||
{
|
{
|
||||||
preCounter++;
|
pre_counter_++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
counterEnabled = true;
|
counter_enabled_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postCounterEnabled)
|
if (post_counter_enabled_)
|
||||||
{
|
{
|
||||||
postCounter++;
|
post_counter_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postCounter > 600)
|
if (post_counter_ > 600)
|
||||||
{
|
{
|
||||||
options.section.section = Section::LOGO;
|
options.section.section = Section::LOGO;
|
||||||
options.section.subsection = Subsection::LOGO_TO_INTRO;
|
options.section.subsection = Subsection::LOGO_TO_INTRO;
|
||||||
@@ -237,100 +234,100 @@ void Ending2::updateCounters()
|
|||||||
void Ending2::iniSpriteList()
|
void Ending2::iniSpriteList()
|
||||||
{
|
{
|
||||||
// Reinicia el vector
|
// Reinicia el vector
|
||||||
spriteList.clear();
|
sprite_list_.clear();
|
||||||
|
|
||||||
// Añade los valores
|
// Añade los valores
|
||||||
spriteList.push_back("bin");
|
sprite_list_.push_back("bin");
|
||||||
spriteList.push_back("floppy");
|
sprite_list_.push_back("floppy");
|
||||||
spriteList.push_back("bird");
|
sprite_list_.push_back("bird");
|
||||||
spriteList.push_back("chip");
|
sprite_list_.push_back("chip");
|
||||||
spriteList.push_back("jeannine");
|
sprite_list_.push_back("jeannine");
|
||||||
spriteList.push_back("spark");
|
sprite_list_.push_back("spark");
|
||||||
spriteList.push_back("code");
|
sprite_list_.push_back("code");
|
||||||
spriteList.push_back("paco");
|
sprite_list_.push_back("paco");
|
||||||
spriteList.push_back("elsa");
|
sprite_list_.push_back("elsa");
|
||||||
spriteList.push_back("z80");
|
sprite_list_.push_back("z80");
|
||||||
|
|
||||||
spriteList.push_back("bell");
|
sprite_list_.push_back("bell");
|
||||||
spriteList.push_back("dong");
|
sprite_list_.push_back("dong");
|
||||||
|
|
||||||
spriteList.push_back("amstrad_cs");
|
sprite_list_.push_back("amstrad_cs");
|
||||||
spriteList.push_back("breakout");
|
sprite_list_.push_back("breakout");
|
||||||
|
|
||||||
spriteList.push_back("flying_arounder");
|
sprite_list_.push_back("flying_arounder");
|
||||||
spriteList.push_back("stopped_arounder");
|
sprite_list_.push_back("stopped_arounder");
|
||||||
spriteList.push_back("walking_arounder");
|
sprite_list_.push_back("walking_arounder");
|
||||||
spriteList.push_back("arounders_door");
|
sprite_list_.push_back("arounders_door");
|
||||||
spriteList.push_back("arounders_machine");
|
sprite_list_.push_back("arounders_machine");
|
||||||
|
|
||||||
spriteList.push_back("abad");
|
sprite_list_.push_back("abad");
|
||||||
spriteList.push_back("abad_bell");
|
sprite_list_.push_back("abad_bell");
|
||||||
spriteList.push_back("lord_abad");
|
sprite_list_.push_back("lord_abad");
|
||||||
|
|
||||||
spriteList.push_back("bat");
|
sprite_list_.push_back("bat");
|
||||||
spriteList.push_back("batman_bell");
|
sprite_list_.push_back("batman_bell");
|
||||||
spriteList.push_back("batman_fire");
|
sprite_list_.push_back("batman_fire");
|
||||||
spriteList.push_back("batman");
|
sprite_list_.push_back("batman");
|
||||||
|
|
||||||
spriteList.push_back("demon");
|
sprite_list_.push_back("demon");
|
||||||
spriteList.push_back("heavy");
|
sprite_list_.push_back("heavy");
|
||||||
spriteList.push_back("dimallas");
|
sprite_list_.push_back("dimallas");
|
||||||
spriteList.push_back("guitar");
|
sprite_list_.push_back("guitar");
|
||||||
|
|
||||||
spriteList.push_back("jailbattle_alien");
|
sprite_list_.push_back("jailbattle_alien");
|
||||||
spriteList.push_back("jailbattle_human");
|
sprite_list_.push_back("jailbattle_human");
|
||||||
|
|
||||||
spriteList.push_back("jailer_#1");
|
sprite_list_.push_back("jailer_#1");
|
||||||
spriteList.push_back("jailer_#2");
|
sprite_list_.push_back("jailer_#2");
|
||||||
spriteList.push_back("jailer_#3");
|
sprite_list_.push_back("jailer_#3");
|
||||||
spriteList.push_back("bry");
|
sprite_list_.push_back("bry");
|
||||||
spriteList.push_back("upv_student");
|
sprite_list_.push_back("upv_student");
|
||||||
|
|
||||||
spriteList.push_back("lamp");
|
sprite_list_.push_back("lamp");
|
||||||
spriteList.push_back("robot");
|
sprite_list_.push_back("robot");
|
||||||
spriteList.push_back("congo");
|
sprite_list_.push_back("congo");
|
||||||
spriteList.push_back("crosshair");
|
sprite_list_.push_back("crosshair");
|
||||||
spriteList.push_back("tree_thing");
|
sprite_list_.push_back("tree_thing");
|
||||||
|
|
||||||
spriteList.push_back("matatunos");
|
sprite_list_.push_back("matatunos");
|
||||||
spriteList.push_back("tuno");
|
sprite_list_.push_back("tuno");
|
||||||
|
|
||||||
spriteList.push_back("mummy");
|
sprite_list_.push_back("mummy");
|
||||||
spriteList.push_back("sam");
|
sprite_list_.push_back("sam");
|
||||||
|
|
||||||
spriteList.push_back("qvoid");
|
sprite_list_.push_back("qvoid");
|
||||||
spriteList.push_back("sigmasua");
|
sprite_list_.push_back("sigmasua");
|
||||||
|
|
||||||
spriteList.push_back("tv_panel");
|
sprite_list_.push_back("tv_panel");
|
||||||
spriteList.push_back("tv");
|
sprite_list_.push_back("tv");
|
||||||
|
|
||||||
spriteList.push_back("spider");
|
sprite_list_.push_back("spider");
|
||||||
spriteList.push_back("shock");
|
sprite_list_.push_back("shock");
|
||||||
spriteList.push_back("wave");
|
sprite_list_.push_back("wave");
|
||||||
|
|
||||||
spriteList.push_back("player");
|
sprite_list_.push_back("player");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga todos los sprites desde una lista
|
// Carga todos los sprites desde una lista
|
||||||
void Ending2::loadSprites()
|
void Ending2::loadSprites()
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
maxSpriteWidth = 0;
|
sprite_max_width_ = 0;
|
||||||
maxSpriteHeight = 0;
|
sprite_max_height_ = 0;
|
||||||
|
|
||||||
// Carga los sprites
|
// Carga los sprites
|
||||||
for (auto sl : spriteList)
|
for (auto sl : sprite_list_)
|
||||||
{
|
{
|
||||||
sprites.emplace_back(std::make_shared<AnimatedSprite>(resource->getTexture(sl + ".png"), resource->getAnimation(sl + ".ani")));
|
sprites_.emplace_back(std::make_shared<AnimatedSprite>(resource_->getTexture(sl + ".png"), resource_->getAnimation(sl + ".ani")));
|
||||||
maxSpriteWidth = std::max(sprites.back()->getWidth(), maxSpriteWidth);
|
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
|
||||||
maxSpriteHeight = std::max(sprites.back()->getHeight(), maxSpriteHeight);
|
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los sprites
|
// Actualiza los sprites
|
||||||
void Ending2::updateSprites()
|
void Ending2::updateSprites()
|
||||||
{
|
{
|
||||||
for (auto sprite : sprites)
|
for (auto sprite : sprites_)
|
||||||
{
|
{
|
||||||
sprite->update();
|
sprite->update();
|
||||||
}
|
}
|
||||||
@@ -339,7 +336,7 @@ void Ending2::updateSprites()
|
|||||||
// Actualiza los sprites de texto
|
// Actualiza los sprites de texto
|
||||||
void Ending2::updateTextSprites()
|
void Ending2::updateTextSprites()
|
||||||
{
|
{
|
||||||
for (auto sprite : spriteTexts)
|
for (auto sprite : sprite_texts_)
|
||||||
{
|
{
|
||||||
sprite->update();
|
sprite->update();
|
||||||
}
|
}
|
||||||
@@ -348,16 +345,16 @@ void Ending2::updateTextSprites()
|
|||||||
// Actualiza los sprites de texto del final
|
// Actualiza los sprites de texto del final
|
||||||
void Ending2::updateTexts()
|
void Ending2::updateTexts()
|
||||||
{
|
{
|
||||||
if (texts.back()->getPosY() > GAMECANVAS_CENTER_Y)
|
if (texts_.back()->getPosY() > GAMECANVAS_CENTER_Y)
|
||||||
{
|
{
|
||||||
for (auto sprite : texts)
|
for (auto sprite : texts_)
|
||||||
{
|
{
|
||||||
sprite->update();
|
sprite->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
postCounterEnabled = true;
|
post_counter_enabled_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,7 +362,7 @@ void Ending2::updateTexts()
|
|||||||
void Ending2::renderSprites()
|
void Ending2::renderSprites()
|
||||||
{
|
{
|
||||||
const Color color = stringToColor(options.video.palette, "red");
|
const Color color = stringToColor(options.video.palette, "red");
|
||||||
for (auto sprite : sprites)
|
for (auto sprite : sprites_)
|
||||||
{
|
{
|
||||||
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
|
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
|
||||||
@@ -378,15 +375,15 @@ void Ending2::renderSprites()
|
|||||||
|
|
||||||
// Pinta el ultimo elemento de otro color
|
// Pinta el ultimo elemento de otro color
|
||||||
const Color c = stringToColor(options.video.palette, "white");
|
const Color c = stringToColor(options.video.palette, "white");
|
||||||
sprites.back()->getTexture()->setColor(c.r, c.g, c.b);
|
sprites_.back()->getTexture()->setColor(c.r, c.g, c.b);
|
||||||
sprites.back()->render();
|
sprites_.back()->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja los sprites con el texto
|
// Dibuja los sprites con el texto
|
||||||
void Ending2::renderSpriteTexts()
|
void Ending2::renderSpriteTexts()
|
||||||
{
|
{
|
||||||
const Color color = stringToColor(options.video.palette, "white");
|
const Color color = stringToColor(options.video.palette, "white");
|
||||||
for (auto sprite : spriteTexts)
|
for (auto sprite : sprite_texts_)
|
||||||
{
|
{
|
||||||
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
|
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
|
||||||
@@ -401,7 +398,7 @@ void Ending2::renderSpriteTexts()
|
|||||||
// Dibuja los sprites con el texto del final
|
// Dibuja los sprites con el texto del final
|
||||||
void Ending2::renderTexts()
|
void Ending2::renderTexts()
|
||||||
{
|
{
|
||||||
for (auto sprite : texts)
|
for (auto sprite : texts_)
|
||||||
{
|
{
|
||||||
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
|
const bool b = sprite->getRect().y < GAMECANVAS_HEIGHT;
|
||||||
@@ -415,58 +412,58 @@ void Ending2::renderTexts()
|
|||||||
// Coloca los sprites en su sito
|
// Coloca los sprites en su sito
|
||||||
void Ending2::placeSprites()
|
void Ending2::placeSprites()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)sprites.size(); ++i)
|
for (int i = 0; i < (int)sprites_.size(); ++i)
|
||||||
{
|
{
|
||||||
const int x = i % 2 == 0 ? firstCol : secondCol;
|
const int x = i % 2 == 0 ? FIRST_COL_ : SECOND_COL_;
|
||||||
const int y = (i / 1) * (maxSpriteHeight + distSpriteText + text->getCharacterSize() + distSpriteSprite) + GAMECANVAS_HEIGHT + 40;
|
const int y = (i / 1) * (sprite_max_height_ + dist_sprite_text_ + text_->getCharacterSize() + dist_sprite_sprite_) + GAMECANVAS_HEIGHT + 40;
|
||||||
const int w = sprites[i]->getWidth();
|
const int w = sprites_[i]->getWidth();
|
||||||
const int h = sprites[i]->getHeight();
|
const int h = sprites_[i]->getHeight();
|
||||||
const int dx = -(w / 2);
|
const int dx = -(w / 2);
|
||||||
const int dy = i % 1 == 0 ? maxSpriteHeight - h : (int)(maxSpriteHeight * 1.5f) - h;
|
const int dy = i % 1 == 0 ? sprite_max_height_ - h : (int)(sprite_max_height_ * 1.5f) - h;
|
||||||
|
|
||||||
sprites[i]->setPosition({x + dx, y + dy, w, h});
|
sprites_[i]->setPosition({x + dx, y + dy, w, h});
|
||||||
sprites[i]->setVelY(despSpeed);
|
sprites_[i]->setVelY(sprite_desp_speed_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recoloca el último sprite, que es el del jugador
|
// Recoloca el último sprite, que es el del jugador
|
||||||
const int w = sprites.back()->getWidth();
|
const int w = sprites_.back()->getWidth();
|
||||||
const int x = GAMECANVAS_CENTER_X - (w / 2);
|
const int x = GAMECANVAS_CENTER_X - (w / 2);
|
||||||
const int y = sprites.back()->getPosY() + maxSpriteHeight * 2;
|
const int y = sprites_.back()->getPosY() + sprite_max_height_ * 2;
|
||||||
sprites.back()->setPosX(x);
|
sprites_.back()->setPosX(x);
|
||||||
sprites.back()->setPosY(y);
|
sprites_.back()->setPosY(y);
|
||||||
sprites.back()->setCurrentAnimation("walk");
|
sprites_.back()->setCurrentAnimation("walk");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los sprites con las texturas con los textos
|
// Crea los sprites con las texturas con los textos
|
||||||
void Ending2::createSpriteTexts()
|
void Ending2::createSpriteTexts()
|
||||||
{
|
{
|
||||||
// Crea los sprites de texto a partir de la lista
|
// Crea los sprites de texto a partir de la lista
|
||||||
for (int i = 0; i < (int)spriteList.size(); ++i)
|
for (int i = 0; i < (int)sprite_list_.size(); ++i)
|
||||||
{
|
{
|
||||||
// Calcula constantes
|
// Calcula constantes
|
||||||
std::string txt = spriteList[i];
|
std::string txt = sprite_list_[i];
|
||||||
std::replace(txt.begin(), txt.end(), '_', ' ');
|
std::replace(txt.begin(), txt.end(), '_', ' ');
|
||||||
txt = txt == "player" ? "JAILDOCTOR" : txt; // Reemplaza el texto
|
txt = txt == "player" ? "JAILDOCTOR" : txt; // Reemplaza el texto
|
||||||
const int w = text->lenght(txt, 1);
|
const int w = text_->lenght(txt, 1);
|
||||||
const int h = text->getCharacterSize();
|
const int h = text_->getCharacterSize();
|
||||||
const int x = i % 2 == 0 ? firstCol : secondCol;
|
const int x = i % 2 == 0 ? FIRST_COL_ : SECOND_COL_;
|
||||||
const int dx = -(w / 2);
|
const int dx = -(w / 2);
|
||||||
const int y = sprites[i]->getPosY() + sprites[i]->getHeight() + distSpriteText;
|
const int y = sprites_[i]->getPosY() + sprites_[i]->getHeight() + dist_sprite_text_;
|
||||||
|
|
||||||
// Cambia la posición del último sprite
|
// Cambia la posición del último sprite
|
||||||
const int X = (i == (int)spriteList.size() - 1) ? GAMECANVAS_CENTER_X - (w / 2) : x + dx;
|
const int X = (i == (int)sprite_list_.size() - 1) ? GAMECANVAS_CENTER_X - (w / 2) : x + dx;
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la textura
|
||||||
auto texture = std::make_shared<Texture>(renderer);
|
auto texture = std::make_shared<Texture>(renderer_);
|
||||||
texture->createBlank(w, h);
|
texture->createBlank(w, h);
|
||||||
texture->setAsRenderTarget(renderer);
|
texture->setAsRenderTarget(renderer_);
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
text->write(0, 0, txt);
|
text_->write(0, 0, txt);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
SDL_Rect pos = {X, y, w, h};
|
SDL_Rect pos = {X, y, w, h};
|
||||||
spriteTexts.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
sprite_texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
||||||
spriteTexts.back()->setVelY(despSpeed);
|
sprite_texts_.back()->setVelY(sprite_desp_speed_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,28 +478,28 @@ void Ending2::createTexts()
|
|||||||
for (int i = 0; i < (int)list.size(); ++i)
|
for (int i = 0; i < (int)list.size(); ++i)
|
||||||
{
|
{
|
||||||
// Calcula constantes
|
// Calcula constantes
|
||||||
const int w = text->lenght(list[i], 1);
|
const int w = text_->lenght(list[i], 1);
|
||||||
const int h = text->getCharacterSize();
|
const int h = text_->getCharacterSize();
|
||||||
const int x = GAMECANVAS_CENTER_X;
|
const int x = GAMECANVAS_CENTER_X;
|
||||||
const int dx = -(w / 2);
|
const int dx = -(w / 2);
|
||||||
const int y = GAMECANVAS_HEIGHT + (text->getCharacterSize() * (i * 2));
|
const int y = GAMECANVAS_HEIGHT + (text_->getCharacterSize() * (i * 2));
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la textura
|
||||||
auto texture = std::make_shared<Texture>(renderer);
|
auto texture = std::make_shared<Texture>(renderer_);
|
||||||
texture->createBlank(w, h);
|
texture->createBlank(w, h);
|
||||||
texture->setAsRenderTarget(renderer);
|
texture->setAsRenderTarget(renderer_);
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
text->write(0, 0, list[i]);
|
text_->write(0, 0, list[i]);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
SDL_Rect pos = {x + dx, y, w, h};
|
SDL_Rect pos = {x + dx, y, w, h};
|
||||||
texts.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
||||||
texts.back()->setVelY(despSpeed);
|
texts_.back()->setVelY(sprite_desp_speed_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los últimos textos
|
// Crea los últimos textos
|
||||||
// El primer texto va a continuación del ultimo spriteText
|
// El primer texto va a continuación del ultimo spriteText
|
||||||
const int start = spriteTexts.back()->getPosY() + text->getCharacterSize() * 15;
|
const int start = sprite_texts_.back()->getPosY() + text_->getCharacterSize() * 15;
|
||||||
list.clear();
|
list.clear();
|
||||||
list.push_back("THANK YOU");
|
list.push_back("THANK YOU");
|
||||||
list.push_back("FOR PLAYING!");
|
list.push_back("FOR PLAYING!");
|
||||||
@@ -511,23 +508,23 @@ void Ending2::createTexts()
|
|||||||
for (int i = 0; i < (int)list.size(); ++i)
|
for (int i = 0; i < (int)list.size(); ++i)
|
||||||
{
|
{
|
||||||
// Calcula constantes
|
// Calcula constantes
|
||||||
const int w = text->lenght(list[i], 1);
|
const int w = text_->lenght(list[i], 1);
|
||||||
const int h = text->getCharacterSize();
|
const int h = text_->getCharacterSize();
|
||||||
const int x = GAMECANVAS_CENTER_X;
|
const int x = GAMECANVAS_CENTER_X;
|
||||||
const int dx = -(w / 2);
|
const int dx = -(w / 2);
|
||||||
const int y = start + (text->getCharacterSize() * (i * 2));
|
const int y = start + (text_->getCharacterSize() * (i * 2));
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la textura
|
||||||
auto texture = std::make_shared<Texture>(renderer);
|
auto texture = std::make_shared<Texture>(renderer_);
|
||||||
texture->createBlank(w, h);
|
texture->createBlank(w, h);
|
||||||
texture->setAsRenderTarget(renderer);
|
texture->setAsRenderTarget(renderer_);
|
||||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
text->write(0, 0, list[i]);
|
text_->write(0, 0, list[i]);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
SDL_Rect pos = {x + dx, y, w, h};
|
SDL_Rect pos = {x + dx, y, w, h};
|
||||||
texts.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
texts_.emplace_back(std::make_shared<MovingSprite>(texture, pos));
|
||||||
texts.back()->setVelY(despSpeed);
|
texts_.back()->setVelY(sprite_desp_speed_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,21 +532,21 @@ void Ending2::createTexts()
|
|||||||
void Ending2::updateFinalFade()
|
void Ending2::updateFinalFade()
|
||||||
{
|
{
|
||||||
// La variable step va de 0 a 40 en el tramo de postCounter que va de 500 a 540. Al dividirlo por 40, va de 0.0f a 1.0f
|
// La variable step va de 0 a 40 en el tramo de postCounter que va de 500 a 540. Al dividirlo por 40, va de 0.0f a 1.0f
|
||||||
const float step = std::min(std::max(postCounter, 500) - 500, 40) / 40.0f;
|
const float step = std::min(std::max(post_counter_, 500) - 500, 40) / 40.0f;
|
||||||
const int index = (colors.size() - 1) * step;
|
const int index = (colors_.size() - 1) * step;
|
||||||
|
|
||||||
for (auto t : texts)
|
for (auto t : texts_)
|
||||||
{
|
{
|
||||||
t->getTexture()->setColor(colors[index].r, colors[index].g, colors[index].b);
|
t->getTexture()->setColor(colors_[index].r, colors_[index].g, colors_[index].b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
void Ending2::updateMusicVolume()
|
void Ending2::updateMusicVolume()
|
||||||
{
|
{
|
||||||
if (postCounter > 0)
|
if (post_counter_ > 0)
|
||||||
{
|
{
|
||||||
const float step = (600.0f - postCounter) / 600.0f;
|
const float step = (600.0f - post_counter_) / 600.0f;
|
||||||
const int volume = 128 * step;
|
const int volume = 128 * step;
|
||||||
JA_SetVolume(volume);
|
JA_SetVolume(volume);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,53 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class AnimatedSprite; // lines 9-9
|
#include "defines.h" // for GAMECANVAS_FIRST_QUARTER_X, GAMECANVAS_THIRD_QUARTER_X, GAMECANVAS_WIDTH
|
||||||
class Asset; // lines 10-10
|
class AnimatedSprite; // lines 9-9
|
||||||
class Input; // lines 11-11
|
class Asset; // lines 10-10
|
||||||
class MovingSprite; // lines 12-12
|
class Input; // lines 11-11
|
||||||
class Resource; // lines 13-13
|
class MovingSprite; // lines 12-12
|
||||||
class Screen; // lines 14-14
|
class Resource; // lines 13-13
|
||||||
class Text; // lines 15-15
|
class Screen; // lines 14-14
|
||||||
struct JA_Music_t; // lines 16-16
|
class Text; // lines 15-15
|
||||||
|
struct JA_Music_t; // lines 16-16
|
||||||
|
|
||||||
class Ending2
|
class Ending2
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Constantes
|
||||||
|
static constexpr int FIRST_COL_ = GAMECANVAS_FIRST_QUARTER_X + (GAMECANVAS_WIDTH / 16); // Primera columna por donde desfilan los sprites
|
||||||
|
static constexpr int SECOND_COL_ = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); // Segunda columna por donde desfilan los sprites
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
std::shared_ptr<Text> text; // Objeto para escribir texto en pantalla
|
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
|
||||||
std::vector<std::shared_ptr<AnimatedSprite>> sprites; // Vector con todos los sprites a dibujar
|
std::vector<std::shared_ptr<AnimatedSprite>> sprites_; // Vector con todos los sprites a dibujar
|
||||||
std::vector<std::shared_ptr<MovingSprite>> spriteTexts; // Vector con los sprites de texto de los sprites
|
std::vector<std::shared_ptr<MovingSprite>> sprite_texts_; // Vector con los sprites de texto de los sprites
|
||||||
std::vector<std::shared_ptr<MovingSprite>> texts; // Vector con los sprites de texto
|
std::vector<std::shared_ptr<MovingSprite>> texts_; // Vector con los sprites de texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
bool counterEnabled; // Indica si está el contador habilitado
|
bool counter_enabled_; // Indica si está el contador habilitado
|
||||||
int preCounter; // Contador previo
|
int pre_counter_; // Contador previo
|
||||||
int postCounter; // Contador posterior
|
int post_counter_; // Contador posterior
|
||||||
bool postCounterEnabled; // Indica si está habilitado el contador
|
bool post_counter_enabled_; // Indica si está habilitado el contador
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
JA_Music_t *music_; // Musica que suena durante el final
|
||||||
JA_Music_t *music; // Musica que suena durante el final
|
std::vector<std::string> sprite_list_; // Lista con todos los sprites a dibujar
|
||||||
std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar
|
std::vector<Color> colors_; // Vector con los colores para el fade
|
||||||
std::vector<Color> colors; // Vector con los colores para el fade
|
int sprite_max_width_; // El valor de ancho del sprite mas ancho
|
||||||
int maxSpriteWidth; // El valor de ancho del sprite mas ancho
|
int sprite_max_height_; // El valor de alto del sprite mas alto
|
||||||
int maxSpriteHeight; // El valor de alto del sprite mas alto
|
int dist_sprite_text_; // Distancia entre el sprite y el texto que lo acompaña
|
||||||
int distSpriteText; // Distancia entre el sprite y el texto que lo acompaña
|
int dist_sprite_sprite_; // Distancia entre dos sprites de la misma columna
|
||||||
int distSpriteSprite; // Distancia entre dos sprites de la misma columna
|
float sprite_desp_speed_; // Velocidad de desplazamiento de los sprites
|
||||||
float despSpeed; // Velocidad de desplazamiento de los sprites
|
|
||||||
int firstCol; // Primera columna por donde desfilan los sprites
|
|
||||||
int secondCol; // Segunda columna por donde desfilan los sprites
|
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ Game::Game()
|
|||||||
current_room_ = "03.room";
|
current_room_ = "03.room";
|
||||||
const int x = 25;
|
const int x = 25;
|
||||||
const int y = 13;
|
const int y = 13;
|
||||||
spawn_point_ = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
spawn_point_ = PlayerSpawn(x * 8, y * 8, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
|
||||||
debug_->setEnabled(false);
|
debug_->setEnabled(false);
|
||||||
#else
|
#else
|
||||||
current_room_ = "03.room";
|
current_room_ = "03.room";
|
||||||
const int x = 25;
|
const int x = 25;
|
||||||
const int y = 13;
|
const int y = 13;
|
||||||
spawn_point_ = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
spawn_point_ = PlayerSpawn(x * 8, y * 8, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
@@ -57,7 +57,7 @@ Game::Game()
|
|||||||
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, false);
|
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, false);
|
||||||
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||||
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||||
const player_t player = {spawn_point_, playerPNG, playerANI, room_};
|
const PlayerData player(spawn_point_, playerPNG, playerANI, room_);
|
||||||
player_ = std::make_shared<Player>(player);
|
player_ = std::make_shared<Player>(player);
|
||||||
text_ = resource_->getText("smb2");
|
text_ = resource_->getText("smb2");
|
||||||
music_ = resource_->getMusic("game.ogg");
|
music_ = resource_->getMusic("game.ogg");
|
||||||
@@ -85,7 +85,6 @@ Game::Game()
|
|||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
ticks_ = 0;
|
ticks_ = 0;
|
||||||
ticks_speed_ = 15;
|
|
||||||
board_.lives = 9;
|
board_.lives = 9;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
board_.lives = 9;
|
board_.lives = 9;
|
||||||
@@ -217,7 +216,7 @@ void Game::run()
|
|||||||
void Game::update()
|
void Game::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
@@ -283,7 +282,7 @@ void Game::updateDebugInfo()
|
|||||||
{
|
{
|
||||||
debug_->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
|
debug_->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
|
||||||
debug_->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4));
|
debug_->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4));
|
||||||
debug_->add("STATE = " + std::to_string(player_->state_));
|
debug_->add("STATE = " + std::to_string(static_cast<int>(player_->state_)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone la información de debug en pantalla
|
// Pone la información de debug en pantalla
|
||||||
@@ -443,7 +442,7 @@ void Game::killPlayer()
|
|||||||
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, board_.jail_is_open);
|
room_ = std::make_shared<Room>(resource_->getRoom(current_room_), &board_.items, board_.jail_is_open);
|
||||||
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||||
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||||
const player_t player = {spawn_point_, playerPNG, playerANI, room_};
|
const PlayerData player(spawn_point_, playerPNG, playerANI, room_);
|
||||||
player_ = std::make_shared<Player>(player);
|
player_ = std::make_shared<Player>(player);
|
||||||
|
|
||||||
// Pone los objetos en pausa mientras esta la habitación en negro
|
// Pone los objetos en pausa mientras esta la habitación en negro
|
||||||
|
|||||||
@@ -44,18 +44,17 @@ private:
|
|||||||
SDL_Texture *room_name_texture_; // Textura para escribir el nombre de la habitación
|
SDL_Texture *room_name_texture_; // Textura para escribir el nombre de la habitación
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
JA_Music_t *music_; // Musica que suena durante el juego
|
JA_Music_t *music_; // Musica que suena durante el juego
|
||||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
std::string current_room_; // Fichero de la habitación actual
|
||||||
std::string current_room_; // Fichero de la habitación actual
|
PlayerSpawn spawn_point_; // Lugar de la habitación donde aparece el jugador
|
||||||
playerSpawn_t spawn_point_; // Lugar de la habitación donde aparece el jugador
|
JA_Sound_t *death_sound_; // Sonido a reproducir cuando muere el jugador
|
||||||
JA_Sound_t *death_sound_; // Sonido a reproducir cuando muere el jugador
|
ScoreboardData board_; // Estructura con los datos del marcador
|
||||||
ScoreboardData board_; // Estructura con los datos del marcador
|
bool paused_; // Indica si el juego se encuentra en pausa
|
||||||
bool paused_; // Indica si el juego se encuentra en pausa
|
bool black_screen_; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
||||||
bool black_screen_; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
int black_screen_counter_; // Contador para temporizar la pantalla en negro
|
||||||
int black_screen_counter_; // Contador para temporizar la pantalla en negro
|
int total_items_; // Cantidad total de items que hay en el mapeado del juego
|
||||||
int total_items_; // Cantidad total de items que hay en el mapeado del juego
|
SDL_Rect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
|
||||||
SDL_Rect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
|
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -1,67 +1,63 @@
|
|||||||
#include "game_over.h"
|
#include "game_over.h"
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <algorithm> // for min, max
|
#include <algorithm> // for min, max
|
||||||
#include <string> // for basic_string, operator+, to_string, cha...
|
#include <string> // for basic_string, operator+, to_string, cha...
|
||||||
#include "animated_sprite.h" // for AnimatedSprite
|
#include "animated_sprite.h" // for AnimatedSprite
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "defines.h" // for GAMECANVAS_CENTER_X
|
#include "defines.h" // for GAMECANVAS_CENTER_X
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "input.h" // for Input
|
#include "input.h" // for Input
|
||||||
#include "jail_audio.h" // for JA_PlayMusic
|
#include "jail_audio.h" // for JA_PlayMusic
|
||||||
#include "options.h" // for Options, options, OptionsStats, Section...
|
#include "options.h" // for Options, options, OptionsStats, Section...
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver()
|
GameOver::GameOver()
|
||||||
: screen(Screen::get()),
|
: screen_(Screen::get()),
|
||||||
renderer(Screen::get()->getRenderer()),
|
renderer_(Screen::get()->getRenderer()),
|
||||||
resource(Resource::get()),
|
resource_(Resource::get()),
|
||||||
asset(Asset::get()),
|
asset_(Asset::get()),
|
||||||
input(Input::get())
|
input_(Input::get())
|
||||||
{
|
{
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
text = resource->getText("smb2");
|
text_ = resource_->getText("smb2");
|
||||||
playerSprite = std::make_shared<AnimatedSprite>(resource->getTexture("player_game_over.png"), resource->getAnimation("player_game_over.ani"));
|
player_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("player_game_over.png"), resource_->getAnimation("player_game_over.ani"));
|
||||||
tvSprite = std::make_shared<AnimatedSprite>(resource->getTexture("tv.png"), resource->getAnimation("tv.ani"));
|
tv_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("tv.png"), resource_->getAnimation("tv.ani"));
|
||||||
music = resource->getMusic("game_over.ogg");
|
music_ = resource_->getMusic("game_over.ogg");
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
preCounter = 0;
|
pre_counter_ = 0;
|
||||||
counter = 0;
|
counter_ = 0;
|
||||||
options.section.section = Section::GAME_OVER;
|
options.section.section = Section::GAME_OVER;
|
||||||
options.section.subsection = Subsection::NONE;
|
options.section.subsection = Subsection::NONE;
|
||||||
ticks = 0;
|
ticks_ = 0;
|
||||||
ticksSpeed = 15;
|
player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10);
|
||||||
endSection = 400;
|
player_sprite_->setPosY(30);
|
||||||
iniFade = 310;
|
tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - 10);
|
||||||
fadeLenght = 20;
|
tv_sprite_->setPosY(30);
|
||||||
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
|
|
||||||
playerSprite->setPosY(30);
|
|
||||||
tvSprite->setPosX(GAMECANVAS_CENTER_X - tvSprite->getWidth() - 10);
|
|
||||||
tvSprite->setPosY(30);
|
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
for (auto cl : colorList)
|
for (auto cl : colorList)
|
||||||
{
|
{
|
||||||
colors.push_back(stringToColor(options.video.palette, cl));
|
colors_.push_back(stringToColor(options.video.palette, cl));
|
||||||
}
|
}
|
||||||
color = colors.back();
|
color_ = colors_.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
void GameOver::update()
|
void GameOver::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
checkInput();
|
checkInput();
|
||||||
@@ -73,44 +69,41 @@ void GameOver::update()
|
|||||||
updateCounters();
|
updateCounters();
|
||||||
|
|
||||||
// Actualiza los dos sprites
|
// Actualiza los dos sprites
|
||||||
playerSprite->update();
|
player_sprite_->update();
|
||||||
tvSprite->update();
|
tv_sprite_->update();
|
||||||
|
|
||||||
screen->update();
|
screen_->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el final en pantalla
|
// Dibuja el final en pantalla
|
||||||
void GameOver::render()
|
void GameOver::render()
|
||||||
{
|
{
|
||||||
const int y = 32;
|
constexpr int Y = 32;
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
screen_->start();
|
||||||
screen->start();
|
screen_->clean();
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean();
|
|
||||||
|
|
||||||
// Escribe el texto de GAME OVER
|
// Escribe el texto de GAME OVER
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, y, "G A M E O V E R", 1, color);
|
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y, "G A M E O V E R", 1, color_);
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
playerSprite->setPosY(y + 30);
|
player_sprite_->setPosY(Y + 30);
|
||||||
tvSprite->setPosY(y + 30);
|
tv_sprite_->setPosY(Y + 30);
|
||||||
renderSprites();
|
renderSprites();
|
||||||
|
|
||||||
// Escribe el texto con las habitaciones y los items
|
// Escribe el texto con las habitaciones y los items
|
||||||
const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10);
|
const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10);
|
||||||
const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10);
|
const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
|
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 80, "ITEMS: " + itemsTxt, 1, color_);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
|
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 90, "ROOMS: " + roomsTxt, 1, color_);
|
||||||
|
|
||||||
// Escribe el texto con "Tu peor pesadilla"
|
// Escribe el texto con "Tu peor pesadilla"
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
|
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 110, "YOUR WORST NIGHTMARE IS", 1, color_);
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options.stats.worst_nightmare, 1, color);
|
text_->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, Y + 120, options.stats.worst_nightmare, 1, color_);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->render();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
@@ -143,53 +136,53 @@ void GameOver::run()
|
|||||||
// Actualiza el color usado para renderizar los textos e imagenes
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
void GameOver::updateColor()
|
void GameOver::updateColor()
|
||||||
{
|
{
|
||||||
const int half = endSection / 2;
|
const int half = COUNTER_SECTION_END_ / 2;
|
||||||
|
|
||||||
if (counter < half)
|
if (counter_ < half)
|
||||||
{
|
{
|
||||||
const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
|
const float step = std::min(counter_, COUNTER_FADE_LENGHT_) / (float)COUNTER_FADE_LENGHT_;
|
||||||
const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
|
const int index = (colors_.size() - 1) - int((colors_.size() - 1) * step);
|
||||||
color = colors[index];
|
color_ = colors_[index];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
|
const float step = std::min(std::max(counter_, COUNTER_INIT_FADE_) - COUNTER_INIT_FADE_, COUNTER_FADE_LENGHT_) / (float)COUNTER_FADE_LENGHT_;
|
||||||
const int index = (colors.size() - 1) * step;
|
const int index = (colors_.size() - 1) * step;
|
||||||
color = colors[index];
|
color_ = colors_[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
void GameOver::renderSprites()
|
void GameOver::renderSprites()
|
||||||
{
|
{
|
||||||
playerSprite->getTexture()->setColor(color.r, color.g, color.b);
|
player_sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
||||||
playerSprite->render();
|
player_sprite_->render();
|
||||||
|
|
||||||
tvSprite->getTexture()->setColor(color.r, color.g, color.b);
|
tv_sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
||||||
tvSprite->render();
|
tv_sprite_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los contadores
|
// Actualiza los contadores
|
||||||
void GameOver::updateCounters()
|
void GameOver::updateCounters()
|
||||||
{
|
{
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
if (preCounter < 50)
|
if (pre_counter_ < 50)
|
||||||
{
|
{
|
||||||
preCounter++;
|
pre_counter_++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
counter++;
|
counter_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hace sonar la música
|
// Hace sonar la música
|
||||||
if (counter == 1)
|
if (counter_ == 1)
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music, 0);
|
JA_PlayMusic(music_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado la sección
|
// Comprueba si ha terminado la sección
|
||||||
else if (counter == endSection)
|
else if (counter_ == COUNTER_SECTION_END_)
|
||||||
{
|
{
|
||||||
options.section.section = Section::LOGO;
|
options.section.section = Section::LOGO;
|
||||||
options.section.subsection = Subsection::LOGO_TO_TITLE;
|
options.section.subsection = Subsection::LOGO_TO_TITLE;
|
||||||
|
|||||||
@@ -1,42 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class AnimatedSprite; // lines 9-9
|
class AnimatedSprite; // lines 9-9
|
||||||
class Asset; // lines 10-10
|
class Asset; // lines 10-10
|
||||||
class Input; // lines 11-11
|
class Input; // lines 11-11
|
||||||
class Resource; // lines 12-12
|
class Resource; // lines 12-12
|
||||||
class Screen; // lines 13-13
|
class Screen; // lines 13-13
|
||||||
class Text; // lines 14-14
|
class Text; // lines 14-14
|
||||||
struct JA_Music_t; // lines 15-15
|
struct JA_Music_t; // lines 15-15
|
||||||
|
|
||||||
class GameOver
|
class GameOver
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Constantes
|
||||||
|
static constexpr int COUNTER_SECTION_END_ = 400; // Contador: cuando acaba la sección
|
||||||
|
static constexpr int COUNTER_INIT_FADE_ = 310; // Contador: cuando emiepza el fade
|
||||||
|
static constexpr int COUNTER_FADE_LENGHT_ = 20; // Contador: duración del fade
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
std::shared_ptr<Text> text; // Objeto para escribir texto en pantalla
|
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
|
||||||
std::shared_ptr<AnimatedSprite> playerSprite; // Sprite con el jugador
|
std::shared_ptr<AnimatedSprite> player_sprite_; // Sprite con el jugador
|
||||||
std::shared_ptr<AnimatedSprite> tvSprite; // Sprite con el televisor
|
std::shared_ptr<AnimatedSprite> tv_sprite_; // Sprite con el televisor
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int preCounter; // Contador previo
|
int pre_counter_ = 0; // Contador previo
|
||||||
int counter; // Contador
|
int counter_ = 0; // Contador
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
std::vector<Color> colors_; // Vector con los colores para el fade
|
||||||
std::vector<Color> colors; // Vector con los colores para el fade
|
Color color_; // Color usado para el texto y los sprites
|
||||||
Color color; // Color usado para el texto y los sprites
|
JA_Music_t *music_; // Musica que suena durante el juego
|
||||||
int endSection; // Contador: cuando acaba la sección
|
|
||||||
int iniFade; // Contador: cuando emiepza el fade
|
|
||||||
int fadeLenght; // Contador: duración del fade
|
|
||||||
JA_Music_t *music; // Musica que suena durante el juego
|
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ private:
|
|||||||
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
||||||
int num_gamepads_; // Numero de mandos conectados
|
int num_gamepads_; // Numero de mandos conectados
|
||||||
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt
|
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||||
bool verbose_ = true; // Indica si ha de mostrar mensajes
|
bool verbose_ = true; // Indica si ha de mostrar mensajes
|
||||||
i_disable_e disabled_until_; // Tiempo que esta deshabilitado
|
i_disable_e disabled_until_; // Tiempo que esta deshabilitado
|
||||||
bool enabled_ = true; // Indica si está habilitado
|
bool enabled_ = true; // Indica si está habilitado
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Input(const std::string &game_controller_db_path);
|
explicit Input(const std::string &game_controller_db_path);
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ void ItemTracker::addItem(const std::string &name, SDL_Point pos)
|
|||||||
// Primero busca si ya hay una entrada con ese nombre
|
// Primero busca si ya hay una entrada con ese nombre
|
||||||
if (const int index = findByName(name); index != -1)
|
if (const int index = findByName(name); index != -1)
|
||||||
{
|
{
|
||||||
list.at(index).pos.push_back(pos);
|
item_list_.at(index).pos.push_back(pos);
|
||||||
}
|
}
|
||||||
// En caso contrario crea la entrada
|
// En caso contrario crea la entrada
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list.emplace_back(name, pos);
|
item_list_.emplace_back(name, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ int ItemTracker::findByName(std::string name)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (const auto &l : list)
|
for (const auto &l : item_list_)
|
||||||
{
|
{
|
||||||
if (l.name == name)
|
if (l.name == name)
|
||||||
{
|
{
|
||||||
@@ -78,7 +78,7 @@ int ItemTracker::findByPos(int index, SDL_Point pos)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (const auto &l : list[index].pos)
|
for (const auto &l : item_list_[index].pos)
|
||||||
{
|
{
|
||||||
if ((l.x == pos.x) && (l.y == pos.y))
|
if ((l.x == pos.x) && (l.y == pos.y))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ struct ItemTrackerData
|
|||||||
std::vector<SDL_Point> pos; // Lista de objetos cogidos de la habitación
|
std::vector<SDL_Point> pos; // Lista de objetos cogidos de la habitación
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ItemTrackerData(const std::string& name, const SDL_Point& position)
|
ItemTrackerData(const std::string &name, const SDL_Point &position)
|
||||||
: name(name)
|
: name(name)
|
||||||
{
|
{
|
||||||
pos.push_back(position);
|
pos.push_back(position);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemTracker
|
class ItemTracker
|
||||||
@@ -24,7 +24,7 @@ private:
|
|||||||
static ItemTracker *item_tracker_;
|
static ItemTracker *item_tracker_;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<ItemTrackerData> list; // Lista con todos los objetos recogidos
|
std::vector<ItemTrackerData> item_list_; // Lista con todos los objetos recogidos
|
||||||
|
|
||||||
// Busca una entrada en la lista por nombre
|
// Busca una entrada en la lista por nombre
|
||||||
int findByName(std::string name);
|
int findByName(std::string name);
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ void LoadingScreen::renderBorder()
|
|||||||
void LoadingScreen::update()
|
void LoadingScreen::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ private:
|
|||||||
int pre_counter_ = 0; // Contador previo para realizar una pausa inicial
|
int pre_counter_ = 0; // Contador previo para realizar una pausa inicial
|
||||||
int counter_ = 0; // Contador
|
int counter_ = 0; // Contador
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
int load_counter_ = 0; // Contador para controlar las cargas
|
int load_counter_ = 0; // Contador para controlar las cargas
|
||||||
bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra
|
bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra
|
||||||
JA_Music_t *loading_sound1_; // Sonidos para imitar la carga tipo spectrum
|
JA_Music_t *loading_sound1_; // Sonidos para imitar la carga tipo spectrum
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
#include <string> // for basic_string, string
|
#include <string> // for basic_string, string
|
||||||
#include "asset.h" // for Asset
|
#include "asset.h" // for Asset
|
||||||
#include "global_events.h" // for check
|
#include "global_events.h" // for check
|
||||||
#include "global_inputs.h" // for check
|
#include "global_inputs.h" // for check
|
||||||
#include "input.h" // for Input
|
#include "input.h" // for Input
|
||||||
#include "jail_audio.h" // for JA_StopMusic
|
#include "jail_audio.h" // for JA_StopMusic
|
||||||
#include "options.h" // for Options, options, SectionState, Section
|
#include "options.h" // for Options, options, SectionState, Section
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // for Resource
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // for Screen
|
||||||
#include "sprite.h" // for Sprite
|
#include "sprite.h" // for Sprite
|
||||||
#include "texture.h" // for Texture
|
#include "texture.h" // for Texture
|
||||||
#include "utils.h" // for Color, stringToColor
|
#include "utils.h" // for Color, stringToColor
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
@@ -153,43 +154,43 @@ void Logo::updateTextureColors()
|
|||||||
since_1998_texture_->setColor(color_[7].r, color_[7].g, color_[7].b);
|
since_1998_texture_->setColor(color_[7].r, color_[7].g, color_[7].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 0)
|
else if (counter_ == INIT_FADE_ + inc * 0)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
jailgames_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||||
since_1998_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
since_1998_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 1)
|
else if (counter_ == INIT_FADE_ + inc * 1)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
jailgames_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||||
since_1998_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
since_1998_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 2)
|
else if (counter_ == INIT_FADE_ + inc * 2)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
jailgames_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||||
since_1998_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
since_1998_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 3)
|
else if (counter_ == INIT_FADE_ + inc * 3)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
jailgames_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||||
since_1998_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
since_1998_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 4)
|
else if (counter_ == INIT_FADE_ + inc * 4)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
jailgames_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||||
since_1998_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
since_1998_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 5)
|
else if (counter_ == INIT_FADE_ + inc * 5)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
jailgames_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||||
since_1998_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
since_1998_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter_ == init_fade_ + inc * 6)
|
else if (counter_ == INIT_FADE_ + inc * 6)
|
||||||
{
|
{
|
||||||
jailgames_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
jailgames_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||||
since_1998_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
since_1998_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||||
@@ -200,7 +201,7 @@ void Logo::updateTextureColors()
|
|||||||
void Logo::update()
|
void Logo::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
@@ -220,7 +221,7 @@ void Logo::update()
|
|||||||
screen_->update();
|
screen_->update();
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
// Comprueba si ha terminado el logo
|
||||||
if (counter_ == end_logo_ + post_logo_)
|
if (counter_ == END_LOGO_ + POST_LOGO_)
|
||||||
{
|
{
|
||||||
endSection();
|
endSection();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
class Asset; // lines 8-8
|
class Asset; // lines 8-8
|
||||||
class Input; // lines 9-9
|
class Input; // lines 9-9
|
||||||
class Resource; // lines 10-10
|
class Resource; // lines 10-10
|
||||||
class Screen; // lines 11-11
|
class Screen; // lines 11-11
|
||||||
class Sprite; // lines 12-12
|
class Sprite; // lines 12-12
|
||||||
class Texture; // lines 13-13
|
class Texture; // lines 13-13
|
||||||
|
|
||||||
class Logo
|
class Logo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// Constantes
|
||||||
|
static constexpr int INIT_FADE_ = 300; // Tiempo del contador cuando inicia el fade a negro
|
||||||
|
static constexpr int END_LOGO_ = 400; // Tiempo del contador para terminar el logo
|
||||||
|
static constexpr int POST_LOGO_ = 20; // Tiempo que dura el logo con el fade al maximo
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
@@ -30,10 +35,6 @@ private:
|
|||||||
std::vector<Color> color_; // Vector con los colores para el fade
|
std::vector<Color> color_; // Vector con los colores para el fade
|
||||||
int counter_ = 0; // Contador
|
int counter_ = 0; // Contador
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
int init_fade_ = 300; // Tiempo del contador cuando inicia el fade a negro
|
|
||||||
int end_logo_ = 400; // Tiempo del contador para terminar el logo
|
|
||||||
int post_logo_ = 20; // Tiempo que dura el logo con el fade al maximo
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -16,106 +16,38 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(player_t player)
|
Player::Player(PlayerData player)
|
||||||
: renderer_(Screen::get()->getRenderer()),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
input_(Input::get()),
|
input_(Input::get()),
|
||||||
resource_(Resource::get()),
|
|
||||||
asset_(Asset::get()),
|
asset_(Asset::get()),
|
||||||
debug_(Debug::get()),
|
debug_(Debug::get()),
|
||||||
room_(player.room)
|
room_(player.room)
|
||||||
{
|
{
|
||||||
// Crea objetos
|
// Inicializa algunas variables
|
||||||
sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture(player.png), resource_->getAnimation(player.animation));
|
initSprite(player.texture, player.animation);
|
||||||
|
setColor();
|
||||||
|
applySpawnValues(player.spawn);
|
||||||
|
placeSprite();
|
||||||
|
initSounds();
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
reLoadPalette();
|
|
||||||
is_on_border_ = false;
|
|
||||||
border_ = BORDER_TOP;
|
|
||||||
auto_movement_ = false;
|
|
||||||
is_alive_ = true;
|
|
||||||
is_paused_ = false;
|
|
||||||
|
|
||||||
jump_init_pos_ = player.spawn.jump_init_pos;
|
|
||||||
state_ = player.spawn.state;
|
|
||||||
previous_state_ = state_;
|
previous_state_ = state_;
|
||||||
|
|
||||||
x_ = player.spawn.x;
|
|
||||||
y_ = player.spawn.y;
|
|
||||||
vx_ = player.spawn.vx;
|
|
||||||
vy_ = player.spawn.vy;
|
|
||||||
w_ = 8;
|
|
||||||
h_ = 16;
|
|
||||||
|
|
||||||
sprite_->setPosX(player.spawn.x);
|
|
||||||
sprite_->setPosY(player.spawn.y);
|
|
||||||
sprite_->setWidth(8);
|
|
||||||
sprite_->setHeight(16);
|
|
||||||
|
|
||||||
sprite_->setFlip(player.spawn.flip);
|
|
||||||
sprite_->setCurrentAnimation("walk");
|
|
||||||
sprite_->update();
|
|
||||||
|
|
||||||
last_position_ = getRect();
|
last_position_ = getRect();
|
||||||
collider_box_ = getRect();
|
collider_box_ = getRect();
|
||||||
const SDL_Point p = {0, 0};
|
collider_points_.resize(collider_points_.size() + 8, {0, 0});
|
||||||
collider_points_.insert(collider_points_.end(), {p, p, p, p, p, p, p, p});
|
under_feet_.resize(under_feet_.size() + 2, {0, 0});
|
||||||
under_feet_.insert(under_feet_.end(), {p, p});
|
feet_.resize(feet_.size() + 2, {0, 0});
|
||||||
feet_.insert(feet_.end(), {p, p});
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump1.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump2.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump3.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump4.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump5.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump6.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump7.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump8.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump9.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump10.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump11.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump12.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump13.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump14.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump15.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump16.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump17.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump18.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump19.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump20.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump21.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump22.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump23.wav").c_str()));
|
|
||||||
jumping_sound_.push_back(JA_LoadSound(asset_->get("jump24.wav").c_str()));
|
|
||||||
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump11.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump12.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump13.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump14.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump15.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump16.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump17.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump18.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump19.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump20.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump21.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump22.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump23.wav").c_str()));
|
|
||||||
falling_sound_.push_back(JA_LoadSound(asset_->get("jump24.wav").c_str()));
|
|
||||||
|
|
||||||
jumping_counter_ = 0;
|
|
||||||
falling_counter_ = 0;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
rx = {0, 0, 0, 0};
|
debug_rect_x_ = {0, 0, 0, 0};
|
||||||
ry = {0, 0, 0, 0};
|
debug_rect_y_ = {0, 0, 0, 0};
|
||||||
debugColor = {0, 255, 0};
|
debug_color_ = {0, 255, 0};
|
||||||
debugPoint = {0, 0};
|
debug_point_ = {0, 0};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el jugador en pantalla
|
// Pinta el jugador en pantalla
|
||||||
void Player::render()
|
void Player::render()
|
||||||
{
|
{
|
||||||
sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
|
||||||
sprite_->render();
|
sprite_->render();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -127,7 +59,7 @@ void Player::render()
|
|||||||
SDL_RenderDrawPoint(renderer_, under_feet_[1].x, under_feet_[1].y);
|
SDL_RenderDrawPoint(renderer_, under_feet_[1].x, under_feet_[1].y);
|
||||||
|
|
||||||
// Pinta rectangulo del jugador
|
// Pinta rectangulo del jugador
|
||||||
SDL_SetRenderDrawColor(renderer_, debugColor.r, debugColor.g, debugColor.b, 192);
|
SDL_SetRenderDrawColor(renderer_, debug_color_.r, debug_color_.g, debug_color_.b, 192);
|
||||||
SDL_Rect rect = getRect();
|
SDL_Rect rect = getRect();
|
||||||
SDL_RenderFillRect(renderer_, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 255);
|
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 255);
|
||||||
@@ -137,16 +69,16 @@ void Player::render()
|
|||||||
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255);
|
||||||
if (vx_ != 0.0f)
|
if (vx_ != 0.0f)
|
||||||
{
|
{
|
||||||
SDL_RenderFillRect(renderer_, &rx);
|
SDL_RenderFillRect(renderer_, &debug_rect_x_);
|
||||||
}
|
}
|
||||||
if (vy_ != 0.0f)
|
if (vy_ != 0.0f)
|
||||||
{
|
{
|
||||||
SDL_RenderFillRect(renderer_, &ry);
|
SDL_RenderFillRect(renderer_, &debug_rect_y_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el punto de debug
|
// Pinta el punto de debug
|
||||||
SDL_SetRenderDrawColor(renderer_, rand() % 256, rand() % 256, rand() % 256, 255);
|
SDL_SetRenderDrawColor(renderer_, rand() % 256, rand() % 256, rand() % 256, 255);
|
||||||
SDL_RenderDrawPoint(renderer_, debugPoint.x, debugPoint.y);
|
SDL_RenderDrawPoint(renderer_, debug_point_.x, debug_point_.y);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -154,30 +86,28 @@ void Player::render()
|
|||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Player::update()
|
void Player::update()
|
||||||
{
|
{
|
||||||
if (is_paused_)
|
if (!is_paused_)
|
||||||
{ // Si está en modo pausa no se actualiza nada
|
{
|
||||||
return;
|
checkInput(); // Comprueba las entradas y modifica variables
|
||||||
|
move(); // Recalcula la posición del jugador
|
||||||
|
animate(); // Establece la animación del jugador
|
||||||
|
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
||||||
|
checkJumpEnd(); // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
||||||
|
checkKillingTiles(); // Comprueba que el jugador no toque ningun tile de los que matan}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkInput(); // Comprueba las entradas y modifica variables
|
|
||||||
move(); // Recalcula la posición del jugador
|
|
||||||
animate(); // Establece la animación del jugador
|
|
||||||
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
|
||||||
checkJumpEnd(); // Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
|
||||||
checkKillingTiles(); // Comprueba que el jugador no toque ningun tile de los que matan
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las entradas y modifica variables
|
// Comprueba las entradas y modifica variables
|
||||||
void Player::checkInput()
|
void Player::checkInput()
|
||||||
{
|
{
|
||||||
// Solo comprueba las entradas de dirección cuando está sobre una superficie
|
// Solo comprueba las entradas de dirección cuando está sobre una superficie
|
||||||
if (state_ != s_standing)
|
if (state_ != PlayerState::STANDING)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!auto_movement_)
|
if (!auto_movement_)
|
||||||
{
|
{
|
||||||
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
|
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
|
||||||
if (input_->checkInput(input_left))
|
if (input_->checkInput(input_left))
|
||||||
{
|
{
|
||||||
@@ -223,7 +153,7 @@ void Player::checkInput()
|
|||||||
|
|
||||||
if (isOnFloor() || isOnAutoSurface())
|
if (isOnFloor() || isOnAutoSurface())
|
||||||
{
|
{
|
||||||
setState(s_jumping);
|
setState(PlayerState::JUMPING);
|
||||||
vy_ = -MAX_VY_;
|
vy_ = -MAX_VY_;
|
||||||
jump_init_pos_ = y_;
|
jump_init_pos_ = y_;
|
||||||
jumping_counter_ = 0;
|
jumping_counter_ = 0;
|
||||||
@@ -231,18 +161,6 @@ void Player::checkInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
|
||||||
bool Player::getOnBorder()
|
|
||||||
{
|
|
||||||
return is_on_border_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Indica en cual de los cuatro bordes se encuentra
|
|
||||||
int Player::getBorder()
|
|
||||||
{
|
|
||||||
return border_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
// Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
||||||
void Player::checkBorders()
|
void Player::checkBorders()
|
||||||
{
|
{
|
||||||
@@ -252,7 +170,7 @@ void Player::checkBorders()
|
|||||||
is_on_border_ = true;
|
is_on_border_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (x_ + w_ > PLAY_AREA_RIGHT)
|
else if (x_ + WIDTH_ > PLAY_AREA_RIGHT)
|
||||||
{
|
{
|
||||||
border_ = BORDER_RIGHT;
|
border_ = BORDER_RIGHT;
|
||||||
is_on_border_ = true;
|
is_on_border_ = true;
|
||||||
@@ -264,7 +182,7 @@ void Player::checkBorders()
|
|||||||
is_on_border_ = true;
|
is_on_border_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (y_ + h_ > PLAY_AREA_BOTTOM)
|
else if (y_ + HEIGHT_ > PLAY_AREA_BOTTOM)
|
||||||
{
|
{
|
||||||
border_ = BORDER_BOTTOM;
|
border_ = BORDER_BOTTOM;
|
||||||
is_on_border_ = true;
|
is_on_border_ = true;
|
||||||
@@ -280,7 +198,7 @@ void Player::checkBorders()
|
|||||||
void Player::checkState()
|
void Player::checkState()
|
||||||
{
|
{
|
||||||
// Actualiza las variables en función del estado
|
// Actualiza las variables en función del estado
|
||||||
if (state_ == s_falling)
|
if (state_ == PlayerState::FALLING)
|
||||||
{
|
{
|
||||||
vx_ = 0.0f;
|
vx_ = 0.0f;
|
||||||
vy_ = MAX_VY_;
|
vy_ = MAX_VY_;
|
||||||
@@ -288,9 +206,9 @@ void Player::checkState()
|
|||||||
playFallSound();
|
playFallSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (state_ == s_standing)
|
else if (state_ == PlayerState::STANDING)
|
||||||
{
|
{
|
||||||
if (previous_state_ == s_falling && falling_counter_ > MAX_FALLING_HEIGHT_)
|
if (previous_state_ == PlayerState::FALLING && falling_counter_ > MAX_FALLING_HEIGHT_)
|
||||||
{ // Si cae de muy alto, el jugador muere
|
{ // Si cae de muy alto, el jugador muere
|
||||||
is_alive_ = false;
|
is_alive_ = false;
|
||||||
}
|
}
|
||||||
@@ -299,7 +217,7 @@ void Player::checkState()
|
|||||||
falling_counter_ = 0;
|
falling_counter_ = 0;
|
||||||
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope())
|
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope())
|
||||||
{
|
{
|
||||||
setState(s_falling);
|
setState(PlayerState::FALLING);
|
||||||
vx_ = 0.0f;
|
vx_ = 0.0f;
|
||||||
vy_ = MAX_VY_;
|
vy_ = MAX_VY_;
|
||||||
falling_counter_++;
|
falling_counter_++;
|
||||||
@@ -307,7 +225,7 @@ void Player::checkState()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (state_ == s_jumping)
|
else if (state_ == PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
falling_counter_ = 0;
|
falling_counter_ = 0;
|
||||||
jumping_counter_++;
|
jumping_counter_++;
|
||||||
@@ -320,13 +238,13 @@ void Player::switchBorders()
|
|||||||
{
|
{
|
||||||
if (border_ == BORDER_TOP)
|
if (border_ == BORDER_TOP)
|
||||||
{
|
{
|
||||||
y_ = PLAY_AREA_BOTTOM - h_ - 0 - BLOCK;
|
y_ = PLAY_AREA_BOTTOM - HEIGHT_ - 0 - BLOCK;
|
||||||
setState(s_standing);
|
setState(PlayerState::STANDING);
|
||||||
}
|
}
|
||||||
else if (border_ == BORDER_BOTTOM)
|
else if (border_ == BORDER_BOTTOM)
|
||||||
{
|
{
|
||||||
y_ = PLAY_AREA_TOP + 0;
|
y_ = PLAY_AREA_TOP + 0;
|
||||||
setState(s_standing);
|
setState(PlayerState::STANDING);
|
||||||
}
|
}
|
||||||
else if (border_ == BORDER_RIGHT)
|
else if (border_ == BORDER_RIGHT)
|
||||||
{
|
{
|
||||||
@@ -334,7 +252,7 @@ void Player::switchBorders()
|
|||||||
}
|
}
|
||||||
if (border_ == BORDER_LEFT)
|
if (border_ == BORDER_LEFT)
|
||||||
{
|
{
|
||||||
x_ = PLAY_AREA_RIGHT - w_ - 0;
|
x_ = PLAY_AREA_RIGHT - WIDTH_ - 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_on_border_ = false;
|
is_on_border_ = false;
|
||||||
@@ -347,7 +265,7 @@ void Player::applyGravity()
|
|||||||
|
|
||||||
// La gravedad solo se aplica cuando el jugador esta saltando
|
// La gravedad solo se aplica cuando el jugador esta saltando
|
||||||
// Nunca mientras cae o esta de pie
|
// Nunca mientras cae o esta de pie
|
||||||
if (state_ == s_jumping)
|
if (state_ == PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
vy_ += GF;
|
vy_ += GF;
|
||||||
if (vy_ > MAX_VY_)
|
if (vy_ > MAX_VY_)
|
||||||
@@ -357,19 +275,6 @@ void Player::applyGravity()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el rectangulo que delimita al jugador
|
|
||||||
SDL_Rect Player::getRect()
|
|
||||||
{
|
|
||||||
return {static_cast<int>(x_), static_cast<int>(y_), w_, h_};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el rectangulo de colision del jugador
|
|
||||||
SDL_Rect &Player::getCollider()
|
|
||||||
{
|
|
||||||
collider_box_ = getRect();
|
|
||||||
return collider_box_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recalcula la posición del jugador y su animación
|
// Recalcula la posición del jugador y su animación
|
||||||
void Player::move()
|
void Player::move()
|
||||||
{
|
{
|
||||||
@@ -378,7 +283,7 @@ void Player::move()
|
|||||||
checkState(); // Comprueba el estado del jugador
|
checkState(); // Comprueba el estado del jugador
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debugColor = {0, 255, 0};
|
debug_color_ = {0, 255, 0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Se mueve hacia la izquierda
|
// Se mueve hacia la izquierda
|
||||||
@@ -388,11 +293,11 @@ void Player::move()
|
|||||||
SDL_Rect proj;
|
SDL_Rect proj;
|
||||||
proj.x = static_cast<int>(x_ + vx_);
|
proj.x = static_cast<int>(x_ + vx_);
|
||||||
proj.y = static_cast<int>(y_);
|
proj.y = static_cast<int>(y_);
|
||||||
proj.h = h_;
|
proj.h = HEIGHT_;
|
||||||
proj.w = ceil(abs(vx_)); // Para evitar que tenga un ancho de 0 pixels
|
proj.w = ceil(abs(vx_)); // Para evitar que tenga un ancho de 0 pixels
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
rx = proj;
|
debug_rect_x_ = proj;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies
|
// Comprueba la colisión con las superficies
|
||||||
@@ -411,18 +316,18 @@ void Player::move()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
|
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
|
||||||
if (state_ != s_jumping)
|
if (state_ != PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
v_line_t leftSide = {static_cast<int>(x_), static_cast<int>(y_) + h_ - 2, static_cast<int>(y_) + h_ - 1}; // Comprueba solo los dos pixels de abajo
|
v_line_t leftSide = {static_cast<int>(x_), static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo
|
||||||
const int ly = room_->checkLeftSlopes(&leftSide);
|
const int ly = room_->checkLeftSlopes(&leftSide);
|
||||||
if (ly > -1)
|
if (ly > -1)
|
||||||
{
|
{
|
||||||
y_ = ly - h_;
|
y_ = ly - HEIGHT_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está bajando la rampa, recoloca al jugador
|
// Si está bajando la rampa, recoloca al jugador
|
||||||
if (isOnDownSlope() && state_ != s_jumping)
|
if (isOnDownSlope() && state_ != PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
y_ += 1;
|
y_ += 1;
|
||||||
}
|
}
|
||||||
@@ -433,13 +338,13 @@ void Player::move()
|
|||||||
{
|
{
|
||||||
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
||||||
SDL_Rect proj;
|
SDL_Rect proj;
|
||||||
proj.x = static_cast<int>(x_) + w_;
|
proj.x = static_cast<int>(x_) + WIDTH_;
|
||||||
proj.y = static_cast<int>(y_);
|
proj.y = static_cast<int>(y_);
|
||||||
proj.h = h_;
|
proj.h = HEIGHT_;
|
||||||
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
rx = proj;
|
debug_rect_x_ = proj;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
@@ -454,38 +359,38 @@ void Player::move()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Si hay colisión lo mueve hasta donde no colisiona
|
// Si hay colisión lo mueve hasta donde no colisiona
|
||||||
x_ = pos - w_;
|
x_ = pos - WIDTH_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
|
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
|
||||||
if (state_ != s_jumping)
|
if (state_ != PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
v_line_t rightSide = {static_cast<int>(x_) + w_ - 1, static_cast<int>(y_) + h_ - 2, static_cast<int>(y_) + h_ - 1}; // Comprueba solo los dos pixels de abajo
|
v_line_t rightSide = {static_cast<int>(x_) + WIDTH_ - 1, static_cast<int>(y_) + HEIGHT_ - 2, static_cast<int>(y_) + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo
|
||||||
const int ry = room_->checkRightSlopes(&rightSide);
|
const int ry = room_->checkRightSlopes(&rightSide);
|
||||||
if (ry > -1)
|
if (ry > -1)
|
||||||
{
|
{
|
||||||
y_ = ry - h_;
|
y_ = ry - HEIGHT_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está bajando la rampa, recoloca al jugador
|
// Si está bajando la rampa, recoloca al jugador
|
||||||
if (isOnDownSlope() && state_ != s_jumping)
|
if (isOnDownSlope() && state_ != PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
y_ += 1;
|
y_ += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si ha salido del suelo, el jugador cae
|
// Si ha salido del suelo, el jugador cae
|
||||||
if (state_ == s_standing && !isOnFloor())
|
if (state_ == PlayerState::STANDING && !isOnFloor())
|
||||||
{
|
{
|
||||||
setState(s_falling);
|
setState(PlayerState::FALLING);
|
||||||
|
|
||||||
// Deja de estar enganchado a la superficie automatica
|
// Deja de estar enganchado a la superficie automatica
|
||||||
auto_movement_ = false;
|
auto_movement_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si ha salido de una superficie automatica, detiene el movimiento automatico
|
// Si ha salido de una superficie automatica, detiene el movimiento automatico
|
||||||
if (state_ == s_standing && isOnFloor() && !isOnAutoSurface())
|
if (state_ == PlayerState::STANDING && isOnFloor() && !isOnAutoSurface())
|
||||||
{
|
{
|
||||||
// Deja de estar enganchado a la superficie automatica
|
// Deja de estar enganchado a la superficie automatica
|
||||||
auto_movement_ = false;
|
auto_movement_ = false;
|
||||||
@@ -499,10 +404,10 @@ void Player::move()
|
|||||||
proj.x = static_cast<int>(x_);
|
proj.x = static_cast<int>(x_);
|
||||||
proj.y = static_cast<int>(y_ + vy_);
|
proj.y = static_cast<int>(y_ + vy_);
|
||||||
proj.h = ceil(abs(vy_)); // Para evitar que tenga una altura de 0 pixels
|
proj.h = ceil(abs(vy_)); // Para evitar que tenga una altura de 0 pixels
|
||||||
proj.w = w_;
|
proj.w = WIDTH_;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
ry = proj;
|
debug_rect_y_ = proj;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
@@ -518,7 +423,7 @@ void Player::move()
|
|||||||
{
|
{
|
||||||
// Si hay colisión lo mueve hasta donde no colisiona y entra en caída
|
// Si hay colisión lo mueve hasta donde no colisiona y entra en caída
|
||||||
y_ = pos + 1;
|
y_ = pos + 1;
|
||||||
setState(s_falling);
|
setState(PlayerState::FALLING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,12 +433,12 @@ void Player::move()
|
|||||||
// Crea el rectangulo de proyección en el eje Y para ver si colisiona
|
// Crea el rectangulo de proyección en el eje Y para ver si colisiona
|
||||||
SDL_Rect proj;
|
SDL_Rect proj;
|
||||||
proj.x = static_cast<int>(x_);
|
proj.x = static_cast<int>(x_);
|
||||||
proj.y = static_cast<int>(y_) + h_;
|
proj.y = static_cast<int>(y_) + HEIGHT_;
|
||||||
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
||||||
proj.w = w_;
|
proj.w = WIDTH_;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
ry = proj;
|
debug_rect_y_ = proj;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies normales y las automáticas
|
// Comprueba la colisión con las superficies normales y las automáticas
|
||||||
@@ -541,8 +446,8 @@ void Player::move()
|
|||||||
if (pos > -1)
|
if (pos > -1)
|
||||||
{
|
{
|
||||||
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
||||||
y_ = pos - h_;
|
y_ = pos - HEIGHT_;
|
||||||
setState(s_standing);
|
setState(PlayerState::STANDING);
|
||||||
|
|
||||||
// Deja de estar enganchado a la superficie automatica
|
// Deja de estar enganchado a la superficie automatica
|
||||||
auto_movement_ = false;
|
auto_movement_ = false;
|
||||||
@@ -550,7 +455,7 @@ void Player::move()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Si no hay colisión con los muros, comprueba la colisión con las rampas
|
// Si no hay colisión con los muros, comprueba la colisión con las rampas
|
||||||
if (state_ != s_jumping)
|
if (state_ != PlayerState::JUMPING)
|
||||||
{ // Las rampas no se miran si se está saltando
|
{ // Las rampas no se miran si se está saltando
|
||||||
v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1};
|
v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1};
|
||||||
v_line_t rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
|
v_line_t rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
|
||||||
@@ -559,11 +464,11 @@ void Player::move()
|
|||||||
{
|
{
|
||||||
// No está saltando y hay colisión con una rampa
|
// No está saltando y hay colisión con una rampa
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
y_ = p - h_;
|
y_ = p - HEIGHT_;
|
||||||
setState(s_standing);
|
setState(PlayerState::STANDING);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debugColor = {255, 255, 0};
|
debug_color_ = {255, 255, 0};
|
||||||
debugPoint = {(int)x_ + (w_ / 2), p};
|
debug_point_ = {(int)x_ + (WIDTH_ / 2), p};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -572,7 +477,7 @@ void Player::move()
|
|||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
y_ += vy_;
|
y_ += vy_;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debugColor = {255, 0, 0};
|
debug_color_ = {255, 0, 0};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -585,13 +490,12 @@ void Player::move()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
placeSprite(); // Coloca el sprite en la nueva posición
|
||||||
sprite_->setPosX(x_);
|
collider_box_ = getRect(); // Actualiza el rectangulo de colisión
|
||||||
sprite_->setPosY(y_);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug_->add("RECT_X: " + std::to_string(rx.x) + "," + std::to_string(rx.y) + "," + std::to_string(rx.w) + "," + std::to_string(rx.h));
|
debug_->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
|
||||||
debug_->add("RECT_Y: " + std::to_string(ry.x) + "," + std::to_string(ry.y) + "," + std::to_string(ry.w) + "," + std::to_string(ry.h));
|
debug_->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,14 +511,14 @@ void Player::animate()
|
|||||||
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
||||||
void Player::checkJumpEnd()
|
void Player::checkJumpEnd()
|
||||||
{
|
{
|
||||||
if (state_ == s_jumping)
|
if (state_ == PlayerState::JUMPING)
|
||||||
{
|
{
|
||||||
if (vy_ > 0)
|
if (vy_ > 0)
|
||||||
{
|
{
|
||||||
if (y_ >= jump_init_pos_)
|
if (y_ >= jump_init_pos_)
|
||||||
{
|
{
|
||||||
// Si alcanza la altura de salto inicial, pasa al estado de caída
|
// Si alcanza la altura de salto inicial, pasa al estado de caída
|
||||||
setState(s_falling);
|
setState(PlayerState::FALLING);
|
||||||
vy_ = MAX_VY_;
|
vy_ = MAX_VY_;
|
||||||
jumping_counter_ = 0;
|
jumping_counter_ = 0;
|
||||||
}
|
}
|
||||||
@@ -760,46 +664,23 @@ bool Player::checkKillingTiles()
|
|||||||
return check;
|
return check;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene algunos parametros del jugador
|
// Establece el color del jugador
|
||||||
playerSpawn_t Player::getSpawnParams()
|
void Player::setColor()
|
||||||
{
|
{
|
||||||
playerSpawn_t params;
|
|
||||||
|
|
||||||
params.x = x_;
|
|
||||||
params.y = y_;
|
|
||||||
params.vx = vx_;
|
|
||||||
params.vy = vy_;
|
|
||||||
params.jump_init_pos = jump_init_pos_;
|
|
||||||
params.state = state_;
|
|
||||||
params.flip = sprite_->getFlip();
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recarga la textura
|
|
||||||
void Player::reLoadTexture()
|
|
||||||
{
|
|
||||||
sprite_->getTexture()->reLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recarga la paleta
|
|
||||||
void Player::reLoadPalette()
|
|
||||||
{
|
|
||||||
color_ = stringToColor(options.video.palette, "white");
|
|
||||||
if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED)
|
|
||||||
{
|
|
||||||
color_ = stringToColor(options.video.palette, "yellow");
|
|
||||||
}
|
|
||||||
if (options.cheats.invincible == Cheat::CheatState::ENABLED)
|
if (options.cheats.invincible == Cheat::CheatState::ENABLED)
|
||||||
{
|
{
|
||||||
color_ = stringToColor(options.video.palette, "cyan");
|
color_ = stringToColor(options.video.palette, "cyan");
|
||||||
}
|
}
|
||||||
}
|
else if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED)
|
||||||
|
{
|
||||||
|
color_ = stringToColor(options.video.palette, "yellow");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color_ = stringToColor(options.video.palette, "white");
|
||||||
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
||||||
void Player::setRoom(std::shared_ptr<Room> room)
|
|
||||||
{
|
|
||||||
room_ = room;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los puntos de colisión
|
// Actualiza los puntos de colisión
|
||||||
@@ -821,15 +702,15 @@ void Player::updateFeet()
|
|||||||
{
|
{
|
||||||
const SDL_Point p = {static_cast<int>(x_), static_cast<int>(y_)};
|
const SDL_Point p = {static_cast<int>(x_), static_cast<int>(y_)};
|
||||||
|
|
||||||
under_feet_[0] = {p.x, p.y + h_};
|
under_feet_[0] = {p.x, p.y + HEIGHT_};
|
||||||
under_feet_[1] = {p.x + 7, p.y + h_};
|
under_feet_[1] = {p.x + 7, p.y + HEIGHT_};
|
||||||
|
|
||||||
feet_[0] = {p.x, p.y + h_ - 1};
|
feet_[0] = {p.x, p.y + HEIGHT_ - 1};
|
||||||
feet_[1] = {p.x + 7, p.y + h_ - 1};
|
feet_[1] = {p.x + 7, p.y + HEIGHT_ - 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el estado del jugador
|
// Cambia el estado del jugador
|
||||||
void Player::setState(state_e value)
|
void Player::setState(PlayerState value)
|
||||||
{
|
{
|
||||||
previous_state_ = state_;
|
previous_state_ = state_;
|
||||||
state_ = value;
|
state_ = value;
|
||||||
@@ -837,20 +718,49 @@ void Player::setState(state_e value)
|
|||||||
checkState();
|
checkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el jugador esta vivo
|
// Inicializa los sonidos de salto y caida
|
||||||
bool Player::isAlive()
|
void Player::initSounds()
|
||||||
{
|
{
|
||||||
return is_alive_;
|
jumping_sound_.clear();
|
||||||
|
falling_sound_.clear();
|
||||||
|
|
||||||
|
for (int i = 1; i <= 24; ++i)
|
||||||
|
{
|
||||||
|
std::string soundFile = "jump" + std::to_string(i) + ".wav";
|
||||||
|
jumping_sound_.push_back(Resource::get()->getSound(soundFile));
|
||||||
|
|
||||||
|
if (i >= 11)
|
||||||
|
{
|
||||||
|
falling_sound_.push_back(Resource::get()->getSound(soundFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone el jugador en modo pausa
|
// Coloca el sprite en la posición del jugador
|
||||||
void Player::pause()
|
void Player::placeSprite()
|
||||||
{
|
{
|
||||||
is_paused_ = true;
|
sprite_->setPosX(x_);
|
||||||
|
sprite_->setPosY(y_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quita el modo pausa del jugador
|
// Aplica los valores de spawn al jugador
|
||||||
void Player::resume()
|
void Player::applySpawnValues(const PlayerSpawn &spawn)
|
||||||
{
|
{
|
||||||
is_paused_ = false;
|
x_ = spawn.x;
|
||||||
|
y_ = spawn.y;
|
||||||
|
vx_ = spawn.vx;
|
||||||
|
vy_ = spawn.vy;
|
||||||
|
jump_init_pos_ = spawn.jump_init_pos;
|
||||||
|
state_ = spawn.state;
|
||||||
|
sprite_->setFlip(spawn.flip);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa el sprite del jugador
|
||||||
|
void Player::initSprite(const std::string &png, const std::string &animation)
|
||||||
|
{
|
||||||
|
sprite_ = std::make_shared<AnimatedSprite>(png, animation);
|
||||||
|
sprite_->setWidth(WIDTH_);
|
||||||
|
sprite_->setHeight(HEIGHT_);
|
||||||
|
sprite_->setCurrentAnimation("walk");
|
||||||
|
// sprite_->update();
|
||||||
}
|
}
|
||||||
109
source/player.h
109
source/player.h
@@ -8,7 +8,7 @@
|
|||||||
#include "utils.h" // Para color_t
|
#include "utils.h" // Para color_t
|
||||||
#include "defines.h" // Para BLOCK
|
#include "defines.h" // Para BLOCK
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
class AnimatedSprite;
|
#include "animated_sprite.h"
|
||||||
class Asset;
|
class Asset;
|
||||||
class Debug;
|
class Debug;
|
||||||
class Input;
|
class Input;
|
||||||
@@ -16,43 +16,55 @@ class Resource;
|
|||||||
class Room;
|
class Room;
|
||||||
struct JA_Sound_t;
|
struct JA_Sound_t;
|
||||||
|
|
||||||
enum state_e
|
enum class PlayerState
|
||||||
{
|
{
|
||||||
s_standing,
|
STANDING,
|
||||||
s_jumping,
|
JUMPING,
|
||||||
s_falling
|
FALLING,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct playerSpawn_t
|
struct PlayerSpawn
|
||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float vx;
|
float vx;
|
||||||
float vy;
|
float vy;
|
||||||
int jump_init_pos;
|
int jump_init_pos;
|
||||||
state_e state;
|
PlayerState state;
|
||||||
SDL_RendererFlip flip;
|
SDL_RendererFlip flip;
|
||||||
|
|
||||||
|
// Constructor por defecto
|
||||||
|
PlayerSpawn() : x(0), y(0), vx(0), vy(0), jump_init_pos(0), state(PlayerState::STANDING), flip(SDL_FLIP_NONE) {}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
PlayerSpawn(float x, float y, float vx, float vy, int jump_init_pos, PlayerState state, SDL_RendererFlip flip)
|
||||||
|
: x(x), y(y), vx(vx), vy(vy), jump_init_pos(jump_init_pos), state(state), flip(flip) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct player_t
|
struct PlayerData
|
||||||
{
|
{
|
||||||
playerSpawn_t spawn;
|
PlayerSpawn spawn;
|
||||||
std::string png;
|
std::shared_ptr< texture;
|
||||||
std::string animation;
|
std::string animation;
|
||||||
std::shared_ptr<Room> room;
|
std::shared_ptr<Room> room;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
PlayerData(PlayerSpawn spawn, std::string png, std::string animation, std::shared_ptr<Room> room)
|
||||||
|
: spawn(spawn), texture(png), animation(animation), room(room) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constantes
|
// Constantes
|
||||||
|
static constexpr int WIDTH_ = 8; // Ancho del jugador
|
||||||
|
static constexpr int HEIGHT_ = 16; // ALto del jugador
|
||||||
static constexpr int MAX_FALLING_HEIGHT_ = BLOCK * 4; // Altura maxima permitida de caída.
|
static constexpr int MAX_FALLING_HEIGHT_ = BLOCK * 4; // Altura maxima permitida de caída.
|
||||||
static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Input *input_; // Objeto para gestionar la entrada
|
Input *input_; // Objeto para gestionar la entrada
|
||||||
Resource *resource_; // Objeto con los recursos
|
|
||||||
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
Debug *debug_; // Objeto para gestionar la información de debug
|
Debug *debug_; // Objeto para gestionar la información de debug
|
||||||
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
|
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
|
||||||
@@ -63,32 +75,30 @@ public:
|
|||||||
float y_; // Posición del jugador en el eje Y
|
float y_; // Posición del jugador en el eje Y
|
||||||
float vx_; // Velocidad/desplazamiento del jugador en el eje X
|
float vx_; // Velocidad/desplazamiento del jugador en el eje X
|
||||||
float vy_; // Velocidad/desplazamiento del jugador en el eje Y
|
float vy_; // Velocidad/desplazamiento del jugador en el eje Y
|
||||||
int w_; // Ancho del jugador
|
|
||||||
int h_; // ALto del jugador
|
|
||||||
Color color_; // Color del jugador
|
Color color_; // Color del jugador
|
||||||
SDL_Rect collider_box_; // Caja de colisión con los enemigos u objetos
|
SDL_Rect collider_box_; // Caja de colisión con los enemigos u objetos
|
||||||
std::vector<SDL_Point> collider_points_; // Puntos de colisión con el mapa
|
std::vector<SDL_Point> collider_points_; // Puntos de colisión con el mapa
|
||||||
std::vector<SDL_Point> under_feet_; // Contiene los puntos que hay bajo cada pie del jugador
|
std::vector<SDL_Point> under_feet_; // Contiene los puntos que hay bajo cada pie del jugador
|
||||||
std::vector<SDL_Point> feet_; // Contiene los puntos que hay en el pie del jugador
|
std::vector<SDL_Point> feet_; // Contiene los puntos que hay en el pie del jugador
|
||||||
state_e state_; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
PlayerState state_; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||||
state_e previous_state_; // Estado previo en el que se encontraba el jugador
|
PlayerState previous_state_; // Estado previo en el que se encontraba el jugador
|
||||||
bool is_on_border_; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
bool is_on_border_ = false; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||||
int border_; // Indica en cual de los cuatro bordes se encuentra
|
bool is_alive_ = true; // Indica si el jugador esta vivo o no
|
||||||
bool auto_movement_; // Indica si esta siendo arrastrado por una superficie automatica
|
bool is_paused_ = false; // Indica si el jugador esta en modo pausa
|
||||||
bool is_paused_; // Indica si el jugador esta en modo pausa
|
bool auto_movement_ = false; // Indica si esta siendo arrastrado por una superficie automatica
|
||||||
|
int border_ = BORDER_TOP; // Indica en cual de los cuatro bordes se encuentra
|
||||||
SDL_Rect last_position_; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento
|
SDL_Rect last_position_; // Contiene la ultima posición del jugador, por si hay que deshacer algun movimiento
|
||||||
int jump_init_pos_; // Valor del eje Y en el que se inicia el salto
|
int jump_init_pos_; // Valor del eje Y en el que se inicia el salto
|
||||||
std::vector<JA_Sound_t *> jumping_sound_; // Vecor con todos los sonidos del salto
|
std::vector<JA_Sound_t *> jumping_sound_; // Vecor con todos los sonidos del salto
|
||||||
std::vector<JA_Sound_t *> falling_sound_; // Vecor con todos los sonidos de la caída
|
std::vector<JA_Sound_t *> falling_sound_; // Vecor con todos los sonidos de la caída
|
||||||
int jumping_counter_; // Cuenta el tiempo de salto
|
int jumping_counter_ = 0; // Cuenta el tiempo de salto
|
||||||
int falling_counter_; // Cuenta el tiempo de caida
|
int falling_counter_ = 0; // Cuenta el tiempo de caida
|
||||||
bool is_alive_; // Indica si el jugador esta vivo o no
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
|
SDL_Rect debug_rect_x_; // Rectangulo de desplazamiento para el modo debug
|
||||||
SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug
|
SDL_Rect debug_rect_y_; // Rectangulo de desplazamiento para el modo debug
|
||||||
Color debugColor; // Color del recuadro de debug del jugador
|
Color debug_color_; // Color del recuadro de debug del jugador
|
||||||
SDL_Point debugPoint; // Punto para debug
|
SDL_Point debug_point_; // Punto para debug
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba las entradas y modifica variables
|
// Comprueba las entradas y modifica variables
|
||||||
@@ -100,9 +110,6 @@ public:
|
|||||||
// Comprueba el estado del jugador
|
// Comprueba el estado del jugador
|
||||||
void checkState();
|
void checkState();
|
||||||
|
|
||||||
// Asigna velocidad negativa en el eje Y al jugador
|
|
||||||
void jump();
|
|
||||||
|
|
||||||
// Aplica gravedad al jugador
|
// Aplica gravedad al jugador
|
||||||
void applyGravity();
|
void applyGravity();
|
||||||
|
|
||||||
@@ -140,11 +147,23 @@ public:
|
|||||||
void updateFeet();
|
void updateFeet();
|
||||||
|
|
||||||
// Cambia el estado del jugador
|
// Cambia el estado del jugador
|
||||||
void setState(state_e value);
|
void setState(PlayerState value);
|
||||||
|
|
||||||
|
// Inicializa los sonidos de salto y caida
|
||||||
|
void initSounds();
|
||||||
|
|
||||||
|
// Coloca el sprite en la posición del jugador
|
||||||
|
void placeSprite();
|
||||||
|
|
||||||
|
// Aplica los valores de spawn al jugador
|
||||||
|
void applySpawnValues(const PlayerSpawn &spawn);
|
||||||
|
|
||||||
|
// Inicializa el sprite del jugador
|
||||||
|
void initSprite(const std::string &png, const std::string &animation);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Player(player_t player);
|
Player(PlayerData player);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Player() = default;
|
~Player() = default;
|
||||||
@@ -156,38 +175,38 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||||
bool getOnBorder();
|
bool getOnBorder() { return is_on_border_; }
|
||||||
|
|
||||||
// Indica en cual de los cuatro bordes se encuentra
|
// Indica en cual de los cuatro bordes se encuentra
|
||||||
int getBorder();
|
int getBorder() { return border_; }
|
||||||
|
|
||||||
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
||||||
void switchBorders();
|
void switchBorders();
|
||||||
|
|
||||||
// Obtiene el rectangulo que delimita al jugador
|
// Obtiene el rectangulo que delimita al jugador
|
||||||
SDL_Rect getRect();
|
SDL_Rect getRect() { return {static_cast<int>(x_), static_cast<int>(y_), WIDTH_, HEIGHT_}; }
|
||||||
|
|
||||||
// Obtiene el rectangulo de colision del jugador
|
// Obtiene el rectangulo de colision del jugador
|
||||||
SDL_Rect &getCollider();
|
SDL_Rect &getCollider() { return collider_box_; }
|
||||||
|
|
||||||
// Obtiene algunos parametros del jugador
|
// Obtiene el estado de reaparición del jugador
|
||||||
playerSpawn_t getSpawnParams();
|
PlayerSpawn getSpawnParams() { return {x_, y_, vx_, vy_, jump_init_pos_, state_, sprite_->getFlip()}; }
|
||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void reLoadTexture();
|
void reLoadTexture() { sprite_->getTexture()->reLoad(); }
|
||||||
|
|
||||||
// Recarga la paleta
|
// Establece el color del jugador
|
||||||
void reLoadPalette();
|
void setColor();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece la habitación en la que se encuentra el jugador
|
||||||
void setRoom(std::shared_ptr<Room> room);
|
void setRoom(std::shared_ptr<Room> room) { room_ = room; }
|
||||||
|
|
||||||
// Comprueba si el jugador esta vivo
|
// Comprueba si el jugador esta vivo
|
||||||
bool isAlive();
|
bool isAlive() { return is_alive_; }
|
||||||
|
|
||||||
// Pone el jugador en modo pausa
|
// Pone el jugador en modo pausa
|
||||||
void pause();
|
void pause() { is_paused_ = true; }
|
||||||
|
|
||||||
// Quita el modo pausa del jugador
|
// Quita el modo pausa del jugador
|
||||||
void resume();
|
void resume() { is_paused_ = false; }
|
||||||
};
|
};
|
||||||
@@ -213,7 +213,7 @@ void Title::renderInfo()
|
|||||||
void Title::update()
|
void Title::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
if (SDL_GetTicks() - ticks_ > GAME_SPEED)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks_ = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ private:
|
|||||||
int counter_ = 0; // Contador
|
int counter_ = 0; // Contador
|
||||||
std::string long_text_; // Texto que aparece en la parte inferior del titulo
|
std::string long_text_; // Texto que aparece en la parte inferior del titulo
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
std::vector<letter_t> letters_; // Vector con las letras de la marquesina
|
std::vector<letter_t> letters_; // Vector con las letras de la marquesina
|
||||||
int marquee_speed_ = 3; // Velocidad de desplazamiento de la marquesina
|
int marquee_speed_ = 3; // Velocidad de desplazamiento de la marquesina
|
||||||
bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros
|
bool show_cheevos_ = false; // Indica si se muestra por pantalla el listado de logros
|
||||||
|
|||||||
Reference in New Issue
Block a user