canvi de pc
This commit is contained in:
@@ -1,67 +1,63 @@
|
||||
#include "game_over.h"
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min, max
|
||||
#include <string> // for basic_string, operator+, to_string, cha...
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "asset.h" // for Asset
|
||||
#include "defines.h" // for GAMECANVAS_CENTER_X
|
||||
#include "global_events.h" // for check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_PlayMusic
|
||||
#include "options.h" // for Options, options, OptionsStats, Section...
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
||||
#include "texture.h" // for Texture
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min, max
|
||||
#include <string> // for basic_string, operator+, to_string, cha...
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "asset.h" // for Asset
|
||||
#include "defines.h" // for GAMECANVAS_CENTER_X
|
||||
#include "global_events.h" // for check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_PlayMusic
|
||||
#include "options.h" // for Options, options, OptionsStats, Section...
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
GameOver::GameOver()
|
||||
: screen(Screen::get()),
|
||||
renderer(Screen::get()->getRenderer()),
|
||||
resource(Resource::get()),
|
||||
asset(Asset::get()),
|
||||
input(Input::get())
|
||||
: screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
resource_(Resource::get()),
|
||||
asset_(Asset::get()),
|
||||
input_(Input::get())
|
||||
{
|
||||
// Reserva memoria para los punteros a objetos
|
||||
text = resource->getText("smb2");
|
||||
playerSprite = 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"));
|
||||
music = resource->getMusic("game_over.ogg");
|
||||
text_ = resource_->getText("smb2");
|
||||
player_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("player_game_over.png"), resource_->getAnimation("player_game_over.ani"));
|
||||
tv_sprite_ = std::make_shared<AnimatedSprite>(resource_->getTexture("tv.png"), resource_->getAnimation("tv.ani"));
|
||||
music_ = resource_->getMusic("game_over.ogg");
|
||||
|
||||
// Inicializa variables
|
||||
preCounter = 0;
|
||||
counter = 0;
|
||||
pre_counter_ = 0;
|
||||
counter_ = 0;
|
||||
options.section.section = Section::GAME_OVER;
|
||||
options.section.subsection = Subsection::NONE;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
endSection = 400;
|
||||
iniFade = 310;
|
||||
fadeLenght = 20;
|
||||
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
|
||||
playerSprite->setPosY(30);
|
||||
tvSprite->setPosX(GAMECANVAS_CENTER_X - tvSprite->getWidth() - 10);
|
||||
tvSprite->setPosY(30);
|
||||
ticks_ = 0;
|
||||
player_sprite_->setPosX(GAMECANVAS_CENTER_X + 10);
|
||||
player_sprite_->setPosY(30);
|
||||
tv_sprite_->setPosX(GAMECANVAS_CENTER_X - tv_sprite_->getWidth() - 10);
|
||||
tv_sprite_->setPosY(30);
|
||||
|
||||
// Inicializa el vector de colores
|
||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||
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
|
||||
void GameOver::update()
|
||||
{
|
||||
// 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
|
||||
ticks = SDL_GetTicks();
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
@@ -73,44 +69,41 @@ void GameOver::update()
|
||||
updateCounters();
|
||||
|
||||
// Actualiza los dos sprites
|
||||
playerSprite->update();
|
||||
tvSprite->update();
|
||||
player_sprite_->update();
|
||||
tv_sprite_->update();
|
||||
|
||||
screen->update();
|
||||
screen_->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
void GameOver::render()
|
||||
{
|
||||
const int y = 32;
|
||||
constexpr int Y = 32;
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
screen_->start();
|
||||
screen_->clean();
|
||||
|
||||
// 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
|
||||
playerSprite->setPosY(y + 30);
|
||||
tvSprite->setPosY(y + 30);
|
||||
player_sprite_->setPosY(Y + 30);
|
||||
tv_sprite_->setPosY(Y + 30);
|
||||
renderSprites();
|
||||
|
||||
// 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 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 + 90, "ROOMS: " + roomsTxt, 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_);
|
||||
|
||||
// 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 + 120, options.stats.worst_nightmare, 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_);
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen->render();
|
||||
screen_->render();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
@@ -143,53 +136,53 @@ void GameOver::run()
|
||||
// Actualiza el color usado para renderizar los textos e imagenes
|
||||
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 int index = (colors.size() - 1) - int((colors.size() - 1) * step);
|
||||
color = colors[index];
|
||||
const float step = std::min(counter_, COUNTER_FADE_LENGHT_) / (float)COUNTER_FADE_LENGHT_;
|
||||
const int index = (colors_.size() - 1) - int((colors_.size() - 1) * step);
|
||||
color_ = colors_[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
|
||||
const int index = (colors.size() - 1) * step;
|
||||
color = colors[index];
|
||||
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;
|
||||
color_ = colors_[index];
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja los sprites
|
||||
void GameOver::renderSprites()
|
||||
{
|
||||
playerSprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
playerSprite->render();
|
||||
player_sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
||||
player_sprite_->render();
|
||||
|
||||
tvSprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
tvSprite->render();
|
||||
tv_sprite_->getTexture()->setColor(color_.r, color_.g, color_.b);
|
||||
tv_sprite_->render();
|
||||
}
|
||||
|
||||
// Actualiza los contadores
|
||||
void GameOver::updateCounters()
|
||||
{
|
||||
// Actualiza el contador
|
||||
if (preCounter < 50)
|
||||
if (pre_counter_ < 50)
|
||||
{
|
||||
preCounter++;
|
||||
pre_counter_++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
counter_++;
|
||||
}
|
||||
|
||||
// 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
|
||||
else if (counter == endSection)
|
||||
else if (counter_ == COUNTER_SECTION_END_)
|
||||
{
|
||||
options.section.section = Section::LOGO;
|
||||
options.section.subsection = Subsection::LOGO_TO_TITLE;
|
||||
|
||||
Reference in New Issue
Block a user