Compare commits
2 Commits
9b9fd15f4e
...
c1f8e16963
| Author | SHA1 | Date | |
|---|---|---|---|
| c1f8e16963 | |||
| 90ebea4807 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -8,4 +8,5 @@ thumbs.db
|
||||
*.tar.gz
|
||||
*.zip
|
||||
*.app
|
||||
*_debug*
|
||||
*_debug*
|
||||
jail_engine*
|
||||
15
Makefile
Normal file
15
Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
executable = jail_engine_demo
|
||||
source = *.cpp units/*.cpp
|
||||
|
||||
windows:
|
||||
@echo off
|
||||
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
|
||||
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
|
||||
|
||||
macos:
|
||||
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
|
||||
|
||||
|
||||
linux:
|
||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
||||
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
||||
88
main.cpp
88
main.cpp
@@ -18,8 +18,8 @@ Código fuente creado por JailDesigner
|
||||
SDL_Event *event;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int ticks = 0;
|
||||
int ticksSpeed = 15;
|
||||
Uint32 ticks = 0;
|
||||
Uint32 ticksSpeed = 15;
|
||||
int counter = 0;
|
||||
int gradColorMin = 64; // Minimo color más alto del degradado
|
||||
int gradColorMax = 192; // Minimo color más alto del degradado
|
||||
@@ -28,13 +28,14 @@ int gradBreathDirection = 0; // Indica si gradCurrentColor crece o decrece
|
||||
|
||||
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;
|
||||
options->screen.nativeWidth = 320;
|
||||
options->screen.nativeHeight = 240;
|
||||
options->screen.nativeZoom = 1;
|
||||
options->screen.windowZoom = 2;
|
||||
options->console = false;
|
||||
|
||||
// Inicializa la lista de recursos
|
||||
Asset *asset = new Asset(argv[0]);
|
||||
@@ -53,7 +54,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Inicializa SDL y la ventana
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options->gameWidth, options->gameHeight, SDL_WINDOW_SHOWN);
|
||||
window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options->screen.nativeWidth * options->screen.nativeZoom * options->screen.windowZoom, options->screen.nativeHeight * options->screen.nativeZoom * options->screen.windowZoom, SDL_WINDOW_SHOWN);
|
||||
// window = SDL_CreateWindow("jail_engine_demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_SHOWN);
|
||||
if (window != nullptr)
|
||||
{
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
@@ -70,13 +72,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Inicializa jail_audio
|
||||
JA_Init(48000, AUDIO_S16, 2);
|
||||
|
||||
JA_Music_t *music;
|
||||
JA_Sound_t *sound;
|
||||
|
||||
music = JA_LoadMusic(asset->get("music.ogg").c_str());
|
||||
sound = JA_LoadSound(asset->get("sound.wav").c_str());
|
||||
int volume = 128;
|
||||
|
||||
// Inicializa el objeto screen
|
||||
Screen *screen = new Screen(window, renderer, options);
|
||||
@@ -99,7 +98,7 @@ int main(int argc, char *argv[])
|
||||
sprite->setVelY(2);
|
||||
|
||||
// Bucle principal
|
||||
// JA_PlayMusic(music, true);
|
||||
JA_PlayMusic(music, true);
|
||||
bool should_exit = false;
|
||||
while (!should_exit)
|
||||
{
|
||||
@@ -116,6 +115,19 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
switch (event->key.keysym.scancode)
|
||||
{
|
||||
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
should_exit = true;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_1:
|
||||
screen->decWindowSize();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_2:
|
||||
screen->incWindowSize();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_N:
|
||||
screen->showNotification("Ejemplo de notificacion", "con 2 lineas de texto", 0);
|
||||
break;
|
||||
@@ -139,7 +151,7 @@ int main(int argc, char *argv[])
|
||||
screen->update();
|
||||
|
||||
// Actualiza el sprite
|
||||
if (sprite->getPosX() + sprite->getWidth() > options->gameWidth or sprite->getPosX() < 0)
|
||||
if (sprite->getPosX() + sprite->getWidth() > options->screen.nativeWidth or sprite->getPosX() < 0)
|
||||
{
|
||||
sprite->undoMoveX();
|
||||
int spr_direction = 1;
|
||||
@@ -155,7 +167,7 @@ int main(int argc, char *argv[])
|
||||
sprite->setVelX(spr_force * spr_direction);
|
||||
JA_PlaySound(sound);
|
||||
}
|
||||
if (sprite->getPosY() + sprite->getHeight() > options->gameHeight or sprite->getPosY() < 0)
|
||||
if (sprite->getPosY() + sprite->getHeight() > options->screen.nativeHeight or sprite->getPosY() < 0)
|
||||
{
|
||||
sprite->undoMoveY();
|
||||
int spr_direction = 1;
|
||||
@@ -191,10 +203,12 @@ int main(int argc, char *argv[])
|
||||
// Dibuja en pantalla
|
||||
screen->start();
|
||||
screen->clean();
|
||||
// SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
|
||||
// SDL_RenderClear(renderer);
|
||||
|
||||
// Dibuja un degradado de fondo
|
||||
const int gradFirstLine = options->gameHeight / 3;
|
||||
const int gradLastLine = options->gameHeight;
|
||||
const int gradFirstLine = options->screen.nativeHeight / 3;
|
||||
const int gradLastLine = options->screen.nativeHeight;
|
||||
const int gradNumLines = gradLastLine - gradFirstLine;
|
||||
const int gradColorFrom = 0;
|
||||
|
||||
@@ -203,43 +217,69 @@ int main(int argc, char *argv[])
|
||||
float step = ((float)(i - gradFirstLine) / gradNumLines);
|
||||
int color = gradColorFrom + ((gradCurrentColor - gradColorFrom) * step);
|
||||
SDL_SetRenderDrawColor(renderer, color, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderDrawLine(renderer, 0, i, options->gameWidth, i);
|
||||
SDL_RenderDrawLine(renderer, 0, i, options->screen.nativeWidth, i);
|
||||
}
|
||||
|
||||
// Escribe el texto
|
||||
text->setZoom(2);
|
||||
text->writeCentered(options->gameWidth / 2, text->getCharacterSize(), "Jail Engine DEMO");
|
||||
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize(), "Jail Engine DEMO");
|
||||
text->disableZoom();
|
||||
text->writeCentered(options->gameWidth / 2, text->getCharacterSize() * 6, "Pulsa 'N' para mostrar una notificacion");
|
||||
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize() * 7, "Pulsa 'N' para mostrar");
|
||||
text->writeCentered(options->screen.nativeWidth / 2, text->getCharacterSize() * 8, "una notificacion");
|
||||
|
||||
// Dibuja el sprite
|
||||
sprite->render();
|
||||
|
||||
// Vuelca el buffer en pantalla
|
||||
screen->blit();
|
||||
// SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
// Finaliza el sprite
|
||||
delete sprite;
|
||||
delete texture;
|
||||
if (sprite != nullptr)
|
||||
{
|
||||
delete sprite;
|
||||
}
|
||||
if (texture != nullptr)
|
||||
{
|
||||
delete texture;
|
||||
}
|
||||
|
||||
// Finaliza el texto
|
||||
delete text;
|
||||
if (text != nullptr)
|
||||
{
|
||||
delete text;
|
||||
}
|
||||
|
||||
// Finaliza el objeto screen
|
||||
delete screen;
|
||||
if (screen != nullptr)
|
||||
{
|
||||
delete screen;
|
||||
}
|
||||
|
||||
// Finaliza jail_audio
|
||||
JA_DeleteSound(sound);
|
||||
JA_DeleteMusic(music);
|
||||
|
||||
// Finaliza el objeto con la lista de recuros
|
||||
delete asset;
|
||||
if (asset != nullptr)
|
||||
{
|
||||
delete asset;
|
||||
}
|
||||
|
||||
// Finaliza las opciones
|
||||
if (options != nullptr)
|
||||
{
|
||||
delete options;
|
||||
}
|
||||
|
||||
// Finaliza SDL y la ventana
|
||||
if (event != nullptr)
|
||||
{
|
||||
delete event;
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
delete event;
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -148,6 +148,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
|
||||
{
|
||||
//std::cout << "Creado AnimatedSprite" << std::endl;
|
||||
// Copia los punteros
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
@@ -176,6 +177,7 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
|
||||
{
|
||||
//std::cout << "Creado AnimatedSprite" << std::endl;
|
||||
// Copia los punteros
|
||||
setTexture(animation->texture);
|
||||
setRenderer(renderer);
|
||||
@@ -193,6 +195,7 @@ AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animati
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
{
|
||||
//std::cout << "Destruido AnimatedSprite" << std::endl;
|
||||
for (auto &a : animation)
|
||||
{
|
||||
a.frames.clear();
|
||||
@@ -510,21 +513,6 @@ void AnimatedSprite::update()
|
||||
MovingSprite::update();
|
||||
}
|
||||
|
||||
// Establece el rectangulo para un frame de una animación
|
||||
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
|
||||
{
|
||||
animation[index_animation].frames.push_back({x, y, w, h});
|
||||
}
|
||||
|
||||
// OLD - Establece el contador para todas las animaciones
|
||||
void AnimatedSprite::setAnimationCounter(int value)
|
||||
{
|
||||
for (auto &a : animation)
|
||||
{
|
||||
a.counter = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Reinicia la animación
|
||||
void AnimatedSprite::resetAnimation()
|
||||
{
|
||||
|
||||
@@ -90,12 +90,6 @@ public:
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
|
||||
// OLD - Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||
|
||||
// OLD - Establece el contador para todas las animaciones
|
||||
void setAnimationCounter(int value);
|
||||
|
||||
// Reinicia la animación
|
||||
void resetAnimation();
|
||||
};
|
||||
|
||||
@@ -4,11 +4,18 @@
|
||||
// Constructor
|
||||
Asset::Asset(std::string executablePath)
|
||||
{
|
||||
//std::cout << "Construido Asset" << std::endl;
|
||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
||||
longestName = 0;
|
||||
verbose = true;
|
||||
}
|
||||
|
||||
// Destructot
|
||||
Asset::~Asset()
|
||||
{
|
||||
//std::cout << "Destruido Asset" << std::endl;
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
||||
{
|
||||
|
||||
@@ -50,6 +50,9 @@ public:
|
||||
// Constructor
|
||||
Asset(std::string path);
|
||||
|
||||
// Destructor
|
||||
~Asset();
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "asset.h"
|
||||
#include "input.h"
|
||||
#include "jail_audio.h"
|
||||
//#include "resource.h"
|
||||
#include "sprite.h"
|
||||
#include "text.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
#include "movingsprite.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
//std::cout << "Construido MovingSprite" << std::endl;
|
||||
// Copia los punteros
|
||||
this->texture = texture;
|
||||
this->renderer = renderer;
|
||||
@@ -53,6 +55,12 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
|
||||
currentFlipV = false;
|
||||
};
|
||||
|
||||
// Destructor
|
||||
MovingSprite::~MovingSprite()
|
||||
{
|
||||
//std::cout << "Destruido MovingSprite" << std::endl;
|
||||
}
|
||||
|
||||
// Reinicia todas las variables
|
||||
void MovingSprite::clear()
|
||||
{
|
||||
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
// Constructor
|
||||
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite();
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, string iconFile, string bitmapFile, string textFile, string soundFile, options_t *options)
|
||||
{
|
||||
//std::cout << "Construido Notify" << std::endl;
|
||||
|
||||
// Inicializa variables
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
@@ -21,15 +23,29 @@ Notify::Notify(SDL_Renderer *renderer, string iconFile, string bitmapFile, strin
|
||||
// Destructor
|
||||
Notify::~Notify()
|
||||
{
|
||||
//std::cout << "Destruido Notify" << std::endl;
|
||||
|
||||
// Libera la memoria de los objetos
|
||||
delete iconTexture;
|
||||
delete text;
|
||||
if (iconTexture != nullptr)
|
||||
{
|
||||
delete iconTexture;
|
||||
}
|
||||
if (text != nullptr)
|
||||
{
|
||||
delete text;
|
||||
}
|
||||
JA_DeleteSound(sound);
|
||||
|
||||
for (auto notification : notifications)
|
||||
{
|
||||
delete notification.sprite;
|
||||
delete notification.texture;
|
||||
if (notification.sprite != nullptr)
|
||||
{
|
||||
delete notification.sprite;
|
||||
}
|
||||
if (notification.texture != nullptr)
|
||||
{
|
||||
delete notification.texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +132,14 @@ void Notify::clearFinishedNotifications()
|
||||
{
|
||||
if (notifications[i].state == ns_finished)
|
||||
{
|
||||
delete notifications[i].sprite;
|
||||
delete notifications[i].texture;
|
||||
if (notifications[i].sprite != nullptr)
|
||||
{
|
||||
delete notifications[i].sprite;
|
||||
}
|
||||
if (notifications[i].texture != nullptr)
|
||||
{
|
||||
delete notifications[i].texture;
|
||||
}
|
||||
notifications.erase(notifications.begin() + i);
|
||||
}
|
||||
}
|
||||
@@ -142,11 +164,11 @@ void Notify::showText(string text1, string text2, int icon)
|
||||
}
|
||||
else if (options->notifications.posH == pos_middle)
|
||||
{
|
||||
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2));
|
||||
despH = ((options->screen.nativeWidth * options->screen.windowZoom) / 2 - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
despH = (options->screen.windowWidth * options->windowSize) - width - padding;
|
||||
despH = (options->screen.nativeWidth * options->screen.windowZoom) - width - padding;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
@@ -157,7 +179,7 @@ void Notify::showText(string text1, string text2, int icon)
|
||||
}
|
||||
else
|
||||
{
|
||||
despV = (options->screen.windowHeight * options->windowSize) - height - padding;
|
||||
despV = (options->screen.nativeHeight * options->screen.windowZoom) - height - padding;
|
||||
}
|
||||
|
||||
const int travelDist = height + padding;
|
||||
|
||||
@@ -5,15 +5,14 @@
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||
{
|
||||
//std::cout << "Construido Screen" << std::endl;
|
||||
// Inicializa variables
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
|
||||
gameCanvasWidth = options->gameWidth;
|
||||
gameCanvasHeight = options->gameHeight;
|
||||
borderWidth = options->borderWidth * 2;
|
||||
borderHeight = options->borderHeight * 2;
|
||||
borderWidth = options->screen.borderWidth * 2;
|
||||
borderHeight = options->screen.borderHeight * 2;
|
||||
|
||||
iniFade();
|
||||
iniSpectrumFade();
|
||||
@@ -22,7 +21,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||
borderColor = {0x00, 0x00, 0x00};
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options->screen.nativeWidth, options->screen.nativeHeight);
|
||||
if (gameCanvas == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
@@ -32,12 +31,13 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||
}
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->videoMode);
|
||||
setVideoMode(options->screen.mode);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
//std::cout << "Destruido Screen" << std::endl;
|
||||
if (notify != nullptr)
|
||||
{
|
||||
delete notify;
|
||||
@@ -90,22 +90,28 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
if (options->borderEnabled)
|
||||
if (options->screen.borderEnabled)
|
||||
{
|
||||
windowWidth = gameCanvasWidth + borderWidth;
|
||||
windowHeight = gameCanvasHeight + borderHeight;
|
||||
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
||||
windowWidth = options->screen.nativeWidth + borderWidth;
|
||||
windowHeight = options->screen.nativeHeight + borderHeight;
|
||||
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), options->screen.nativeWidth, options->screen.nativeHeight};
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
windowWidth = gameCanvasWidth;
|
||||
windowHeight = gameCanvasHeight;
|
||||
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||
// windowWidth = options->screen.nativeWidth;
|
||||
windowWidth = options->screen.nativeWidth * options->screen.nativeZoom * options->screen.windowZoom;
|
||||
// windowHeight = options->screen.nativeHeight;
|
||||
windowHeight = options->screen.nativeHeight * options->screen.nativeZoom * options->screen.windowZoom;
|
||||
// dest = {0, 0, options->screen.nativeWidth, options->screen.nativeHeight};
|
||||
gameWidth = options->screen.nativeWidth * options->screen.nativeZoom;
|
||||
gameHeight = options->screen.nativeHeight * options->screen.nativeZoom;
|
||||
dest = {0, 0, gameWidth, gameHeight};
|
||||
}
|
||||
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
||||
// SDL_SetWindowSize(window, windowWidth * options->screen.windowZoom, windowHeight * options->screen.windowZoom);
|
||||
SDL_SetWindowSize(window, windowWidth, windowHeight);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
|
||||
@@ -119,24 +125,24 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||
|
||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||
if (options->integerScale)
|
||||
if (options->screen.integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
|
||||
while (((options->screen.nativeWidth * (scale + 1)) <= windowWidth) && ((options->screen.nativeHeight * (scale + 1)) <= windowHeight))
|
||||
{
|
||||
scale++;
|
||||
}
|
||||
|
||||
dest.w = gameCanvasWidth * scale;
|
||||
dest.h = gameCanvasHeight * scale;
|
||||
dest.w = options->screen.nativeWidth * scale;
|
||||
dest.h = options->screen.nativeHeight * scale;
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else if (options->keepAspect)
|
||||
else if (options->screen.keepAspect)
|
||||
{
|
||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
||||
float ratio = (float)options->screen.nativeWidth / (float)options->screen.nativeHeight;
|
||||
if ((windowWidth - options->screen.nativeWidth) >= (windowHeight - options->screen.nativeHeight))
|
||||
{
|
||||
dest.h = windowHeight;
|
||||
dest.w = (int)((windowHeight * ratio) + 0.5f);
|
||||
@@ -160,41 +166,40 @@ void Screen::setVideoMode(int videoMode)
|
||||
}
|
||||
|
||||
// Modifica el tamaño del renderizador
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
// SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
SDL_RenderSetLogicalSize(renderer, gameWidth, gameHeight);
|
||||
|
||||
// Actualiza las opciones
|
||||
options->videoMode = videoMode;
|
||||
options->screen.windowWidth = windowWidth;
|
||||
options->screen.windowHeight = windowHeight;
|
||||
options->screen.mode = videoMode;
|
||||
}
|
||||
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options->videoMode);
|
||||
options->screen.mode = (options->screen.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options->screen.mode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowSize(int size)
|
||||
{
|
||||
options->windowSize = size;
|
||||
options->screen.windowZoom = size;
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void Screen::decWindowSize()
|
||||
{
|
||||
--options->windowSize;
|
||||
options->windowSize = std::max(options->windowSize, 1);
|
||||
--options->screen.windowZoom;
|
||||
options->screen.windowZoom = std::max(options->screen.windowZoom, 1);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void Screen::incWindowSize()
|
||||
{
|
||||
++options->windowSize;
|
||||
options->windowSize = std::min(options->windowSize, 4);
|
||||
++options->screen.windowZoom;
|
||||
options->screen.windowZoom = std::min(options->screen.windowZoom, 4);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
@@ -213,25 +218,25 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderWidth(int s)
|
||||
{
|
||||
options->borderWidth = s;
|
||||
options->screen.borderWidth = s;
|
||||
}
|
||||
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderHeight(int s)
|
||||
{
|
||||
options->borderHeight = s;
|
||||
options->screen.borderHeight = s;
|
||||
}
|
||||
|
||||
// Establece si se ha de ver el borde en el modo ventana
|
||||
void Screen::setBorderEnabled(bool value)
|
||||
{
|
||||
options->borderEnabled = value;
|
||||
options->screen.borderEnabled = value;
|
||||
}
|
||||
|
||||
// Cambia entre borde visible y no visible
|
||||
void Screen::switchBorder()
|
||||
{
|
||||
options->borderEnabled = !options->borderEnabled;
|
||||
options->screen.borderEnabled = !options->screen.borderEnabled;
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
@@ -300,7 +305,7 @@ void Screen::renderFade()
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||
const SDL_Rect rect = {0, 0, options->screen.nativeWidth, options->screen.nativeHeight};
|
||||
color_t color = {0, 0, 0};
|
||||
const float step = (float)fadeCounter / (float)fadeLenght;
|
||||
const int alpha = 0 + (255 - 0) * step;
|
||||
|
||||
@@ -22,14 +22,14 @@ private:
|
||||
Notify *notify; // Dibuja notificaciones por pantalla
|
||||
|
||||
// Variables
|
||||
int windowWidth; // Ancho de la pantalla o ventana
|
||||
int windowHeight; // Alto de la pantalla o ventana
|
||||
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||
int borderWidth; // Anchura del borde
|
||||
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
|
||||
int borderWidth; // Anchura del borde que se añade a la resolución nativa del juego
|
||||
int borderHeight; // Anltura del borde que se añade a la resolución nativa del juego
|
||||
int gameWidth; // Resultado de multiplicar la resolución nativa (mas el borde) por el zoom nativo
|
||||
int gameHeight; // Resultado de multiplicar la resolución nativa (mas el borde) por el zoom nativo
|
||||
int windowWidth; // Resultado de multiplicar gameWidth por el zoom de la ventana
|
||||
int windowHeight; // Resultado de multiplicar gameWidth por el zoom de la 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
|
||||
|
||||
// Variables - Efectos
|
||||
bool fade; // Indica si esta activo el efecto de fade
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "sprite.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
//std::cout << "Construido Sprite" << std::endl;
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
@@ -28,6 +30,7 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende
|
||||
|
||||
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
//std::cout << "Construido Sprite" << std::endl;
|
||||
// Establece la posición X,Y del sprite
|
||||
this->x = rect.x;
|
||||
this->y = rect.y;
|
||||
@@ -51,6 +54,12 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
|
||||
zoomH = 1.0f;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
//std::cout << "Destruido Sprite" << std::endl;
|
||||
}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render()
|
||||
{
|
||||
|
||||
@@ -29,6 +29,9 @@ public:
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ textFile_t LoadTextFile(string file, bool verbose)
|
||||
// Constructor
|
||||
Text::Text(string textFile, string bitmapFile, SDL_Renderer *renderer)
|
||||
{
|
||||
//std::cout << "Construido Text" << std::endl;
|
||||
// Carga los offsets desde el fichero
|
||||
textFile_t tf = LoadTextFile(textFile);
|
||||
|
||||
@@ -104,6 +105,7 @@ Text::Text(string textFile, string bitmapFile, SDL_Renderer *renderer)
|
||||
// Constructor
|
||||
Text::Text(string textFile, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
//std::cout << "Construido Text" << std::endl;
|
||||
// Carga los offsets desde el fichero
|
||||
textFile_t tf = LoadTextFile(textFile);
|
||||
|
||||
@@ -128,6 +130,7 @@ Text::Text(string textFile, Texture *texture, SDL_Renderer *renderer)
|
||||
// Constructor
|
||||
Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
|
||||
{
|
||||
//std::cout << "Construido Text" << std::endl;
|
||||
// Inicializa variables desde la estructura
|
||||
boxHeight = textFile->boxHeight;
|
||||
boxWidth = textFile->boxWidth;
|
||||
@@ -149,8 +152,13 @@ Text::Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer)
|
||||
// Destructor
|
||||
Text::~Text()
|
||||
{
|
||||
delete sprite;
|
||||
if (texture)
|
||||
//std::cout << "Destruido Text" << std::endl;
|
||||
if (sprite != nullptr)
|
||||
{
|
||||
delete sprite;
|
||||
}
|
||||
|
||||
if (texture != nullptr)
|
||||
{
|
||||
delete texture;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// Constructor
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
||||
{
|
||||
//std::cout << "Construido Texture" << std::endl;
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->path = path;
|
||||
@@ -26,6 +27,8 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
||||
// Destructor
|
||||
Texture::~Texture()
|
||||
{
|
||||
//std::cout << "Destruido Texture" << std::endl;
|
||||
|
||||
// Libera memoria
|
||||
unload();
|
||||
}
|
||||
|
||||
@@ -559,25 +559,24 @@ bool colorAreEqual(color_t color1, color_t color2)
|
||||
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->screen.mode = 0;
|
||||
options->screen.windowZoom = 1;
|
||||
options->screen.filter = 0;
|
||||
options->screen.vsync = true;
|
||||
options->screen.nativeWidth = 320;
|
||||
options->screen.nativeHeight = 240;
|
||||
options->screen.nativeZoom = 1;
|
||||
options->screen.integerScale = true;
|
||||
options->screen.keepAspect = true;
|
||||
options->screen.borderEnabled = false;
|
||||
options->screen.borderWidth = 0;
|
||||
options->screen.borderHeight = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -122,25 +122,24 @@ struct op_stats_t
|
||||
// Estructura con opciones de la pantalla
|
||||
struct op_screen_t
|
||||
{
|
||||
int windowWidth; // Ancho de la ventana
|
||||
int windowHeight; // Alto de la ventana
|
||||
Uint32 mode; // Contiene el valor del modo de pantalla completa
|
||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||
bool vsync; // Indica si se quiere usar vsync o no
|
||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
|
||||
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
|
||||
int nativeWidth; // Ancho de la textura original de renderizado del juego
|
||||
int nativeHeight; // Alto de la textura original de renderizado del juego
|
||||
int nativeZoom; // Zoom que se aplica a la textura original de renderizado del juego
|
||||
int windowZoom; // Zoom que se aplica a la ventana de juegoF
|
||||
};
|
||||
|
||||
// Estructura con todas las opciones de configuración del programa
|
||||
struct options_t
|
||||
{
|
||||
string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
|
||||
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
||||
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||
bool vSync; // Indica si se quiere usar vsync o no
|
||||
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||
int gameHeight; // Alto de la resolucion nativa del juego
|
||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
|
||||
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
|
||||
palette_e palette; // Paleta de colores a usar en el juego
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||
|
||||
Reference in New Issue
Block a user