forked from jaildesigner-jailgames/jaildoctors_dilemma
Arreglos en la estructura i format del codi
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
#include "loading_screen.h"
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for rand
|
||||
#include "asset.h" // for Asset
|
||||
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||
#include "global_events.h" // for check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic
|
||||
#include "options.h" // for Options, options, OptionsVideo, Section...
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Color, stringToColor, Palette
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for rand
|
||||
#include "asset.h" // for Asset
|
||||
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||
#include "global_events.h" // for check
|
||||
#include "global_inputs.h" // for check
|
||||
#include "input.h" // for Input
|
||||
#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic
|
||||
#include "options.h" // for Options, options, OptionsVideo, Section...
|
||||
#include "resource.h" // for Resource
|
||||
#include "screen.h" // for Screen
|
||||
#include "sprite.h" // for Sprite
|
||||
#include "texture.h" // for Texture
|
||||
#include "utils.h" // for Color, stringToColor, Palette
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
@@ -42,13 +42,13 @@ LoadingScreen::LoadingScreen()
|
||||
loading_sound3_ = resource_->getMusic("loading_sound3.ogg");
|
||||
|
||||
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
|
||||
if (texture_ == nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "LoadingScreen::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
if (texture_ == nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "LoadingScreen::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
clearTexture();
|
||||
|
||||
// Inicializa variables
|
||||
@@ -62,14 +62,12 @@ LoadingScreen::LoadingScreen()
|
||||
{ // Primer bloque de 2K
|
||||
line_index_[i] = ((i % 8) * 8) + (i / 8);
|
||||
}
|
||||
|
||||
else if (i >= 64 && i < 128)
|
||||
else if (i < 128)
|
||||
{ // Segundo bloque de 2K
|
||||
line_index_[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
|
||||
}
|
||||
|
||||
else if (i >= 128 && i < 192)
|
||||
{ // tercer bloque de 2K
|
||||
else
|
||||
{ // Tercer bloque de 2K
|
||||
line_index_[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
|
||||
}
|
||||
}
|
||||
@@ -169,30 +167,32 @@ void LoadingScreen::renderLoad()
|
||||
// Dibuja el efecto de carga en el borde
|
||||
void LoadingScreen::renderBorder()
|
||||
{
|
||||
// Pinta el borde de colro azul
|
||||
Color color = stringToColor(options.video.palette, "blue");
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
// Pinta el borde de colro azul
|
||||
Color color = stringToColor(options.video.palette, "blue");
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Añade lineas amarillas
|
||||
color = stringToColor(options.video.palette, "yellow");
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
const int width = options.game.width + (options.video.border.width * 2);
|
||||
const int height = options.game.height + (options.video.border.height * 2);
|
||||
bool drawEnabled = rand() % 2 == 0 ? true : false;
|
||||
int row = 0;
|
||||
int rowSize = 1;
|
||||
while (row < height)
|
||||
{
|
||||
rowSize = (rand() % 4) + 3;
|
||||
if (drawEnabled)
|
||||
for (int i = row; i < row + rowSize; ++i)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer_, 0, i, width, i);
|
||||
}
|
||||
row += rowSize;
|
||||
drawEnabled = !drawEnabled;
|
||||
}
|
||||
// Añade lineas amarillas
|
||||
color = stringToColor(options.video.palette, "yellow");
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
const int WIDTH = options.game.width + (options.video.border.width * 2);
|
||||
const int HEIGHT = options.game.height + (options.video.border.height * 2);
|
||||
bool drawEnabled = rand() % 2 == 0 ? true : false;
|
||||
|
||||
int row = 0;
|
||||
while (row < HEIGHT)
|
||||
{
|
||||
const int ROW_HEIGHT = (rand() % 4) + 3;
|
||||
if (drawEnabled)
|
||||
{
|
||||
for (int i = row; i < row + ROW_HEIGHT; ++i)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer_, 0, i, WIDTH, i);
|
||||
}
|
||||
}
|
||||
row += ROW_HEIGHT;
|
||||
drawEnabled = !drawEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
@@ -254,70 +254,31 @@ void LoadingScreen::run()
|
||||
JA_SetVolume(128);
|
||||
}
|
||||
|
||||
// Reconstruye la pantalla de carga
|
||||
void LoadingScreen::recreateLoadingScreen()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen_->start();
|
||||
|
||||
// Primera parte de la carga, la parte en blanco y negro
|
||||
if (loading_first_part_)
|
||||
{
|
||||
const int numSteps = 5;
|
||||
const int step = 51;
|
||||
|
||||
for (int i = 0; i <= counter_; i++)
|
||||
{
|
||||
load_counter_ = i / numSteps;
|
||||
load_rect_.x = step * (i % numSteps);
|
||||
load_rect_.y = line_index_[load_counter_];
|
||||
mono_loading_screen_sprite_->setClip(load_rect_);
|
||||
mono_loading_screen_sprite_->setPosition(load_rect_);
|
||||
mono_loading_screen_sprite_->render();
|
||||
}
|
||||
}
|
||||
// Segunda parte de la carga, la parte de los bloques en color
|
||||
else
|
||||
{
|
||||
for (int i = 0; i <= load_counter_; i++)
|
||||
{
|
||||
load_rect_.x = (i * 8) % 256;
|
||||
load_rect_.y = (i / 32) * 8;
|
||||
color_loading_screen_sprite_->setClip(load_rect_);
|
||||
color_loading_screen_sprite_->setPosition(load_rect_);
|
||||
color_loading_screen_sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen_->render();
|
||||
}
|
||||
|
||||
// Dibuja sobre la textura
|
||||
void LoadingScreen::fillTexture()
|
||||
{
|
||||
// Empieza a dibujar en la textura
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
|
||||
// Dibuja la pantalla de carga
|
||||
renderLoad();
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Limpia la textura
|
||||
void LoadingScreen::clearTexture()
|
||||
{
|
||||
// Empieza a dibujar en la textura
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
|
||||
// Limpia
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
Reference in New Issue
Block a user