forked from jaildesigner-jailgames/jaildoctors_dilemma
Empezando a trabajar en el titulo
This commit is contained in:
BIN
media/title/loading_screeen1.png
Normal file
BIN
media/title/loading_screeen1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
BIN
media/title/loading_screeen2.png
Normal file
BIN
media/title/loading_screeen2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
@@ -194,6 +194,9 @@ bool Director::setFileList()
|
|||||||
asset->add("/media/logo/since_1998.png", bitmap);
|
asset->add("/media/logo/since_1998.png", bitmap);
|
||||||
asset->add("/media/logo/seagull.png", bitmap);
|
asset->add("/media/logo/seagull.png", bitmap);
|
||||||
|
|
||||||
|
asset->add("/media/title/loading_screen1.png", bitmap);
|
||||||
|
asset->add("/media/title/loading_screen2.png", bitmap);
|
||||||
|
|
||||||
return asset->check();
|
return asset->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "menu.h"
|
|
||||||
|
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "menu.h"
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
|||||||
267
source/title.cpp
Normal file
267
source/title.cpp
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
#include "title.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||||
|
{
|
||||||
|
// Copia la dirección de los objetos
|
||||||
|
this->renderer = renderer;
|
||||||
|
this->screen = screen;
|
||||||
|
this->asset = asset;
|
||||||
|
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
eventHandler = new SDL_Event();
|
||||||
|
texture = new LTexture(renderer, asset->get("jailgames.png"));
|
||||||
|
texture2 = new LTexture(renderer, asset->get("since_1998.png"));
|
||||||
|
sprite2 = new Sprite((256 - texture2->getWidth()) / 2, 83 + texture->getHeight() + 5, texture2->getWidth(), texture2->getHeight(), texture2, renderer);
|
||||||
|
sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight());
|
||||||
|
texture2->setColor(0, 0, 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < texture->getHeight(); i++)
|
||||||
|
{
|
||||||
|
sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer));
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
sprite[i]->setPosX(256 + (i * 3));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprite[i]->setPosX(-181 - (i * 3));
|
||||||
|
}
|
||||||
|
sprite[i]->setPosY(83 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
counter = 0;
|
||||||
|
section.name = SECTION_PROG_LOGO;
|
||||||
|
section.subsection = 0;
|
||||||
|
ticks = 0;
|
||||||
|
ticksSpeed = 15;
|
||||||
|
initFade = 300;
|
||||||
|
endLogo = 400;
|
||||||
|
postLogo = 20;
|
||||||
|
|
||||||
|
color_t c = stringToColor("black");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("blue");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("red");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("purple");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("green");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("cyan");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("yellow");
|
||||||
|
color.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("light_white");
|
||||||
|
color.push_back(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Title::~Title()
|
||||||
|
{
|
||||||
|
delete texture;
|
||||||
|
delete texture2;
|
||||||
|
|
||||||
|
for (auto s : sprite)
|
||||||
|
{
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete sprite2;
|
||||||
|
delete eventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
void Title::checkEventHandler()
|
||||||
|
{
|
||||||
|
// Comprueba los eventos que hay en la cola
|
||||||
|
while (SDL_PollEvent(eventHandler) != 0)
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (eventHandler->type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cualquier tecla pulsada
|
||||||
|
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_GAME;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void Title::update()
|
||||||
|
{
|
||||||
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
checkEventHandler();
|
||||||
|
|
||||||
|
// Incrementa el contador
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
// update de JAILGAMES
|
||||||
|
if (counter > 30)
|
||||||
|
{
|
||||||
|
for (int i = 1; i < sprite.size(); i++)
|
||||||
|
{
|
||||||
|
const int speed = 8;
|
||||||
|
const int dest = 37;
|
||||||
|
if (sprite[i]->getPosX() != 37)
|
||||||
|
{
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
sprite[i]->incPosX(-speed);
|
||||||
|
if (sprite[i]->getPosX() < dest)
|
||||||
|
{
|
||||||
|
sprite[i]->setPosX(dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprite[i]->incPosX(speed);
|
||||||
|
if (sprite[i]->getPosX() > dest)
|
||||||
|
{
|
||||||
|
sprite[i]->setPosX(dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update de fade
|
||||||
|
{
|
||||||
|
const int ini = 70;
|
||||||
|
const int inc = 4;
|
||||||
|
|
||||||
|
if (counter == ini + inc * 0)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[0].r, color[0].g, color[0].b);
|
||||||
|
}
|
||||||
|
else if (counter == ini + inc * 1)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[1].r, color[1].g, color[1].b);
|
||||||
|
}
|
||||||
|
else if (counter == ini + inc * 2)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[2].r, color[2].g, color[2].b);
|
||||||
|
}
|
||||||
|
else if (counter == ini + inc * 3)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[3].r, color[3].g, color[3].b);
|
||||||
|
}
|
||||||
|
else if (counter == ini + inc * 4)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[4].r, color[4].g, color[4].b);
|
||||||
|
}
|
||||||
|
else if (counter == ini + inc * 5)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[5].r, color[5].g, color[5].b);
|
||||||
|
}
|
||||||
|
else if (counter == ini + inc * 6)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[6].r, color[6].g, color[6].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter == ini + inc * 7)
|
||||||
|
{
|
||||||
|
texture2->setColor(color[7].r, color[7].g, color[7].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter == initFade + inc * 0)
|
||||||
|
{
|
||||||
|
texture->setColor(color[6].r, color[6].g, color[6].b);
|
||||||
|
texture2->setColor(color[6].r, color[6].g, color[6].b);
|
||||||
|
}
|
||||||
|
else if (counter == initFade + inc * 1)
|
||||||
|
{
|
||||||
|
texture->setColor(color[5].r, color[5].g, color[5].b);
|
||||||
|
texture2->setColor(color[5].r, color[5].g, color[5].b);
|
||||||
|
}
|
||||||
|
else if (counter == initFade + inc * 2)
|
||||||
|
{
|
||||||
|
texture->setColor(color[4].r, color[4].g, color[4].b);
|
||||||
|
texture2->setColor(color[4].r, color[4].g, color[4].b);
|
||||||
|
}
|
||||||
|
else if (counter == initFade + inc * 3)
|
||||||
|
{
|
||||||
|
texture->setColor(color[3].r, color[3].g, color[3].b);
|
||||||
|
texture2->setColor(color[3].r, color[3].g, color[3].b);
|
||||||
|
}
|
||||||
|
else if (counter == initFade + inc * 4)
|
||||||
|
{
|
||||||
|
texture->setColor(color[2].r, color[2].g, color[2].b);
|
||||||
|
texture2->setColor(color[2].r, color[2].g, color[2].b);
|
||||||
|
}
|
||||||
|
else if (counter == initFade + inc * 5)
|
||||||
|
{
|
||||||
|
texture->setColor(color[1].r, color[1].g, color[1].b);
|
||||||
|
texture2->setColor(color[1].r, color[1].g, color[1].b);
|
||||||
|
}
|
||||||
|
else if (counter == initFade + inc * 6)
|
||||||
|
{
|
||||||
|
texture->setColor(color[0].r, color[0].g, color[0].b);
|
||||||
|
texture2->setColor(color[0].r, color[0].g, color[0].b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el logo
|
||||||
|
if (counter == endLogo + postLogo)
|
||||||
|
{
|
||||||
|
section.name = SECTION_PROG_QUIT;
|
||||||
|
section.subsection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void Title::render()
|
||||||
|
{
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
screen->clean();
|
||||||
|
|
||||||
|
// Dibuja los objetos
|
||||||
|
for (auto s : sprite)
|
||||||
|
{
|
||||||
|
s->render();
|
||||||
|
}
|
||||||
|
sprite2->render();
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen->blit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle para el logo del juego
|
||||||
|
section_t Title::run()
|
||||||
|
{
|
||||||
|
// Detiene la música
|
||||||
|
JA_StopMusic();
|
||||||
|
|
||||||
|
while (section.name == SECTION_PROG_LOGO)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
56
source/title.h
Normal file
56
source/title.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "const.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "asset.h"
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef TITLE_H
|
||||||
|
#define TITLE_H
|
||||||
|
|
||||||
|
// Clase Title
|
||||||
|
class Title
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
|
LTexture *texture; // Textura con los graficos "JAILGAMES"
|
||||||
|
LTexture *texture2; // Textura con los graficos "Since 1998"
|
||||||
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
|
std::vector<Sprite *> sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
|
Sprite *sprite2; // Sprite para manejar la textura2
|
||||||
|
std::vector<color_t> color; // Vector con los colores para el fade
|
||||||
|
int counter; // Contador
|
||||||
|
section_t section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
int initFade; // Tiempo del contador cuando inicia el fade a negro
|
||||||
|
int endLogo; // Tiempo del contador para terminar el logo
|
||||||
|
int postLogo; // Tiempo que dura el logo con el fade al maximo
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
void checkEventHandler();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Title(SDL_Renderer *renderer, Screen *screen, Asset *asset);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Title();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
section_t run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user