Demo: añadida la clase screen
This commit is contained in:
BIN
data/notify.png
Normal file
BIN
data/notify.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
data/notify.wav
Normal file
BIN
data/notify.wav
Normal file
Binary file not shown.
22
main.cpp
22
main.cpp
@@ -13,6 +13,7 @@ Código fuente creado por JailDesigner
|
||||
#include "units/asset.h"
|
||||
#include "units/movingsprite.h"
|
||||
#include "units/texture.h"
|
||||
#include "units/screen.h"
|
||||
|
||||
SDL_Event *event;
|
||||
SDL_Window *window;
|
||||
@@ -30,6 +31,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Inicializa las opciones
|
||||
struct options_t *options = new options_t;
|
||||
initOptions(options);
|
||||
options->gameWidth = 640;
|
||||
options->gameHeight = 480;
|
||||
options->console = true;
|
||||
@@ -41,6 +43,8 @@ int main(int argc, char *argv[])
|
||||
asset->add("/data/smb2.txt", t_font);
|
||||
asset->add("/data/smb2.png", t_bitmap);
|
||||
asset->add("/data/z80.png", t_bitmap);
|
||||
asset->add("/data/notify.png", t_bitmap);
|
||||
asset->add("/data/notify.wav", t_sound);
|
||||
asset->setVerbose(options->console);
|
||||
if (!asset->check())
|
||||
{
|
||||
@@ -74,6 +78,10 @@ int main(int argc, char *argv[])
|
||||
sound = JA_LoadSound(asset->get("sound.wav").c_str());
|
||||
int volume = 128;
|
||||
|
||||
// Inicializa el objeto screen
|
||||
Screen *screen = new Screen(window, renderer, options);
|
||||
screen->addNotifier(asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"));
|
||||
|
||||
// Inicializa el texto
|
||||
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
|
||||
|
||||
@@ -160,7 +168,7 @@ int main(int argc, char *argv[])
|
||||
sprite->update();
|
||||
|
||||
// Actualiza el degradado
|
||||
//if (counter % 4 == 0)
|
||||
// if (counter % 4 == 0)
|
||||
{
|
||||
gradBreathDirection == 0 ? gradCurrentColor-- : gradCurrentColor++;
|
||||
if (gradCurrentColor == gradColorMin)
|
||||
@@ -175,8 +183,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
//SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
//SDL_RenderClear(renderer);
|
||||
screen->start();
|
||||
screen->clean();
|
||||
// Dibuja un degradado de fondo
|
||||
const int gradFirstLine = options->gameHeight / 3;
|
||||
const int gradLastLine = options->gameHeight;
|
||||
@@ -195,7 +205,8 @@ int main(int argc, char *argv[])
|
||||
// Dibuja el sprite
|
||||
sprite->render();
|
||||
// Vuelca el buffer en pantalla
|
||||
SDL_RenderPresent(renderer);
|
||||
//SDL_RenderPresent(renderer);
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
// Finaliza el sprite
|
||||
@@ -205,6 +216,9 @@ int main(int argc, char *argv[])
|
||||
// Finaliza el texto
|
||||
delete text;
|
||||
|
||||
// Finaliza el objeto screen
|
||||
delete screen;
|
||||
|
||||
// Finaliza jail_audio
|
||||
JA_DeleteSound(sound);
|
||||
JA_DeleteMusic(music);
|
||||
|
||||
@@ -3,16 +3,12 @@
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
this->asset = asset;
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
|
||||
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
@@ -41,13 +37,17 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
setVideoMode(options->videoMode);
|
||||
|
||||
// Inicializa variables
|
||||
notifyAdded = false;
|
||||
notifyActive = false;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
if (notify != nullptr)
|
||||
{
|
||||
delete notify;
|
||||
}
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
// Esconde la ventana
|
||||
//SDL_HideWindow(window);
|
||||
// SDL_HideWindow(window);
|
||||
|
||||
if (options->borderEnabled)
|
||||
{
|
||||
@@ -118,7 +118,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
// Muestra la ventana
|
||||
//SDL_ShowWindow(window);
|
||||
// SDL_ShowWindow(window);
|
||||
}
|
||||
|
||||
// Si está activo el modo de pantalla completa añade el borde
|
||||
@@ -385,22 +385,37 @@ void Screen::renderFX()
|
||||
renderSpectrumFade();
|
||||
}
|
||||
|
||||
// Añade un notificador a la pantalla
|
||||
void Screen::addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile)
|
||||
{
|
||||
notify = new Notify(renderer, iconsFile, bitmapFontFile, offsetFontFile, soundFile, options);
|
||||
notifyAdded = true;
|
||||
}
|
||||
|
||||
// Actualiza el notificador
|
||||
void Screen::updateNotifier()
|
||||
{
|
||||
if (notifyAdded)
|
||||
{
|
||||
notify->update();
|
||||
notifyActive = notify->active();
|
||||
}
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
||||
{
|
||||
if (notifyAdded)
|
||||
{
|
||||
notify->showText(text1, text2, icon);
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja las notificaciones
|
||||
void Screen::renderNotifications()
|
||||
{
|
||||
if (notifyAdded)
|
||||
{
|
||||
if (!notifyActive)
|
||||
{
|
||||
return;
|
||||
@@ -409,6 +424,7 @@ void Screen::renderNotifications()
|
||||
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
||||
notify->render();
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el tamaño de las notificaciones
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "notify.h"
|
||||
#include "utils.h"
|
||||
#include <vector>
|
||||
@@ -18,7 +17,6 @@ private:
|
||||
// Objetos y punteros
|
||||
SDL_Window *window; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con el listado de recursos
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
options_t *options; // Variable con todas las opciones del programa
|
||||
Notify *notify; // Dibuja notificaciones por pantalla
|
||||
@@ -32,6 +30,7 @@ private:
|
||||
int borderHeight; // Anltura del borde
|
||||
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
|
||||
bool notifyAdded; // Indica si se ha añadido un notificador
|
||||
bool notifyActive; // Indica si hay notificaciones activas
|
||||
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
||||
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
||||
@@ -71,7 +70,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
|
||||
|
||||
// Destructor
|
||||
~Screen();
|
||||
@@ -134,6 +133,9 @@ public:
|
||||
// Dibuja los efectos
|
||||
void renderFX();
|
||||
|
||||
// Añade un notificador a la pantalla
|
||||
void addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile);
|
||||
|
||||
// Actualiza el notificador
|
||||
void updateNotifier();
|
||||
|
||||
|
||||
@@ -554,3 +554,30 @@ bool colorAreEqual(color_t color1, color_t color2)
|
||||
|
||||
return (r && g && b);
|
||||
}
|
||||
|
||||
// Inicializa la estructura de opciones
|
||||
void initOptions(options_t *options)
|
||||
{
|
||||
options->configVersion = "";
|
||||
options->videoMode = 0;
|
||||
options->windowSize = 1;
|
||||
options->filter = 0;
|
||||
options->vSync = true;
|
||||
options->gameWidth = 320;
|
||||
options->gameHeight = 240;
|
||||
options->integerScale = true;
|
||||
options->keepAspect = true;
|
||||
options->borderEnabled = false;
|
||||
options->borderWidth = 0;
|
||||
options->borderHeight = 0;
|
||||
options->palette = p_zxspectrum;
|
||||
options->console = false;
|
||||
|
||||
options->notifications.posV = pos_top;
|
||||
options->notifications.posH = pos_left;
|
||||
options->notifications.sound = true;
|
||||
options->notifications.color = {48, 48, 48};
|
||||
|
||||
options->screen.windowWidth = options->gameWidth * options->windowSize;
|
||||
options->screen.windowHeight = options->gameHeight * options->windowSize;
|
||||
}
|
||||
@@ -199,4 +199,7 @@ string boolToString(bool value);
|
||||
// Compara dos colores
|
||||
bool colorAreEqual(color_t color1, color_t color2);
|
||||
|
||||
// Inicializa la estructura de opciones
|
||||
void initOptions(options_t *options);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user