Compare commits
6 Commits
96d19599cd
...
50078084ab
| Author | SHA1 | Date | |
|---|---|---|---|
| 50078084ab | |||
| 832cd12d5f | |||
| 90bfd8349b | |||
| ab59604cff | |||
| 27294125fe | |||
| ee174762e6 |
Binary file not shown.
|
Before Width: | Height: | Size: 67 KiB |
@@ -20,9 +20,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
borderHeight = options->video.border.height * 2;
|
borderHeight = options->video.border.height * 2;
|
||||||
dest = {0, 0, 0, 0};
|
dest = {0, 0, 0, 0};
|
||||||
borderColor = {0, 0, 0};
|
borderColor = {0, 0, 0};
|
||||||
fade = 0;
|
fade.enabled = false;
|
||||||
fadeCounter = 0;
|
fade.counter = 0;
|
||||||
fadeLenght = 0;
|
fade.lenght = 0;
|
||||||
|
fade.color = {0xFF, 0xFF, 0xFF};
|
||||||
|
flash.enabled = false;
|
||||||
|
flash.counter = 0;
|
||||||
|
flash.lenght = 0;
|
||||||
|
flash.color = {0xFF, 0xFF, 0xFF};
|
||||||
shake.desp = 1;
|
shake.desp = 1;
|
||||||
shake.delay = 3;
|
shake.delay = 3;
|
||||||
shake.counter = 0;
|
shake.counter = 0;
|
||||||
@@ -64,6 +69,9 @@ void Screen::start()
|
|||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::blit()
|
void Screen::blit()
|
||||||
{
|
{
|
||||||
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
|
doFlash();
|
||||||
|
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
@@ -241,13 +249,13 @@ void Screen::switchBorder()
|
|||||||
// Activa el fade
|
// Activa el fade
|
||||||
void Screen::setFade()
|
void Screen::setFade()
|
||||||
{
|
{
|
||||||
fade = true;
|
fade.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado el fade
|
// Comprueba si ha terminado el fade
|
||||||
bool Screen::fadeEnded()
|
bool Screen::fadeEnded()
|
||||||
{
|
{
|
||||||
if (fade || fadeCounter > 0)
|
if (fade.enabled || fade.counter > 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -258,21 +266,21 @@ bool Screen::fadeEnded()
|
|||||||
// Inicializa las variables para el fade
|
// Inicializa las variables para el fade
|
||||||
void Screen::iniFade()
|
void Screen::iniFade()
|
||||||
{
|
{
|
||||||
fade = false;
|
fade.enabled = false;
|
||||||
fadeCounter = 0;
|
fade.counter = 0;
|
||||||
fadeLenght = 200;
|
fade.lenght = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el fade
|
// Actualiza el fade
|
||||||
void Screen::updateFade()
|
void Screen::updateFade()
|
||||||
{
|
{
|
||||||
if (!fade)
|
if (!fade.enabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fadeCounter++;
|
fade.counter++;
|
||||||
if (fadeCounter > fadeLenght)
|
if (fade.counter > fade.lenght)
|
||||||
{
|
{
|
||||||
iniFade();
|
iniFade();
|
||||||
}
|
}
|
||||||
@@ -281,14 +289,14 @@ void Screen::updateFade()
|
|||||||
// Dibuja el fade
|
// Dibuja el fade
|
||||||
void Screen::renderFade()
|
void Screen::renderFade()
|
||||||
{
|
{
|
||||||
if (!fade)
|
if (!fade.enabled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||||
color_t color = {0, 0, 0};
|
color_t color = {0, 0, 0};
|
||||||
const float step = (float)fadeCounter / (float)fadeLenght;
|
const float step = (float)fade.counter / (float)fade.lenght;
|
||||||
const int alpha = 0 + (255 - 0) * step;
|
const int alpha = 0 + (255 - 0) * step;
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
@@ -310,10 +318,11 @@ void Screen::renderFX()
|
|||||||
void Screen::update()
|
void Screen::update()
|
||||||
{
|
{
|
||||||
updateShake();
|
updateShake();
|
||||||
|
// updateFlash();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void Screen::startShake()
|
void Screen::setShake()
|
||||||
{
|
{
|
||||||
shake.remaining = shake.lenght;
|
shake.remaining = shake.lenght;
|
||||||
shake.counter = shake.delay;
|
shake.counter = shake.delay;
|
||||||
@@ -341,4 +350,37 @@ void Screen::updateShake()
|
|||||||
{
|
{
|
||||||
dest.x = shake.origin;
|
dest.x = shake.origin;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone la pantalla de color
|
||||||
|
void Screen::setFlash(color_t color, int lenght)
|
||||||
|
{
|
||||||
|
flash.enabled = true;
|
||||||
|
flash.counter = 0;
|
||||||
|
flash.lenght = lenght;
|
||||||
|
flash.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
|
void Screen::doFlash()
|
||||||
|
{
|
||||||
|
if (flash.enabled)
|
||||||
|
{
|
||||||
|
// Dibuja el color del flash en la textura
|
||||||
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||||
|
SDL_SetRenderTarget(renderer, gameCanvas);
|
||||||
|
SDL_SetRenderDrawColor(renderer, flash.color.r, flash.color.g, flash.color.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
|
|
||||||
|
// Actualiza la lógica del efecto
|
||||||
|
if (flash.counter < flash.lenght)
|
||||||
|
{
|
||||||
|
flash.counter++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flash.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,10 +32,17 @@ private:
|
|||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
|
|
||||||
|
struct effect_t
|
||||||
|
{
|
||||||
|
bool enabled; // Indica si el efecto está activo
|
||||||
|
int counter; // Contador para el efecto
|
||||||
|
int lenght; // Duración del efecto
|
||||||
|
color_t color; // Color del efecto
|
||||||
|
};
|
||||||
|
|
||||||
// Variables - Efectos
|
// Variables - Efectos
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
effect_t fade; // Variable para gestionar el efecto de fade
|
||||||
int fadeCounter; // Temporizador para el efecto de fade
|
effect_t flash; // Variable para gestionar el efecto de flash
|
||||||
int fadeLenght; // Duración del fade
|
|
||||||
|
|
||||||
struct shake_t
|
struct shake_t
|
||||||
{
|
{
|
||||||
@@ -65,6 +72,9 @@ private:
|
|||||||
// Actualiza la logica para agitar la pantalla
|
// Actualiza la logica para agitar la pantalla
|
||||||
void updateShake();
|
void updateShake();
|
||||||
|
|
||||||
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
|
void doFlash();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||||
@@ -122,7 +132,10 @@ public:
|
|||||||
bool fadeEnded();
|
bool fadeEnded();
|
||||||
|
|
||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void startShake();
|
void setShake();
|
||||||
|
|
||||||
|
// Pone la pantalla de color
|
||||||
|
void setFlash(color_t color, int lenght);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
|||||||
#define SUBSECTION_GAME_GAMEOVER 3
|
#define SUBSECTION_GAME_GAMEOVER 3
|
||||||
#define SUBSECTION_TITLE_1 3
|
#define SUBSECTION_TITLE_1 3
|
||||||
#define SUBSECTION_TITLE_2 4
|
#define SUBSECTION_TITLE_2 4
|
||||||
#define SUBSECTION_TITLE_3 5
|
#define SUBSECTION_TITLE_INSTRUCTIONS 5
|
||||||
#define SUBSECTION_TITLE_INSTRUCTIONS 6
|
|
||||||
|
|
||||||
// Ningun tipo
|
// Ningun tipo
|
||||||
#define NO_KIND 0
|
#define NO_KIND 0
|
||||||
|
|||||||
@@ -309,7 +309,6 @@ bool Director::setFileList()
|
|||||||
asset->add(prefix + "/data/gfx/title_crisis.png", t_bitmap);
|
asset->add(prefix + "/data/gfx/title_crisis.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/title_dust.png", t_bitmap);
|
asset->add(prefix + "/data/gfx/title_dust.png", t_bitmap);
|
||||||
asset->add(prefix + "/data/gfx/title_dust.ani", t_data);
|
asset->add(prefix + "/data/gfx/title_dust.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/title_gradient.png", t_bitmap);
|
|
||||||
|
|
||||||
asset->add(prefix + "/data/gfx/player_head.ani", t_data);
|
asset->add(prefix + "/data/gfx/player_head.ani", t_data);
|
||||||
asset->add(prefix + "/data/gfx/player_body.ani", t_data);
|
asset->add(prefix + "/data/gfx/player_body.ani", t_data);
|
||||||
|
|||||||
@@ -3057,7 +3057,7 @@ void Game::disableTimeStopItem()
|
|||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void Game::shakeScreen()
|
void Game::shakeScreen()
|
||||||
{
|
{
|
||||||
screen->startShake();
|
screen->setShake();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
|
|||||||
209
source/game_logo.cpp
Normal file
209
source/game_logo.cpp
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
#include "game_logo.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
GameLogo::GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y)
|
||||||
|
{
|
||||||
|
// Copia los punteros
|
||||||
|
this->renderer = renderer;
|
||||||
|
this->screen = screen;
|
||||||
|
this->asset = asset;
|
||||||
|
this->x = x;
|
||||||
|
this->y = y;
|
||||||
|
|
||||||
|
// Crea los objetos
|
||||||
|
dustTexture = new Texture(renderer, asset->get("title_dust.png"));
|
||||||
|
coffeeTexture = new Texture(renderer, asset->get("title_coffee.png"));
|
||||||
|
crisisTexture = new Texture(renderer, asset->get("title_crisis.png"));
|
||||||
|
|
||||||
|
coffeeBitmap = new SmartSprite(coffeeTexture, renderer);
|
||||||
|
crisisBitmap = new SmartSprite(crisisTexture, renderer);
|
||||||
|
dustBitmapL = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani"));
|
||||||
|
dustBitmapR = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani"));
|
||||||
|
|
||||||
|
// Sonidos
|
||||||
|
crashSound = JA_LoadSound(asset->get("title.wav").c_str());
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
GameLogo::~GameLogo()
|
||||||
|
{
|
||||||
|
dustTexture->unload();
|
||||||
|
delete dustTexture;
|
||||||
|
|
||||||
|
coffeeTexture->unload();
|
||||||
|
delete coffeeTexture;
|
||||||
|
|
||||||
|
crisisTexture->unload();
|
||||||
|
delete crisisTexture;
|
||||||
|
|
||||||
|
delete coffeeBitmap;
|
||||||
|
delete crisisBitmap;
|
||||||
|
delete dustBitmapL;
|
||||||
|
delete dustBitmapR;
|
||||||
|
|
||||||
|
JA_DeleteSound(crashSound);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void GameLogo::init()
|
||||||
|
{
|
||||||
|
const int xp = x - coffeeBitmap->getWidth() / 2;
|
||||||
|
const int desp = getInitialVerticalDesp();
|
||||||
|
// Variables
|
||||||
|
status = disabled;
|
||||||
|
shake.desp = 1;
|
||||||
|
shake.delay = 3;
|
||||||
|
shake.lenght = 8;
|
||||||
|
shake.remaining = shake.lenght;
|
||||||
|
shake.counter = shake.delay;
|
||||||
|
shake.origin = xp;
|
||||||
|
|
||||||
|
// Inicializa el bitmap de 'Coffee'
|
||||||
|
coffeeBitmap->init();
|
||||||
|
coffeeBitmap->setPosX(xp);
|
||||||
|
coffeeBitmap->setPosY(y - coffeeBitmap->getHeight() - desp);
|
||||||
|
coffeeBitmap->setWidth(167);
|
||||||
|
coffeeBitmap->setHeight(46);
|
||||||
|
coffeeBitmap->setVelX(0.0f);
|
||||||
|
coffeeBitmap->setVelY(2.5f);
|
||||||
|
coffeeBitmap->setAccelX(0.0f);
|
||||||
|
coffeeBitmap->setAccelY(0.1f);
|
||||||
|
coffeeBitmap->setSpriteClip(0, 0, 167, 46);
|
||||||
|
coffeeBitmap->setEnabled(true);
|
||||||
|
coffeeBitmap->setEnabledCounter(0);
|
||||||
|
coffeeBitmap->setDestX(xp);
|
||||||
|
coffeeBitmap->setDestY(y - coffeeBitmap->getHeight());
|
||||||
|
|
||||||
|
// Inicializa el bitmap de 'Crisis'
|
||||||
|
crisisBitmap->init();
|
||||||
|
crisisBitmap->setPosX(xp + 15);
|
||||||
|
crisisBitmap->setPosY(y + desp);
|
||||||
|
crisisBitmap->setWidth(137);
|
||||||
|
crisisBitmap->setHeight(46);
|
||||||
|
crisisBitmap->setVelX(0.0f);
|
||||||
|
crisisBitmap->setVelY(-2.5f);
|
||||||
|
crisisBitmap->setAccelX(0.0f);
|
||||||
|
crisisBitmap->setAccelY(-0.1f);
|
||||||
|
crisisBitmap->setSpriteClip(0, 0, 137, 46);
|
||||||
|
crisisBitmap->setEnabled(true);
|
||||||
|
crisisBitmap->setEnabledCounter(0);
|
||||||
|
crisisBitmap->setDestX(xp + 15);
|
||||||
|
crisisBitmap->setDestY(y);
|
||||||
|
|
||||||
|
// Inicializa el bitmap de 'DustRight'
|
||||||
|
dustBitmapR->resetAnimation();
|
||||||
|
dustBitmapR->setPosX(coffeeBitmap->getPosX() + coffeeBitmap->getWidth());
|
||||||
|
dustBitmapR->setPosY(y);
|
||||||
|
dustBitmapR->setWidth(16);
|
||||||
|
dustBitmapR->setHeight(16);
|
||||||
|
dustBitmapR->setFlip(SDL_FLIP_HORIZONTAL);
|
||||||
|
|
||||||
|
// Inicializa el bitmap de 'DustLeft'
|
||||||
|
dustBitmapL->resetAnimation();
|
||||||
|
dustBitmapL->setPosX(coffeeBitmap->getPosX() - 16);
|
||||||
|
dustBitmapL->setPosY(y);
|
||||||
|
dustBitmapL->setWidth(16);
|
||||||
|
dustBitmapL->setHeight(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta la clase en pantalla
|
||||||
|
void GameLogo::render()
|
||||||
|
{
|
||||||
|
// Dibuja el logo
|
||||||
|
coffeeBitmap->render();
|
||||||
|
crisisBitmap->render();
|
||||||
|
|
||||||
|
// Dibuja el polvillo del logo
|
||||||
|
dustBitmapR->render();
|
||||||
|
dustBitmapL->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void GameLogo::update()
|
||||||
|
{
|
||||||
|
if (status == moving)
|
||||||
|
{
|
||||||
|
coffeeBitmap->update();
|
||||||
|
crisisBitmap->update();
|
||||||
|
|
||||||
|
// Si los objetos han llegado a su destino, cambiamos de Sección
|
||||||
|
if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished())
|
||||||
|
{
|
||||||
|
status = shaking;
|
||||||
|
|
||||||
|
// Pantallazo blanco
|
||||||
|
screen->setFlash({0xFF, 0xFF, 0xFF}, 5);
|
||||||
|
|
||||||
|
// Reproduce el efecto sonoro
|
||||||
|
JA_PlaySound(crashSound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (status == shaking)
|
||||||
|
{
|
||||||
|
// Agita el logo
|
||||||
|
if (shake.remaining > 0)
|
||||||
|
{
|
||||||
|
if (shake.counter > 0)
|
||||||
|
{
|
||||||
|
shake.counter--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shake.counter = shake.delay;
|
||||||
|
const int desp = shake.remaining % 2 == 0 ? shake.desp * (-1) : shake.desp;
|
||||||
|
coffeeBitmap->setPosX(shake.origin + desp);
|
||||||
|
crisisBitmap->setPosX(shake.origin + desp + 15);
|
||||||
|
shake.remaining--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
coffeeBitmap->setPosX(shake.origin);
|
||||||
|
crisisBitmap->setPosX(shake.origin + 15);
|
||||||
|
status = finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
dustBitmapR->update();
|
||||||
|
dustBitmapL->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (status == finished)
|
||||||
|
{
|
||||||
|
dustBitmapR->update();
|
||||||
|
dustBitmapL->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa la clase
|
||||||
|
void GameLogo::enable()
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
status = moving;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si ha terminado la animación
|
||||||
|
bool GameLogo::hasFinished()
|
||||||
|
{
|
||||||
|
return (status == finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recarga las texturas
|
||||||
|
void GameLogo::reLoad()
|
||||||
|
{
|
||||||
|
dustTexture->reLoad();
|
||||||
|
coffeeTexture->reLoad();
|
||||||
|
crisisTexture->reLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcula el desplazamiento vertical inicial
|
||||||
|
int GameLogo::getInitialVerticalDesp()
|
||||||
|
{
|
||||||
|
int despUp = y;
|
||||||
|
int despDown = GAMECANVAS_HEIGHT - y;
|
||||||
|
|
||||||
|
return std::max(despUp, despDown);
|
||||||
|
}
|
||||||
84
source/game_logo.h
Normal file
84
source/game_logo.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "common/asset.h"
|
||||||
|
#include "common/screen.h"
|
||||||
|
#include "common/smartsprite.h"
|
||||||
|
#include "common/jail_audio.h"
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
|
#ifndef GAME_LOGO_H
|
||||||
|
#define GAME_LOGO_H
|
||||||
|
|
||||||
|
// Clase GameLogo
|
||||||
|
class GameLogo
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// Objetos y punteros
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
|
||||||
|
Texture *dustTexture; // Textura con los graficos del polvo
|
||||||
|
Texture *coffeeTexture; // Textura con los graficos de la palabra coffee
|
||||||
|
Texture *crisisTexture; // Textura con los graficos de la plabra crisis
|
||||||
|
|
||||||
|
AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||||
|
AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
||||||
|
|
||||||
|
SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
|
||||||
|
SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
int x; // Posición donde ddibujar a la clase
|
||||||
|
int y; // Posición donde ddibujar a la clase
|
||||||
|
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
||||||
|
|
||||||
|
enum status_e
|
||||||
|
{
|
||||||
|
disabled,
|
||||||
|
moving,
|
||||||
|
shaking,
|
||||||
|
finished
|
||||||
|
} status; // Estado en el que se encuentra la clase
|
||||||
|
|
||||||
|
struct shake_t
|
||||||
|
{
|
||||||
|
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||||
|
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||||
|
int counter; // Contador para el retraso
|
||||||
|
int lenght; // Cantidad de desplazamientos a realizar
|
||||||
|
int remaining; // Cantidad de desplazamientos pendientes a realizar
|
||||||
|
int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||||
|
} shake; // Estructura para generar el efecto de agitación
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Calcula el desplazamiento vertical inicial
|
||||||
|
int getInitialVerticalDesp();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
GameLogo(SDL_Renderer *renderer, Screen *screen, Asset *asset, int x, int y);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~GameLogo();
|
||||||
|
|
||||||
|
// Pinta la clase en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Activa la clase
|
||||||
|
void enable();
|
||||||
|
|
||||||
|
// Indica si ha terminado la animación
|
||||||
|
bool hasFinished();
|
||||||
|
|
||||||
|
// Recarga las texturas
|
||||||
|
void reLoad();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -80,7 +80,7 @@ void HiScoreTable::update()
|
|||||||
if (manualQuit)
|
if (manualQuit)
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
section->subsection = SUBSECTION_TITLE_2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ void Instructions::update()
|
|||||||
if (manualQuit)
|
if (manualQuit)
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_TITLE;
|
section->name = SECTION_PROG_TITLE;
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
section->subsection = SUBSECTION_TITLE_2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
110
source/tiledbg.cpp
Normal file
110
source/tiledbg.cpp
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#include "tiledbg.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Tiledbg::Tiledbg(SDL_Renderer *renderer, Screen *screen, Asset *asset, SDL_Rect pos)
|
||||||
|
{
|
||||||
|
// Copia los punteros
|
||||||
|
this->renderer = renderer;
|
||||||
|
this->screen = screen;
|
||||||
|
this->asset = asset;
|
||||||
|
this->pos = pos;
|
||||||
|
|
||||||
|
// Crea la textura para el mosaico de fondo
|
||||||
|
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, pos.w * 2, pos.h * 2);
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Tiledbg::~Tiledbg()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void Tiledbg::init()
|
||||||
|
{
|
||||||
|
counter = 0;
|
||||||
|
mode = rand() % 2;
|
||||||
|
tileWidth = 64;
|
||||||
|
tileHeight = 64;
|
||||||
|
|
||||||
|
// Rellena la textura con el contenido
|
||||||
|
fillTexture();
|
||||||
|
|
||||||
|
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida
|
||||||
|
// con el mosaico que hay pintado en el titulo al iniciar
|
||||||
|
window.x = 128;
|
||||||
|
window.y = 96;
|
||||||
|
window.w = pos.w;
|
||||||
|
window.h = pos.h;
|
||||||
|
|
||||||
|
// Inicializa los valores del vector con los valores del seno
|
||||||
|
for (int i = 0; i < 360; ++i)
|
||||||
|
{
|
||||||
|
sin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rellena la textura con el contenido
|
||||||
|
void Tiledbg::fillTexture()
|
||||||
|
{
|
||||||
|
// Crea los objetos para pintar en la textura de fondo
|
||||||
|
Texture *bgTileTexture = new Texture(renderer, asset->get("title_bg_tile.png"));
|
||||||
|
Sprite *tile = new Sprite({0, 0, tileWidth, tileHeight}, bgTileTexture, renderer);
|
||||||
|
|
||||||
|
// Prepara para dibujar sobre la textura
|
||||||
|
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||||
|
SDL_SetRenderTarget(renderer, canvas);
|
||||||
|
|
||||||
|
// Rellena la textura con el tile
|
||||||
|
const int iMax = pos.w * 2 / tileWidth;
|
||||||
|
const int jMax = pos.h * 2 / tileHeight;
|
||||||
|
tile->setSpriteClip(0, 0, tileWidth, tileHeight);
|
||||||
|
for (int i = 0; i < iMax; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < jMax; ++j)
|
||||||
|
{
|
||||||
|
tile->setPosX(i * tileWidth);
|
||||||
|
tile->setPosY(j * tileHeight);
|
||||||
|
tile->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelve a colocar el renderizador como estaba
|
||||||
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
|
|
||||||
|
// Libera la memoria utilizada por los objetos
|
||||||
|
bgTileTexture->unload();
|
||||||
|
delete bgTileTexture;
|
||||||
|
delete tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta la clase en pantalla
|
||||||
|
void Tiledbg::render()
|
||||||
|
{
|
||||||
|
SDL_RenderCopy(renderer, canvas, &window, &pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void Tiledbg::update()
|
||||||
|
{
|
||||||
|
if (mode == 0)
|
||||||
|
{ // El tileado de fondo se desplaza en diagonal
|
||||||
|
++window.x %= tileWidth;
|
||||||
|
++window.y %= tileHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // El tileado de fondo se desplaza en circulo
|
||||||
|
++counter %= 360;
|
||||||
|
window.x = 128 + (int(sin[(counter + 270) % 360] * 128));
|
||||||
|
window.y = 96 + (int(sin[(360 - counter) % 360] * 96));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recarga las texturas
|
||||||
|
void Tiledbg::reLoad()
|
||||||
|
{
|
||||||
|
fillTexture();
|
||||||
|
}
|
||||||
54
source/tiledbg.h
Normal file
54
source/tiledbg.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "common/asset.h"
|
||||||
|
#include "common/screen.h"
|
||||||
|
#include "common/sprite.h"
|
||||||
|
#include "const.h"
|
||||||
|
|
||||||
|
#ifndef TILEDBG_H
|
||||||
|
#define TILEDBG_H
|
||||||
|
|
||||||
|
// Clase Tiledbg
|
||||||
|
class Tiledbg
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// Objetos y punteros
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
|
SDL_Rect window; // Ventana visible para la textura de fondo del titulo
|
||||||
|
SDL_Texture *canvas; // Textura dibujar el fondo del titulo
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
SDL_Rect pos; // Posición y tamaña del mosaico
|
||||||
|
int counter; // Contador
|
||||||
|
Uint8 mode; // Tipo de movimiento del mosaico
|
||||||
|
float sin[360]; // Vector con los valores del seno precalculados
|
||||||
|
int tileWidth; // Ancho del tile
|
||||||
|
int tileHeight; // Alto del tile
|
||||||
|
|
||||||
|
// Inicializa las variables
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Rellena la textura con el contenido
|
||||||
|
void fillTexture();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Tiledbg(SDL_Renderer *renderer, Screen *screen, Asset *asset, SDL_Rect pos);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Tiledbg();
|
||||||
|
|
||||||
|
// Pinta la clase en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Recarga las texturas
|
||||||
|
void reLoad();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
394
source/title.cpp
394
source/title.cpp
@@ -3,7 +3,7 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
|
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
|
||||||
{
|
{
|
||||||
// Copia las direcciones de los punteros
|
// Copia las direcciones de los punteros y objetos
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->screen = screen;
|
this->screen = screen;
|
||||||
this->input = input;
|
this->input = input;
|
||||||
@@ -12,21 +12,10 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
|
|||||||
this->lang = lang;
|
this->lang = lang;
|
||||||
this->section = section;
|
this->section = section;
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria y crea los objetos
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
fade = new Fade(renderer);
|
fade = new Fade(renderer);
|
||||||
|
|
||||||
dustTexture = new Texture(renderer, asset->get("title_dust.png"));
|
|
||||||
coffeeTexture = new Texture(renderer, asset->get("title_coffee.png"));
|
|
||||||
crisisTexture = new Texture(renderer, asset->get("title_crisis.png"));
|
|
||||||
gradientTexture = new Texture(renderer, asset->get("title_gradient.png"));
|
|
||||||
|
|
||||||
coffeeBitmap = new SmartSprite(coffeeTexture, renderer);
|
|
||||||
crisisBitmap = new SmartSprite(crisisTexture, renderer);
|
|
||||||
dustBitmapL = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani"));
|
|
||||||
dustBitmapR = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani"));
|
|
||||||
gradient = new Sprite({0, 0, 256, 192}, gradientTexture, renderer);
|
|
||||||
|
|
||||||
text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||||
text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||||
|
|
||||||
@@ -37,8 +26,10 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
|
|||||||
backgroundObj->setGradientNumber(1);
|
backgroundObj->setGradientNumber(1);
|
||||||
backgroundObj->setTransition(0.8f);
|
backgroundObj->setTransition(0.8f);
|
||||||
|
|
||||||
// Sonidos
|
tiledbg = new Tiledbg(renderer, screen, asset, {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT});
|
||||||
crashSound = JA_LoadSound(asset->get("title.wav").c_str());
|
|
||||||
|
gameLogo = new GameLogo(renderer, screen, asset, GAMECANVAS_CENTER_X, GAMECANVAS_FIRST_QUARTER_Y + 20);
|
||||||
|
gameLogo->enable();
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
titleMusic = JA_LoadMusic(asset->get("title.ogg").c_str());
|
titleMusic = JA_LoadMusic(asset->get("title.ogg").c_str());
|
||||||
@@ -50,47 +41,26 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
|
|||||||
// Destructor
|
// Destructor
|
||||||
Title::~Title()
|
Title::~Title()
|
||||||
{
|
{
|
||||||
|
// Destruye los objetos y libera la memoria
|
||||||
delete eventHandler;
|
delete eventHandler;
|
||||||
delete fade;
|
delete fade;
|
||||||
|
|
||||||
dustTexture->unload();
|
|
||||||
delete dustTexture;
|
|
||||||
|
|
||||||
coffeeTexture->unload();
|
|
||||||
delete coffeeTexture;
|
|
||||||
|
|
||||||
crisisTexture->unload();
|
|
||||||
delete crisisTexture;
|
|
||||||
|
|
||||||
gradientTexture->unload();
|
|
||||||
delete gradientTexture;
|
|
||||||
|
|
||||||
delete coffeeBitmap;
|
|
||||||
delete crisisBitmap;
|
|
||||||
delete dustBitmapL;
|
|
||||||
delete dustBitmapR;
|
|
||||||
delete gradient;
|
|
||||||
|
|
||||||
delete text1;
|
delete text1;
|
||||||
delete text2;
|
delete text2;
|
||||||
|
|
||||||
delete backgroundObj;
|
delete backgroundObj;
|
||||||
|
delete tiledbg;
|
||||||
|
delete gameLogo;
|
||||||
|
|
||||||
JA_DeleteSound(crashSound);
|
|
||||||
JA_DeleteMusic(titleMusic);
|
JA_DeleteMusic(titleMusic);
|
||||||
|
|
||||||
SDL_DestroyTexture(background);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa los valores
|
// Inicializa los valores de las variables
|
||||||
void Title::init()
|
void Title::init()
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
section->subsection = SUBSECTION_TITLE_1;
|
section->subsection = SUBSECTION_TITLE_1;
|
||||||
counter = TITLE_COUNTER;
|
counter = TITLE_COUNTER;
|
||||||
backgroundCounter = 0;
|
|
||||||
backgroundMode = rand() % 2;
|
|
||||||
menuVisible = false;
|
|
||||||
nextSection.name = SECTION_PROG_GAME;
|
nextSection.name = SECTION_PROG_GAME;
|
||||||
postFade = 0;
|
postFade = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
@@ -127,148 +97,48 @@ void Title::init()
|
|||||||
options->input[1].name = availableInputDevices[deviceIndex[1]].name;
|
options->input[1].name = availableInputDevices[deviceIndex[1]].name;
|
||||||
options->input[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
|
options->input[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el bitmap de Coffee
|
|
||||||
coffeeBitmap->init();
|
|
||||||
coffeeBitmap->setPosX(45);
|
|
||||||
coffeeBitmap->setPosY(11 - 200);
|
|
||||||
coffeeBitmap->setWidth(167);
|
|
||||||
coffeeBitmap->setHeight(46);
|
|
||||||
coffeeBitmap->setVelX(0.0f);
|
|
||||||
coffeeBitmap->setVelY(2.5f);
|
|
||||||
coffeeBitmap->setAccelX(0.0f);
|
|
||||||
coffeeBitmap->setAccelY(0.1f);
|
|
||||||
coffeeBitmap->setSpriteClip(0, 0, 167, 46);
|
|
||||||
coffeeBitmap->setEnabled(true);
|
|
||||||
coffeeBitmap->setEnabledCounter(0);
|
|
||||||
coffeeBitmap->setDestX(45);
|
|
||||||
coffeeBitmap->setDestY(11);
|
|
||||||
|
|
||||||
// Inicializa el bitmap de Crisis
|
|
||||||
crisisBitmap->init();
|
|
||||||
crisisBitmap->setPosX(60);
|
|
||||||
crisisBitmap->setPosY(57 + 200);
|
|
||||||
crisisBitmap->setWidth(137);
|
|
||||||
crisisBitmap->setHeight(46);
|
|
||||||
crisisBitmap->setVelX(0.0f);
|
|
||||||
crisisBitmap->setVelY(-2.5f);
|
|
||||||
crisisBitmap->setAccelX(0.0f);
|
|
||||||
crisisBitmap->setAccelY(-0.1f);
|
|
||||||
crisisBitmap->setSpriteClip(0, 0, 137, 46);
|
|
||||||
crisisBitmap->setEnabled(true);
|
|
||||||
crisisBitmap->setEnabledCounter(0);
|
|
||||||
crisisBitmap->setDestX(60);
|
|
||||||
crisisBitmap->setDestY(57);
|
|
||||||
|
|
||||||
// Inicializa el bitmap de DustRight
|
|
||||||
dustBitmapR->resetAnimation();
|
|
||||||
dustBitmapR->setPosX(218);
|
|
||||||
dustBitmapR->setPosY(47);
|
|
||||||
dustBitmapR->setWidth(16);
|
|
||||||
dustBitmapR->setHeight(16);
|
|
||||||
dustBitmapR->setFlip(SDL_FLIP_HORIZONTAL);
|
|
||||||
|
|
||||||
// Inicializa el bitmap de DustLeft
|
|
||||||
dustBitmapL->resetAnimation();
|
|
||||||
dustBitmapL->setPosX(33);
|
|
||||||
dustBitmapL->setPosY(47);
|
|
||||||
dustBitmapL->setWidth(16);
|
|
||||||
dustBitmapL->setHeight(16);
|
|
||||||
|
|
||||||
// Inicializa el sprite con el degradado
|
|
||||||
gradient->setSpriteClip(0, 96, 256, 192);
|
|
||||||
|
|
||||||
// Crea el mosaico de fondo del titulo
|
|
||||||
createTiledBackground();
|
|
||||||
|
|
||||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar
|
|
||||||
backgroundWindow.x = 128;
|
|
||||||
backgroundWindow.y = 96;
|
|
||||||
backgroundWindow.w = GAMECANVAS_WIDTH;
|
|
||||||
backgroundWindow.h = GAMECANVAS_HEIGHT;
|
|
||||||
|
|
||||||
// Inicializa los valores del vector con los valores del seno
|
|
||||||
for (int i = 0; i < 360; ++i)
|
|
||||||
{
|
|
||||||
sin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Title::update()
|
void Title::update()
|
||||||
{
|
{
|
||||||
// Comprueba las entradas
|
|
||||||
checkInput();
|
|
||||||
|
|
||||||
// Calcula la lógica de los objetos
|
// Calcula la lógica de los objetos
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Actualiza el objeto 'background'
|
||||||
backgroundObj->update();
|
backgroundObj->update();
|
||||||
counter++;
|
|
||||||
|
|
||||||
switch (section->subsection)
|
// Sección 1 - Titulo animandose
|
||||||
|
if (section->subsection == SUBSECTION_TITLE_1)
|
||||||
{
|
{
|
||||||
// Sección 1 - Titulo desplazandose
|
gameLogo->update();
|
||||||
case SUBSECTION_TITLE_1:
|
if (gameLogo->hasFinished())
|
||||||
{
|
|
||||||
// Actualiza los objetos
|
|
||||||
coffeeBitmap->update();
|
|
||||||
crisisBitmap->update();
|
|
||||||
|
|
||||||
// Si los objetos han llegado a su destino, cambiamos de Sección
|
|
||||||
if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished())
|
|
||||||
{
|
{
|
||||||
section->subsection = SUBSECTION_TITLE_2;
|
section->subsection = SUBSECTION_TITLE_2;
|
||||||
|
|
||||||
// Pantallazo blanco
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
|
||||||
JA_PlaySound(crashSound);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
// Sección 2 - Titulo vibrando
|
// Sección 2 - La pantalla con el titulo, el fondo animado y la música
|
||||||
case SUBSECTION_TITLE_2:
|
else if (section->subsection == SUBSECTION_TITLE_2)
|
||||||
{
|
|
||||||
// Agita la pantalla
|
|
||||||
static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
|
|
||||||
static const int a = coffeeBitmap->getPosX();
|
|
||||||
static const int b = crisisBitmap->getPosX();
|
|
||||||
static int step = 0;
|
|
||||||
|
|
||||||
coffeeBitmap->setPosX(a + v[step / 3]);
|
|
||||||
crisisBitmap->setPosX(b + v[step / 3]);
|
|
||||||
dustBitmapR->update();
|
|
||||||
dustBitmapL->update();
|
|
||||||
|
|
||||||
step++;
|
|
||||||
|
|
||||||
if (step == 33)
|
|
||||||
{
|
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Sección 3 - La pantalla de titulo con el menú y la música
|
|
||||||
case SUBSECTION_TITLE_3:
|
|
||||||
{
|
{
|
||||||
if (counter > 0)
|
if (counter > 0)
|
||||||
{ // Reproduce la música
|
{
|
||||||
|
counter--;
|
||||||
|
|
||||||
|
// Reproduce la música
|
||||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||||
{
|
{
|
||||||
JA_PlayMusic(titleMusic);
|
JA_PlayMusic(titleMusic);
|
||||||
}
|
}
|
||||||
|
|
||||||
dustBitmapR->update();
|
// Actualiza el logo con el título del juego
|
||||||
dustBitmapL->update();
|
gameLogo->update();
|
||||||
|
|
||||||
|
// Actualiza el mosaico de fondo
|
||||||
|
tiledbg->update();
|
||||||
|
|
||||||
// Actualiza la lógica del titulo
|
// Actualiza la lógica del titulo
|
||||||
fade->update();
|
fade->update();
|
||||||
@@ -316,9 +186,6 @@ void Title::update()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el tileado de fondo
|
|
||||||
updateBG();
|
|
||||||
}
|
}
|
||||||
else if (counter == 0)
|
else if (counter == 0)
|
||||||
{
|
{
|
||||||
@@ -351,129 +218,39 @@ void Title::update()
|
|||||||
demo = true;
|
demo = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el objeto en pantalla
|
// Dibuja el objeto en pantalla
|
||||||
void Title::render()
|
void Title::render()
|
||||||
{
|
{
|
||||||
switch (section->subsection)
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen->start();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
screen->clean(bgColor);
|
||||||
|
|
||||||
|
// Dibuja el mosacico de fondo
|
||||||
|
tiledbg->render();
|
||||||
|
// backgroundObj->render();
|
||||||
|
|
||||||
|
// Dinuja el logo con el título del juego
|
||||||
|
gameLogo->render();
|
||||||
|
|
||||||
|
if (section->subsection == SUBSECTION_TITLE_2)
|
||||||
{
|
{
|
||||||
// Sección 1 - Titulo desplazandose
|
|
||||||
case SUBSECTION_TITLE_1:
|
|
||||||
{
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean(bgColor);
|
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
|
||||||
SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr);
|
|
||||||
backgroundObj->render();
|
|
||||||
|
|
||||||
// Dibuja el degradado
|
|
||||||
// gradient->render();
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
coffeeBitmap->render();
|
|
||||||
crisisBitmap->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Sección 2 - Titulo vibrando
|
|
||||||
case SUBSECTION_TITLE_2:
|
|
||||||
{ // Reproduce el efecto sonoro
|
|
||||||
JA_PlaySound(crashSound);
|
|
||||||
|
|
||||||
// Agita la pantalla
|
|
||||||
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
|
|
||||||
const int a = coffeeBitmap->getPosX();
|
|
||||||
const int b = crisisBitmap->getPosX();
|
|
||||||
for (int n = 0; n < 11 * 3; ++n)
|
|
||||||
{
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean(bgColor);
|
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
|
||||||
SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr);
|
|
||||||
backgroundObj->render();
|
|
||||||
|
|
||||||
// Dibuja el degradado
|
|
||||||
// gradient->render();
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
coffeeBitmap->setPosX(a + v[n / 3]);
|
|
||||||
crisisBitmap->setPosX(b + v[n / 3]);
|
|
||||||
coffeeBitmap->render();
|
|
||||||
crisisBitmap->render();
|
|
||||||
|
|
||||||
dustBitmapR->update();
|
|
||||||
dustBitmapL->update();
|
|
||||||
dustBitmapR->render();
|
|
||||||
dustBitmapL->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
|
|
||||||
section->subsection = SUBSECTION_TITLE_3;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Sección 3 - La pantalla de titulo con el menú y la música
|
|
||||||
case SUBSECTION_TITLE_3:
|
|
||||||
{ // Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean(bgColor);
|
|
||||||
|
|
||||||
// Dibuja el tileado de fondo
|
|
||||||
SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr);
|
|
||||||
backgroundObj->render();
|
|
||||||
|
|
||||||
// Dibuja el degradado
|
|
||||||
// gradient->render();
|
|
||||||
|
|
||||||
coffeeBitmap->render();
|
|
||||||
crisisBitmap->render();
|
|
||||||
|
|
||||||
// Dibuja el polvillo del título
|
|
||||||
dustBitmapR->render();
|
|
||||||
dustBitmapL->render();
|
|
||||||
|
|
||||||
// PRESS ANY KEY!
|
// PRESS ANY KEY!
|
||||||
//if ((counter % 50 > 14) && (menuVisible == false))
|
|
||||||
if (counter % 50 > 14)
|
if (counter % 50 > 14)
|
||||||
{
|
{
|
||||||
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_THIRD_QUARTER_Y + BLOCK, lang->getText(23), 1, noColor, 1, shdwTxtColor);
|
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_THIRD_QUARTER_Y + BLOCK, lang->getText(23), 1, noColor, 1, shdwTxtColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fade
|
|
||||||
fade->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
// Fade
|
||||||
break;
|
fade->render();
|
||||||
}
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos
|
// Comprueba los eventos
|
||||||
@@ -493,18 +270,6 @@ void Title::checkEvents()
|
|||||||
{
|
{
|
||||||
reLoadTextures();
|
reLoadTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section->subsection == SUBSECTION_TITLE_3)
|
|
||||||
{ // Si se pulsa alguna tecla durante la tercera sección del titulo
|
|
||||||
if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP))
|
|
||||||
{
|
|
||||||
// Muestra el menu
|
|
||||||
menuVisible = true;
|
|
||||||
|
|
||||||
// Reinicia el contador
|
|
||||||
counter = TITLE_COUNTER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,21 +295,11 @@ void Title::checkInput()
|
|||||||
{
|
{
|
||||||
screen->incWindowSize();
|
screen->incWindowSize();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el tileado de fondo
|
else if (input->checkInput(input_accept, REPEAT_FALSE))
|
||||||
void Title::updateBG()
|
{
|
||||||
{
|
fade->activateFade();
|
||||||
if (backgroundMode == 0)
|
postFade = 0;
|
||||||
{ // El tileado de fondo se desplaza en diagonal
|
|
||||||
++backgroundWindow.x %= 64;
|
|
||||||
++backgroundWindow.y %= 64;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // El tileado de fondo se desplaza en circulo
|
|
||||||
++backgroundCounter %= 360;
|
|
||||||
backgroundWindow.x = 128 + (int(sin[(backgroundCounter + 270) % 360] * 128));
|
|
||||||
backgroundWindow.y = 96 + (int(sin[(360 - backgroundCounter) % 360] * 96));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,6 +329,7 @@ void Title::run()
|
|||||||
{
|
{
|
||||||
while (section->name == SECTION_PROG_TITLE)
|
while (section->name == SECTION_PROG_TITLE)
|
||||||
{
|
{
|
||||||
|
checkInput();
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
@@ -665,49 +421,6 @@ bool Title::updatePlayerInputs(int numPlayer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea el mosaico de fondo del titulo
|
|
||||||
void Title::createTiledBackground()
|
|
||||||
{
|
|
||||||
// Crea la textura para el mosaico de fondo
|
|
||||||
background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH * 2, GAMECANVAS_HEIGHT * 2);
|
|
||||||
if (background == nullptr)
|
|
||||||
{
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea los objetos para pintar en la textura de fondo
|
|
||||||
Texture *bgTileTexture = new Texture(renderer, asset->get("title_bg_tile.png"));
|
|
||||||
Sprite *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, renderer);
|
|
||||||
|
|
||||||
// Prepara para dibujar sobre la textura
|
|
||||||
SDL_SetRenderTarget(renderer, background);
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0x43, 0x43, 0x4F, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Rellena la textura con el tile
|
|
||||||
tile->setSpriteClip(0, 0, 64, 64);
|
|
||||||
for (int i = 0; i < 8; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < 6; ++j)
|
|
||||||
{
|
|
||||||
tile->setPosX(i * 64);
|
|
||||||
tile->setPosY(j * 64);
|
|
||||||
tile->render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelve a colocar el renderizador apuntando a la pantalla
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
// Libera la memoria utilizada por los objetos
|
|
||||||
bgTileTexture->unload();
|
|
||||||
delete bgTileTexture;
|
|
||||||
delete tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
||||||
void Title::checkInputDevices()
|
void Title::checkInputDevices()
|
||||||
{
|
{
|
||||||
@@ -749,9 +462,6 @@ void Title::checkInputDevices()
|
|||||||
// Recarga las texturas
|
// Recarga las texturas
|
||||||
void Title::reLoadTextures()
|
void Title::reLoadTextures()
|
||||||
{
|
{
|
||||||
dustTexture->reLoad();
|
gameLogo->reLoad();
|
||||||
coffeeTexture->reLoad();
|
tiledbg->reLoad();
|
||||||
crisisTexture->reLoad();
|
|
||||||
gradientTexture->reLoad();
|
|
||||||
createTiledBackground();
|
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "background.h"
|
#include "background.h"
|
||||||
|
#include "tiledbg.h"
|
||||||
|
#include "game_logo.h"
|
||||||
|
|
||||||
#ifndef TITLE_H
|
#ifndef TITLE_H
|
||||||
#define TITLE_H
|
#define TITLE_H
|
||||||
@@ -47,22 +49,8 @@ private:
|
|||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
section_t *section; // Indicador para el bucle del titulo
|
section_t *section; // Indicador para el bucle del titulo
|
||||||
Background *backgroundObj; // Objeto para dibujar el fondo del juego
|
Background *backgroundObj; // Objeto para dibujar el fondo del juego
|
||||||
|
Tiledbg *tiledbg; // Objeto para dibujar el mosaico animado de fondo
|
||||||
Texture *dustTexture; // Textura con los graficos del polvo
|
GameLogo *gameLogo; // Objeto para dibujar el logo con el título del juego
|
||||||
Texture *coffeeTexture; // Textura con los graficos de la palabra coffee
|
|
||||||
Texture *crisisTexture; // Textura con los graficos de la plabra crisis
|
|
||||||
Texture *gradientTexture; // Textura con los graficos para el degradado del fondo del titulo
|
|
||||||
|
|
||||||
SDL_Rect backgroundWindow; // Ventana visible para la textura de fondo del titulo
|
|
||||||
SDL_Texture *background; // Textura dibujar el fondo del titulo
|
|
||||||
|
|
||||||
AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
|
||||||
AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
|
|
||||||
|
|
||||||
SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
|
|
||||||
SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
|
|
||||||
|
|
||||||
Sprite *gradient; // Sprite para dibujar el degradado del titulo
|
|
||||||
|
|
||||||
Text *text1; // Objeto de texto para poder escribir textos en pantalla
|
Text *text1; // Objeto de texto para poder escribir textos en pantalla
|
||||||
Text *text2; // Objeto de texto para poder escribir textos en pantalla
|
Text *text2; // Objeto de texto para poder escribir textos en pantalla
|
||||||
@@ -70,13 +58,8 @@ private:
|
|||||||
|
|
||||||
// Variable
|
// Variable
|
||||||
JA_Music_t *titleMusic; // Musica para el titulo
|
JA_Music_t *titleMusic; // Musica para el titulo
|
||||||
JA_Sound_t *crashSound; // Sonido con el impacto del título
|
|
||||||
int backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
|
|
||||||
int counter; // Temporizador para la pantalla de titulo
|
int counter; // Temporizador para la pantalla de titulo
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint8 backgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo
|
|
||||||
float sin[360]; // Vector con los valores del seno precalculados
|
|
||||||
bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
|
|
||||||
bool demo; // Indica si el modo demo estará activo
|
bool demo; // Indica si el modo demo estará activo
|
||||||
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
@@ -86,7 +69,7 @@ private:
|
|||||||
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
|
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
|
||||||
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
||||||
|
|
||||||
// Inicializa los valores
|
// Inicializa los valores de las variables
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -101,9 +84,6 @@ private:
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|
||||||
// Actualiza el tileado de fondo
|
|
||||||
void updateBG();
|
|
||||||
|
|
||||||
// Cambia el valor de la variable de modo de pantalla completa
|
// Cambia el valor de la variable de modo de pantalla completa
|
||||||
void switchFullScreenModeVar();
|
void switchFullScreenModeVar();
|
||||||
|
|
||||||
@@ -119,9 +99,6 @@ private:
|
|||||||
// Modifica las opciones para los controles de los jugadores
|
// Modifica las opciones para los controles de los jugadores
|
||||||
bool updatePlayerInputs(int numPlayer);
|
bool updatePlayerInputs(int numPlayer);
|
||||||
|
|
||||||
// Crea el mosaico de fondo del titulo
|
|
||||||
void createTiledBackground();
|
|
||||||
|
|
||||||
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
// Comprueba cuantos mandos hay conectados para gestionar el menu de opciones
|
||||||
void checkInputDevices();
|
void checkInputDevices();
|
||||||
|
|
||||||
|
|||||||
4
todo.txt
4
todo.txt
@@ -6,4 +6,6 @@
|
|||||||
[] Hacer el marcador transparente
|
[] Hacer el marcador transparente
|
||||||
[] Valorar la opcion de que write devuelva texturas con el texto en lugar de pintar letra a letra
|
[] Valorar la opcion de que write devuelva texturas con el texto en lugar de pintar letra a letra
|
||||||
[] Arreglar los anclajes en la pantalla de game over
|
[] Arreglar los anclajes en la pantalla de game over
|
||||||
[] Al poner pausa, que se sigan moviendo las nubes
|
[] Al poner pausa, que se sigan moviendo las nubes
|
||||||
|
[] Revisar la clase Fade
|
||||||
|
[] Quitar los static de title / crear clase para el logo de coffee crisis
|
||||||
Reference in New Issue
Block a user