se va la luz
This commit is contained in:
@@ -13,7 +13,7 @@ Asset::~Asset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void Asset::add(std::string file, enum assetType type, bool required)
|
void Asset::add(std::string file, enum assetType_e type, bool required)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
temp.file = executablePath + file;
|
temp.file = executablePath + file;
|
||||||
@@ -48,7 +48,7 @@ bool Asset::check()
|
|||||||
printf("\n** Checking files.\n");
|
printf("\n** Checking files.\n");
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
for (int type = 0; type < maxAssetType; ++type)
|
for (int type = 0; type < t_maxAssetType; ++type)
|
||||||
{
|
{
|
||||||
// Comprueba si hay ficheros de ese tipo
|
// Comprueba si hay ficheros de ese tipo
|
||||||
bool any = false;
|
bool any = false;
|
||||||
@@ -117,39 +117,39 @@ std::string Asset::getTypeName(int type)
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case bitmap:
|
case t_bitmap:
|
||||||
return "BITMAP";
|
return "BITMAP";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case music:
|
case t_music:
|
||||||
return "MUSIC";
|
return "MUSIC";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sound:
|
case t_sound:
|
||||||
return "SOUND";
|
return "SOUND";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case font:
|
case t_font:
|
||||||
return "FONT";
|
return "FONT";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lang:
|
case t_lang:
|
||||||
return "LANG";
|
return "LANG";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case data:
|
case t_data:
|
||||||
return "DATA";
|
return "DATA";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case room:
|
case t_room:
|
||||||
return "ROOM";
|
return "ROOM";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case enemy:
|
case t_enemy:
|
||||||
return "ENEMY";
|
return "ENEMY";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case item:
|
case t_item:
|
||||||
return "ITEM";
|
return "ITEM";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -7,18 +7,18 @@
|
|||||||
#ifndef ASSET_H
|
#ifndef ASSET_H
|
||||||
#define ASSET_H
|
#define ASSET_H
|
||||||
|
|
||||||
enum assetType
|
enum assetType_e
|
||||||
{
|
{
|
||||||
bitmap,
|
t_bitmap,
|
||||||
music,
|
t_music,
|
||||||
sound,
|
t_sound,
|
||||||
font,
|
t_font,
|
||||||
lang,
|
t_lang,
|
||||||
data,
|
t_data,
|
||||||
room,
|
t_room,
|
||||||
enemy,
|
t_enemy,
|
||||||
item,
|
t_item,
|
||||||
maxAssetType
|
t_maxAssetType
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clase Asset
|
// Clase Asset
|
||||||
@@ -29,7 +29,7 @@ private:
|
|||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
std::string file; // Ruta del fichero desde la raiz del directorio
|
||||||
enum assetType type; // Indica el tipo de recurso
|
enum assetType_e type; // Indica el tipo de recurso
|
||||||
bool required; // Indica si es un fichero que debe de existir
|
bool required; // Indica si es un fichero que debe de existir
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
~Asset();
|
~Asset();
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void add(std::string file, enum assetType type, bool required = true);
|
void add(std::string file, enum assetType_e type, bool required = true);
|
||||||
|
|
||||||
// Devuelve un elemento de la lista a partir de una cadena
|
// Devuelve un elemento de la lista a partir de una cadena
|
||||||
std::string get(std::string text);
|
std::string get(std::string text);
|
||||||
|
|||||||
@@ -12,14 +12,14 @@
|
|||||||
#define HALF_BLOCK BLOCK / 2
|
#define HALF_BLOCK BLOCK / 2
|
||||||
|
|
||||||
// Tamaño de la pantalla de juego
|
// Tamaño de la pantalla de juego
|
||||||
#define SCREEN_WIDTH 256
|
#define GAME_WIDTH 256
|
||||||
#define SCREEN_HEIGHT 192
|
#define GAME_HEIGHT 192
|
||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK);
|
const int PLAY_AREA_BOTTOM = GAME_HEIGHT - (4 * BLOCK);
|
||||||
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||||
const int PLAY_AREA_RIGHT = SCREEN_WIDTH - (0 * BLOCK);
|
const int PLAY_AREA_RIGHT = GAME_WIDTH - (0 * BLOCK);
|
||||||
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||||
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||||
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||||
@@ -30,12 +30,12 @@ const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
|||||||
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
// Anclajes de pantalla
|
// Anclajes de pantalla
|
||||||
const int SCREEN_CENTER_X = SCREEN_WIDTH / 2;
|
const int SCREEN_CENTER_X = GAME_WIDTH / 2;
|
||||||
const int SCREEN_FIRST_QUARTER_X = SCREEN_WIDTH / 4;
|
const int SCREEN_FIRST_QUARTER_X = GAME_WIDTH / 4;
|
||||||
const int SCREEN_THIRD_QUARTER_X = (SCREEN_WIDTH / 4) * 3;
|
const int SCREEN_THIRD_QUARTER_X = (GAME_WIDTH / 4) * 3;
|
||||||
const int SCREEN_CENTER_Y = SCREEN_HEIGHT / 2;
|
const int SCREEN_CENTER_Y = GAME_HEIGHT / 2;
|
||||||
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
|
const int SCREEN_FIRST_QUARTER_Y = GAME_HEIGHT / 4;
|
||||||
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
|
const int SCREEN_THIRD_QUARTER_Y = (GAME_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
// Secciones del programa
|
// Secciones del programa
|
||||||
#define PROG_SECTION_LOGO 0
|
#define PROG_SECTION_LOGO 0
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Director::Director(std::string path)
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Crea el objeto que controla los ficheros de recursos
|
// Crea el objeto que controla los ficheros de recursos
|
||||||
mAsset = new Asset(path.substr(0, path.find_last_of("\\/")) + "../");
|
asset = new Asset(path.substr(0, path.find_last_of("\\/")) + "../");
|
||||||
|
|
||||||
// Establece la lista de ficheros
|
// Establece la lista de ficheros
|
||||||
Uint8 section = PROG_SECTION_LOGO;
|
Uint8 section = PROG_SECTION_LOGO;
|
||||||
@@ -19,26 +19,26 @@ Director::Director(std::string path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea el objeto de idioma
|
// Crea el objeto de idioma
|
||||||
mLang = new Lang(mAsset);
|
lang = new Lang(asset);
|
||||||
|
|
||||||
// Crea el puntero a la estructura y carga el fichero de configuración
|
// Crea el puntero a la estructura y carga el fichero de configuración
|
||||||
mOptions = new options_t;
|
options = new options_t;
|
||||||
loadConfigFile();
|
loadConfigFile();
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
mInput = new Input(mAsset->get("controllerdb.txt"));
|
input = new Input(asset->get("controllerdb.txt"));
|
||||||
|
|
||||||
// Inicializa SDL
|
// Inicializa SDL
|
||||||
initSDL();
|
initSDL();
|
||||||
|
|
||||||
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
|
// Crea el objeto para dibujar en pantalla (Requiere initSDL)
|
||||||
mScreen = new Screen(mWindow, mRenderer, mOptions);
|
screen = new Screen(window, renderer, options, GAME_WIDTH, GAME_HEIGHT);
|
||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
initJailAudio();
|
initJailAudio();
|
||||||
|
|
||||||
// Aplica las opciones
|
// Aplica las opciones
|
||||||
mLang->setLang(mOptions->language);
|
lang->setLang(options->language);
|
||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
init(section);
|
init(section);
|
||||||
@@ -48,25 +48,25 @@ Director::~Director()
|
|||||||
{
|
{
|
||||||
saveConfigFile();
|
saveConfigFile();
|
||||||
|
|
||||||
delete mAsset;
|
delete asset;
|
||||||
mAsset = nullptr;
|
asset = nullptr;
|
||||||
|
|
||||||
delete mInput;
|
delete input;
|
||||||
mInput = nullptr;
|
input = nullptr;
|
||||||
|
|
||||||
delete mScreen;
|
delete screen;
|
||||||
mScreen = nullptr;
|
screen = nullptr;
|
||||||
|
|
||||||
delete mLang;
|
delete lang;
|
||||||
mLang = nullptr;
|
lang = nullptr;
|
||||||
|
|
||||||
delete mOptions;
|
delete options;
|
||||||
mOptions = nullptr;
|
options = nullptr;
|
||||||
|
|
||||||
SDL_DestroyRenderer(mRenderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(mWindow);
|
SDL_DestroyWindow(window);
|
||||||
mRenderer = nullptr;
|
renderer = nullptr;
|
||||||
mWindow = nullptr;
|
window = nullptr;
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
@@ -75,36 +75,36 @@ Director::~Director()
|
|||||||
void Director::init(Uint8 name)
|
void Director::init(Uint8 name)
|
||||||
{
|
{
|
||||||
// Sección
|
// Sección
|
||||||
mSection.name = name;
|
section.name = name;
|
||||||
mSection.subsection = 0;
|
section.subsection = 0;
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
mLang->setLang(mOptions->language);
|
lang->setLang(options->language);
|
||||||
|
|
||||||
// Controles
|
// Controles
|
||||||
mInput->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||||
mInput->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||||
mInput->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||||
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||||
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
input->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||||
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
input->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
input->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
input->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
input->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||||
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
input->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||||
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
input->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||||
|
|
||||||
mInput->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
input->bindGameControllerButton(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||||
mInput->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
input->bindGameControllerButton(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||||
mInput->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
input->bindGameControllerButton(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||||
mInput->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
input->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||||
mInput->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
|
input->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
|
||||||
mInput->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
|
input->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
|
||||||
mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
input->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
||||||
mInput->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
input->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
||||||
mInput->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
input->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
||||||
mInput->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
input->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
||||||
mInput->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
input->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
@@ -131,14 +131,14 @@ bool Director::initSDL()
|
|||||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||||
|
|
||||||
// Establece el filtro de la textura
|
// Establece el filtro de la textura
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(mOptions->filter).c_str()))
|
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->filter).c_str()))
|
||||||
{
|
{
|
||||||
printf("Warning: Nearest texture filtering not enabled!\n");
|
printf("Warning: Nearest texture filtering not enabled!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la ventana
|
// Crea la ventana
|
||||||
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth * options->windowSize, options->screenHeight * options->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
if (mWindow == nullptr)
|
if (window == nullptr)
|
||||||
{
|
{
|
||||||
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
success = false;
|
success = false;
|
||||||
@@ -146,12 +146,12 @@ bool Director::initSDL()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
||||||
if (mOptions->vSync)
|
if (options->vSync)
|
||||||
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
else
|
else
|
||||||
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
if (mRenderer == nullptr)
|
if (renderer == nullptr)
|
||||||
{
|
{
|
||||||
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
success = false;
|
success = false;
|
||||||
@@ -159,13 +159,13 @@ bool Director::initSDL()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Inicializa el color de renderizado
|
// Inicializa el color de renderizado
|
||||||
SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0xFF);
|
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||||
|
|
||||||
// Establece el tamaño del buffer de renderizado
|
// Establece el tamaño del buffer de renderizado
|
||||||
SDL_RenderSetLogicalSize(mRenderer, mOptions->screenWidth, mOptions->screenHeight);
|
SDL_RenderSetLogicalSize(renderer, options->screenWidth, options->screenHeight);
|
||||||
|
|
||||||
// Establece el modo de mezcla
|
// Establece el modo de mezcla
|
||||||
SDL_SetRenderDrawBlendMode(mRenderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,174 +178,101 @@ bool Director::initSDL()
|
|||||||
bool Director::setFileList()
|
bool Director::setFileList()
|
||||||
{
|
{
|
||||||
// Ficheros binarios
|
// Ficheros binarios
|
||||||
mAsset->add("data/score.bin", data, false);
|
asset->add("data/score.bin", t_data, false);
|
||||||
mAsset->add("data/demo.bin", data);
|
asset->add("data/demo.bin", t_data);
|
||||||
mAsset->add("data/config.bin", data, false);
|
asset->add("data/config.bin", t_data, false);
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
mAsset->add("media/music/intro.ogg", music);
|
asset->add("media/music/intro.ogg", t_music);
|
||||||
mAsset->add("media/music/playing.ogg", music);
|
asset->add("media/music/playing.ogg", t_music);
|
||||||
mAsset->add("media/music/title.ogg", music);
|
asset->add("media/music/title.ogg", t_music);
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
mAsset->add("media/sound/balloon.wav", sound);
|
asset->add("media/sound/balloon.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble1.wav", sound);
|
asset->add("media/sound/bubble1.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble2.wav", sound);
|
asset->add("media/sound/bubble2.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble3.wav", sound);
|
asset->add("media/sound/bubble3.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble4.wav", sound);
|
asset->add("media/sound/bubble4.wav", t_sound);
|
||||||
mAsset->add("media/sound/bullet.wav", sound);
|
asset->add("media/sound/bullet.wav", t_sound);
|
||||||
mAsset->add("media/sound/coffeeout.wav", sound);
|
asset->add("media/sound/coffeeout.wav", t_sound);
|
||||||
mAsset->add("media/sound/hiscore.wav", sound);
|
asset->add("media/sound/hiscore.wav", t_sound);
|
||||||
mAsset->add("media/sound/itemdrop.wav", sound);
|
asset->add("media/sound/itemdrop.wav", t_sound);
|
||||||
mAsset->add("media/sound/itempickup.wav", sound);
|
asset->add("media/sound/itempickup.wav", t_sound);
|
||||||
mAsset->add("media/sound/menu_cancel.wav", sound);
|
asset->add("media/sound/menu_cancel.wav", t_sound);
|
||||||
mAsset->add("media/sound/menu_move.wav", sound);
|
asset->add("media/sound/menu_move.wav", t_sound);
|
||||||
mAsset->add("media/sound/menu_select.wav", sound);
|
asset->add("media/sound/menu_select.wav", t_sound);
|
||||||
mAsset->add("media/sound/player_collision.wav", sound);
|
asset->add("media/sound/player_collision.wav", t_sound);
|
||||||
mAsset->add("media/sound/stage_change.wav", sound);
|
asset->add("media/sound/stage_change.wav", t_sound);
|
||||||
mAsset->add("media/sound/title.wav", sound);
|
asset->add("media/sound/title.wav", t_sound);
|
||||||
mAsset->add("media/sound/clock.wav", sound);
|
asset->add("media/sound/clock.wav", t_sound);
|
||||||
mAsset->add("media/sound/powerball.wav", sound);
|
asset->add("media/sound/powerball.wav", t_sound);
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
mAsset->add("media/gfx/balloon.png", bitmap);
|
asset->add("media/gfx/balloon.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/bullet.png", bitmap);
|
asset->add("media/gfx/bullet.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/game_bg.png", bitmap);
|
asset->add("media/gfx/game_bg.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/game_text.png", bitmap);
|
asset->add("media/gfx/game_text.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/intro.png", bitmap);
|
asset->add("media/gfx/intro.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/items.png", bitmap);
|
asset->add("media/gfx/items.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/logo.png", bitmap);
|
asset->add("media/gfx/logo.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_body.png", bitmap);
|
asset->add("media/gfx/player1_body.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_death.png", bitmap);
|
asset->add("media/gfx/player1_death.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_legs.png", bitmap);
|
asset->add("media/gfx/player1_legs.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/title.png", bitmap);
|
asset->add("media/gfx/title.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_head.png", bitmap);
|
asset->add("media/gfx/player1_head.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_body.png", bitmap);
|
asset->add("media/gfx/player2_body.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_death.png", bitmap);
|
asset->add("media/gfx/player2_death.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_legs.png", bitmap);
|
asset->add("media/gfx/player2_legs.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_head.png", bitmap);
|
asset->add("media/gfx/player2_head.png", t_bitmap);
|
||||||
|
|
||||||
// Fuentes
|
// Fuentes
|
||||||
mAsset->add("media/font/8bithud.png", font);
|
asset->add("media/font/8bithud.png", t_font);
|
||||||
mAsset->add("media/font/8bithud.txt", font);
|
asset->add("media/font/8bithud.txt", t_font);
|
||||||
mAsset->add("media/font/nokia.png", font);
|
asset->add("media/font/nokia.png", t_font);
|
||||||
mAsset->add("media/font/nokia_big2.png", font);
|
asset->add("media/font/nokia_big2.png", t_font);
|
||||||
mAsset->add("media/font/nokia.txt", font);
|
asset->add("media/font/nokia.txt", t_font);
|
||||||
mAsset->add("media/font/nokia2.png", font);
|
asset->add("media/font/nokia2.png", t_font);
|
||||||
mAsset->add("media/font/nokia2.txt", font);
|
asset->add("media/font/nokia2.txt", t_font);
|
||||||
mAsset->add("media/font/nokia_big2.txt", font);
|
asset->add("media/font/nokia_big2.txt", t_font);
|
||||||
mAsset->add("media/font/smb2_big.png", font);
|
asset->add("media/font/smb2_big.png", t_font);
|
||||||
mAsset->add("media/font/smb2_big.txt", font);
|
asset->add("media/font/smb2_big.txt", t_font);
|
||||||
mAsset->add("media/font/smb2.png", font);
|
asset->add("media/font/smb2.png", t_font);
|
||||||
mAsset->add("media/font/smb2.txt", font);
|
asset->add("media/font/smb2.txt", t_font);
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
mAsset->add("media/lang/es_ES.txt", lang);
|
asset->add("media/lang/es_ES.txt", t_lang);
|
||||||
mAsset->add("media/lang/en_UK.txt", lang);
|
asset->add("media/lang/en_UK.txt", t_lang);
|
||||||
mAsset->add("media/lang/ba_BA.txt", lang);
|
asset->add("media/lang/ba_BA.txt", t_lang);
|
||||||
|
|
||||||
// DATA
|
// DATA
|
||||||
mAsset->add("data/gamecontrollerdb.txt", data);
|
asset->add("data/gamecontrollerdb.txt", t_data);
|
||||||
|
|
||||||
return mAsset->check();
|
return asset->check();
|
||||||
|
|
||||||
// Inicializa el vector
|
|
||||||
/*for (int i = 0; i < MAX_FILE_LIST; i++)
|
|
||||||
mFileList[i] = "";
|
|
||||||
|
|
||||||
// Ficheros binarios
|
|
||||||
mFileList[0] = mExecutablePath + "/" + "../data/score.bin";
|
|
||||||
mFileList[1] = mExecutablePath + "/" + "../data/demo.bin";
|
|
||||||
mFileList[2] = mExecutablePath + "/" + "../data/config.bin";
|
|
||||||
|
|
||||||
// Musicas
|
|
||||||
mFileList[3] = mExecutablePath + "/" + "../media/music/intro.ogg";
|
|
||||||
mFileList[4] = mExecutablePath + "/" + "../media/music/playing.ogg";
|
|
||||||
mFileList[5] = mExecutablePath + "/" + "../media/music/title.ogg";
|
|
||||||
|
|
||||||
// Sonidos
|
|
||||||
mFileList[6] = mExecutablePath + "/" + "../media/sound/balloon.wav";
|
|
||||||
mFileList[7] = mExecutablePath + "/" + "../media/sound/bubble1.wav";
|
|
||||||
mFileList[8] = mExecutablePath + "/" + "../media/sound/bubble2.wav";
|
|
||||||
mFileList[9] = mExecutablePath + "/" + "../media/sound/bubble3.wav";
|
|
||||||
mFileList[10] = mExecutablePath + "/" + "../media/sound/bubble4.wav";
|
|
||||||
mFileList[11] = mExecutablePath + "/" + "../media/sound/bullet.wav";
|
|
||||||
mFileList[12] = mExecutablePath + "/" + "../media/sound/coffeeout.wav";
|
|
||||||
mFileList[13] = mExecutablePath + "/" + "../media/sound/hiscore.wav";
|
|
||||||
mFileList[14] = mExecutablePath + "/" + "../media/sound/itemdrop.wav";
|
|
||||||
mFileList[15] = mExecutablePath + "/" + "../media/sound/itempickup.wav";
|
|
||||||
mFileList[16] = mExecutablePath + "/" + "../media/sound/menu_cancel.wav";
|
|
||||||
mFileList[17] = mExecutablePath + "/" + "../media/sound/menu_move.wav";
|
|
||||||
mFileList[18] = mExecutablePath + "/" + "../media/sound/menu_select.wav";
|
|
||||||
mFileList[19] = mExecutablePath + "/" + "../media/sound/player_collision.wav";
|
|
||||||
mFileList[20] = mExecutablePath + "/" + "../media/sound/stage_change.wav";
|
|
||||||
mFileList[21] = mExecutablePath + "/" + "../media/sound/title.wav";
|
|
||||||
mFileList[22] = mExecutablePath + "/" + "../media/sound/clock.wav";
|
|
||||||
mFileList[23] = mExecutablePath + "/" + "../media/sound/powerball.wav";
|
|
||||||
|
|
||||||
// Texturas
|
|
||||||
mFileList[24] = mExecutablePath + "/" + "../media/gfx/balloon.png";
|
|
||||||
mFileList[25] = mExecutablePath + "/" + "../media/gfx/bullet.png";
|
|
||||||
mFileList[31] = mExecutablePath + "/" + "../media/gfx/game_bg.png";
|
|
||||||
mFileList[32] = mExecutablePath + "/" + "../media/gfx/game_text.png";
|
|
||||||
mFileList[33] = mExecutablePath + "/" + "../media/gfx/intro.png";
|
|
||||||
mFileList[34] = mExecutablePath + "/" + "../media/gfx/items.png";
|
|
||||||
mFileList[35] = mExecutablePath + "/" + "../media/gfx/logo.png";
|
|
||||||
mFileList[37] = mExecutablePath + "/" + "../media/gfx/player1_body.png";
|
|
||||||
mFileList[38] = mExecutablePath + "/" + "../media/gfx/player1_death.png";
|
|
||||||
mFileList[39] = mExecutablePath + "/" + "../media/gfx/player1_legs.png";
|
|
||||||
mFileList[40] = mExecutablePath + "/" + "../media/gfx/title.png";
|
|
||||||
mFileList[41] = mExecutablePath + "/" + "../media/gfx/player1_head.png";
|
|
||||||
mFileList[42] = mExecutablePath + "/" + "../media/gfx/player2_body.png";
|
|
||||||
mFileList[43] = mExecutablePath + "/" + "../media/gfx/player2_death.png";
|
|
||||||
mFileList[44] = mExecutablePath + "/" + "../media/gfx/player2_legs.png";
|
|
||||||
mFileList[45] = mExecutablePath + "/" + "../media/gfx/player2_head.png";
|
|
||||||
|
|
||||||
// Fuentes
|
|
||||||
mFileList[27] = mExecutablePath + "/" + "../media/font/8bithud.png";
|
|
||||||
mFileList[46] = mExecutablePath + "/" + "../media/font/8bithud.txt";
|
|
||||||
mFileList[28] = mExecutablePath + "/" + "../media/font/nokia.png";
|
|
||||||
mFileList[54] = mExecutablePath + "/" + "../media/font/nokia_big2.png";
|
|
||||||
mFileList[52] = mExecutablePath + "/" + "../media/font/nokia.txt";
|
|
||||||
mFileList[56] = mExecutablePath + "/" + "../media/font/nokia2.png";
|
|
||||||
mFileList[57] = mExecutablePath + "/" + "../media/font/nokia2.txt";
|
|
||||||
mFileList[55] = mExecutablePath + "/" + "../media/font/nokia_big2.txt";
|
|
||||||
mFileList[29] = mExecutablePath + "/" + "../media/font/smb2_big.png";
|
|
||||||
mFileList[47] = mExecutablePath + "/" + "../media/font/smb2_big.txt";
|
|
||||||
mFileList[30] = mExecutablePath + "/" + "../media/font/smb2.png";
|
|
||||||
mFileList[48] = mExecutablePath + "/" + "../media/font/smb2.txt";
|
|
||||||
|
|
||||||
// Textos
|
|
||||||
mFileList[49] = mExecutablePath + "/" + "../media/lang/es_ES.txt";
|
|
||||||
mFileList[50] = mExecutablePath + "/" + "../media/lang/en_UK.txt";
|
|
||||||
mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
|
|
||||||
|
|
||||||
// DATA
|
|
||||||
mFileList[53] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
bool Director::loadConfigFile()
|
bool Director::loadConfigFile()
|
||||||
{
|
{
|
||||||
// Pone unos valores por defecto
|
// Pone unos valores por defecto
|
||||||
mOptions->fullScreenMode = 0;
|
options->fullScreenMode = 0;
|
||||||
mOptions->windowSize = 3;
|
options->windowSize = 3;
|
||||||
mOptions->language = ba_BA;
|
options->language = ba_BA;
|
||||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
options->difficulty = DIFFICULTY_NORMAL;
|
||||||
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
options->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
options->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
options->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
options->vSync = true;
|
||||||
mOptions->screenWidth = SCREEN_WIDTH;
|
options->screenWidth = GAME_WIDTH;
|
||||||
mOptions->screenHeight = SCREEN_HEIGHT;
|
options->screenHeight = GAME_HEIGHT;
|
||||||
mOptions->integerScale = true;
|
options->integerScale = true;
|
||||||
mOptions->keepAspect = true;
|
options->keepAspect = true;
|
||||||
|
options->borderSize = 0.0f;
|
||||||
|
options->borderEnabled = false;
|
||||||
|
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
const std::string p = mAsset->get("config.bin");
|
const std::string p = asset->get("config.bin");
|
||||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||||
|
|
||||||
@@ -361,18 +288,18 @@ bool Director::loadConfigFile()
|
|||||||
printf("New file (%s) created!\n", filename.c_str());
|
printf("New file (%s) created!\n", filename.c_str());
|
||||||
|
|
||||||
// Escribe los datos
|
// Escribe los datos
|
||||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
SDL_RWwrite(file, &options->fullScreenMode, sizeof(options->fullScreenMode), 1);
|
||||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
SDL_RWwrite(file, &options->windowSize, sizeof(options->windowSize), 1);
|
||||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
SDL_RWwrite(file, &options->language, sizeof(options->language), 1);
|
||||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
SDL_RWwrite(file, &options->difficulty, sizeof(options->difficulty), 1);
|
||||||
SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
SDL_RWwrite(file, &options->input[0].deviceType, sizeof(options->input[0].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWwrite(file, &options->input[1].deviceType, sizeof(options->input[1].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &options->filter, sizeof(options->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &options->vSync, sizeof(options->vSync), 1);
|
||||||
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
SDL_RWwrite(file, &options->screenWidth, sizeof(options->screenWidth), 1);
|
||||||
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
SDL_RWwrite(file, &options->screenHeight, sizeof(options->screenHeight), 1);
|
||||||
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
SDL_RWwrite(file, &options->integerScale, sizeof(options->integerScale), 1);
|
||||||
SDL_RWwrite(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
SDL_RWwrite(file, &options->keepAspect, sizeof(options->keepAspect), 1);
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
@@ -388,28 +315,28 @@ bool Director::loadConfigFile()
|
|||||||
{
|
{
|
||||||
// Carga los datos
|
// Carga los datos
|
||||||
printf("Reading file %s\n", filename.c_str());
|
printf("Reading file %s\n", filename.c_str());
|
||||||
SDL_RWread(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
SDL_RWread(file, &options->fullScreenMode, sizeof(options->fullScreenMode), 1);
|
||||||
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
SDL_RWread(file, &options->windowSize, sizeof(options->windowSize), 1);
|
||||||
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
|
SDL_RWread(file, &options->language, sizeof(options->language), 1);
|
||||||
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
SDL_RWread(file, &options->difficulty, sizeof(options->difficulty), 1);
|
||||||
SDL_RWread(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
SDL_RWread(file, &options->input[0].deviceType, sizeof(options->input[0].deviceType), 1);
|
||||||
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWread(file, &options->input[1].deviceType, sizeof(options->input[1].deviceType), 1);
|
||||||
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWread(file, &options->filter, sizeof(options->filter), 1);
|
||||||
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWread(file, &options->vSync, sizeof(options->vSync), 1);
|
||||||
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
SDL_RWread(file, &options->screenWidth, sizeof(options->screenWidth), 1);
|
||||||
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
SDL_RWread(file, &options->screenHeight, sizeof(options->screenHeight), 1);
|
||||||
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
SDL_RWread(file, &options->integerScale, sizeof(options->integerScale), 1);
|
||||||
SDL_RWread(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
SDL_RWread(file, &options->keepAspect, sizeof(options->keepAspect), 1);
|
||||||
|
|
||||||
// Normaliza los valores
|
// Normaliza los valores
|
||||||
if (!((mOptions->fullScreenMode == 0) ||
|
if (!((options->fullScreenMode == 0) ||
|
||||||
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN) ||
|
(options->fullScreenMode == SDL_WINDOW_FULLSCREEN) ||
|
||||||
(mOptions->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)))
|
(options->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)))
|
||||||
mOptions->fullScreenMode = 0;
|
options->fullScreenMode = 0;
|
||||||
if ((mOptions->windowSize < 1) || (mOptions->windowSize > 4))
|
if ((options->windowSize < 1) || (options->windowSize > 4))
|
||||||
mOptions->windowSize = 3;
|
options->windowSize = 3;
|
||||||
if ((mOptions->language < 0) || (mOptions->language > MAX_LANGUAGES))
|
if ((options->language < 0) || (options->language > MAX_LANGUAGES))
|
||||||
mOptions->language = en_UK;
|
options->language = en_UK;
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
@@ -422,24 +349,24 @@ bool Director::loadConfigFile()
|
|||||||
bool Director::saveConfigFile()
|
bool Director::saveConfigFile()
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
const std::string p = mAsset->get("config.bin");
|
const std::string p = asset->get("config.bin");
|
||||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||||
if (file != nullptr)
|
if (file != nullptr)
|
||||||
{
|
{
|
||||||
// Guarda los datos
|
// Guarda los datos
|
||||||
SDL_RWwrite(file, &mOptions->fullScreenMode, sizeof(mOptions->fullScreenMode), 1);
|
SDL_RWwrite(file, &options->fullScreenMode, sizeof(options->fullScreenMode), 1);
|
||||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
SDL_RWwrite(file, &options->windowSize, sizeof(options->windowSize), 1);
|
||||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
SDL_RWwrite(file, &options->language, sizeof(options->language), 1);
|
||||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
SDL_RWwrite(file, &options->difficulty, sizeof(options->difficulty), 1);
|
||||||
SDL_RWwrite(file, &mOptions->input[0].deviceType, sizeof(mOptions->input[0].deviceType), 1);
|
SDL_RWwrite(file, &options->input[0].deviceType, sizeof(options->input[0].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
|
SDL_RWwrite(file, &options->input[1].deviceType, sizeof(options->input[1].deviceType), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &options->filter, sizeof(options->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &options->vSync, sizeof(options->vSync), 1);
|
||||||
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
|
SDL_RWwrite(file, &options->screenWidth, sizeof(options->screenWidth), 1);
|
||||||
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
|
SDL_RWwrite(file, &options->screenHeight, sizeof(options->screenHeight), 1);
|
||||||
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
|
SDL_RWwrite(file, &options->integerScale, sizeof(options->integerScale), 1);
|
||||||
SDL_RWwrite(file, &mOptions->keepAspect, sizeof(mOptions->keepAspect), 1);
|
SDL_RWwrite(file, &options->keepAspect, sizeof(options->keepAspect), 1);
|
||||||
|
|
||||||
printf("Writing file %s\n", filename.c_str());
|
printf("Writing file %s\n", filename.c_str());
|
||||||
|
|
||||||
@@ -456,56 +383,56 @@ bool Director::saveConfigFile()
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint8 Director::getSubsection()
|
Uint8 Director::getSubsection()
|
||||||
{
|
{
|
||||||
return mSection.subsection;
|
return section.subsection;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint8 Director::getSection()
|
Uint8 Director::getSection()
|
||||||
{
|
{
|
||||||
return mSection.name;
|
return section.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Director::setSection(section_t section)
|
void Director::setSection(section_t section)
|
||||||
{
|
{
|
||||||
mSection = section;
|
section = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runLogo()
|
void Director::runLogo()
|
||||||
{
|
{
|
||||||
mLogo = new Logo(mRenderer, mScreen, mAsset);
|
logo = new Logo(renderer, screen, asset);
|
||||||
setSection(mLogo->run());
|
setSection(logo->run());
|
||||||
delete mLogo;
|
delete logo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runIntro()
|
void Director::runIntro()
|
||||||
{
|
{
|
||||||
mIntro = new Intro(mRenderer, mScreen, mAsset, mLang);
|
intro = new Intro(renderer, screen, asset, lang);
|
||||||
setSection(mIntro->run());
|
setSection(intro->run());
|
||||||
delete mIntro;
|
delete intro;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
mTitle = new Title(mWindow, mRenderer, mScreen, mInput, mAsset, mOptions, mLang);
|
title = new Title(window, renderer, screen, input, asset, options, lang);
|
||||||
setSection(mTitle->run(mSection.subsection));
|
setSection(title->run(section.subsection));
|
||||||
delete mTitle;
|
delete title;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runGame()
|
void Director::runGame()
|
||||||
{
|
{
|
||||||
if (mSection.subsection == GAME_SECTION_PLAY_1P)
|
if (section.subsection == GAME_SECTION_PLAY_1P)
|
||||||
{
|
{
|
||||||
mGame = new Game(1, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
|
game = new Game(1, 0, renderer, screen, asset, lang, input, false, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
else if (section.subsection == GAME_SECTION_PLAY_2P)
|
||||||
{
|
{
|
||||||
mGame = new Game(2, 0, mRenderer, mScreen, mAsset, mLang, mInput, false, mOptions);
|
game = new Game(2, 0, renderer, screen, asset, lang, input, false, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
setSection(mGame->run());
|
setSection(game->run());
|
||||||
delete mGame;
|
delete game;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::run()
|
void Director::run()
|
||||||
|
|||||||
@@ -34,19 +34,18 @@
|
|||||||
class Director
|
class Director
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SDL_Window *mWindow; // La ventana donde dibujamos
|
SDL_Window *window; // La ventana donde dibujamos
|
||||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Logo *mLogo; // Objeto para la sección del logo
|
Logo *logo; // Objeto para la sección del logo
|
||||||
Intro *mIntro; // Objeto para la sección de la intro
|
Intro *intro; // Objeto para la sección de la intro
|
||||||
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
Title *title; // Objeto para la sección del titulo y el menu de opciones
|
||||||
Game *mGame; // Objeto para la sección del juego
|
Game *game; // Objeto para la sección del juego
|
||||||
Input *mInput; // Objeto Input para gestionar las entradas
|
Input *input; // Objeto Input para gestionar las entradas
|
||||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
struct options_t *mOptions; // Variable con todas las opciones del programa
|
struct options_t *options; // Variable con todas las opciones del programa
|
||||||
std::string mExecutablePath; // Path del ejecutable
|
section_t section; // Sección y subsección actual del programa;
|
||||||
section_t mSection; // Sección y subsección actual del programa;
|
|
||||||
|
|
||||||
// Inicializa jail_audio
|
// Inicializa jail_audio
|
||||||
void initJailAudio();
|
void initJailAudio();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Fade::Fade(SDL_Renderer *renderer)
|
|||||||
{
|
{
|
||||||
mRenderer = renderer;
|
mRenderer = renderer;
|
||||||
|
|
||||||
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH, GAME_HEIGHT);
|
||||||
if (mBackbuffer == nullptr)
|
if (mBackbuffer == nullptr)
|
||||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ void Fade::render()
|
|||||||
switch (mFadeType)
|
switch (mFadeType)
|
||||||
{
|
{
|
||||||
case FADE_FULLSCREEN:
|
case FADE_FULLSCREEN:
|
||||||
mRect1 = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
mRect1 = {0, 0, GAME_WIDTH, GAME_HEIGHT};
|
||||||
|
|
||||||
for (int i = 0; i < 256; i += 4)
|
for (int i = 0; i < 256; i += 4)
|
||||||
{
|
{
|
||||||
@@ -66,21 +66,21 @@ void Fade::render()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FADE_CENTER:
|
case FADE_CENTER:
|
||||||
mRect1 = {0, 0, SCREEN_WIDTH, 0};
|
mRect1 = {0, 0, GAME_WIDTH, 0};
|
||||||
mRect2 = {0, 0, SCREEN_WIDTH, 0};
|
mRect2 = {0, 0, GAME_WIDTH, 0};
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64);
|
SDL_SetRenderDrawColor(mRenderer, mR, mG, mB, 64);
|
||||||
|
|
||||||
for (int i = 0; i < mCounter; i++)
|
for (int i = 0; i < mCounter; i++)
|
||||||
{
|
{
|
||||||
mRect1.h = mRect2.h = i * 4;
|
mRect1.h = mRect2.h = i * 4;
|
||||||
mRect2.y = SCREEN_HEIGHT - (i * 4);
|
mRect2.y = GAME_HEIGHT - (i * 4);
|
||||||
|
|
||||||
SDL_RenderFillRect(mRenderer, &mRect1);
|
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||||
SDL_RenderFillRect(mRenderer, &mRect2);
|
SDL_RenderFillRect(mRenderer, &mRect2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mCounter * 4) > SCREEN_HEIGHT)
|
if ((mCounter * 4) > GAME_HEIGHT)
|
||||||
mFinished = true;
|
mFinished = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -98,8 +98,8 @@ void Fade::render()
|
|||||||
// Dibujamos sobre el backbuffer
|
// Dibujamos sobre el backbuffer
|
||||||
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
SDL_SetRenderTarget(mRenderer, mBackbuffer);
|
||||||
|
|
||||||
mRect1.x = rand() % (SCREEN_WIDTH - mRect1.w);
|
mRect1.x = rand() % (GAME_WIDTH - mRect1.w);
|
||||||
mRect1.y = rand() % (SCREEN_HEIGHT - mRect1.h);
|
mRect1.y = rand() % (GAME_HEIGHT - mRect1.h);
|
||||||
SDL_RenderFillRect(mRenderer, &mRect1);
|
SDL_RenderFillRect(mRenderer, &mRect1);
|
||||||
|
|
||||||
// Volvemos a usar el renderizador de forma normal
|
// Volvemos a usar el renderizador de forma normal
|
||||||
|
|||||||
@@ -49,19 +49,21 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
mSmartSprite[i] = new SmartSprite();
|
mSmartSprite[i] = new SmartSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
mTextureBalloon = new LTexture(mRenderer);
|
mTextureBalloon = new LTexture(mRenderer, mAsset->get("balloon.png"));
|
||||||
mTextureBullet = new LTexture(mRenderer);
|
mTextureBullet = new LTexture(mRenderer, mAsset->get("bullet.png"));
|
||||||
mTextureGameBG = new LTexture(mRenderer);
|
mTextureGameBG = new LTexture(mRenderer, mAsset->get("game_bg.png"));
|
||||||
mTextureGameText = new LTexture(mRenderer);
|
mTextureGameText = new LTexture(mRenderer, mAsset->get("game_text.png"));
|
||||||
mTextureItems = new LTexture(mRenderer);
|
mTextureItems = new LTexture(mRenderer, mAsset->get("items.png"));
|
||||||
mTexturePlayer1Head = new LTexture(mRenderer);
|
|
||||||
mTexturePlayer1Body = new LTexture(mRenderer);
|
mTexturePlayer1Head = new LTexture(mRenderer, mAsset->get("player1_head.png"));
|
||||||
mTexturePlayer1Death = new LTexture(mRenderer);
|
mTexturePlayer1Body = new LTexture(mRenderer, mAsset->get("player1_body.png"));
|
||||||
mTexturePlayer1Legs = new LTexture(mRenderer);
|
mTexturePlayer1Legs = new LTexture(mRenderer, mAsset->get("player1_legs.png"));
|
||||||
mTexturePlayer2Head = new LTexture(mRenderer);
|
mTexturePlayer1Death = new LTexture(mRenderer, mAsset->get("player1_death.png"));
|
||||||
mTexturePlayer2Body = new LTexture(mRenderer);
|
|
||||||
mTexturePlayer2Death = new LTexture(mRenderer);
|
mTexturePlayer2Head = new LTexture(mRenderer, mAsset->get("player2_head.png"));
|
||||||
mTexturePlayer2Legs = new LTexture(mRenderer);
|
mTexturePlayer2Body = new LTexture(mRenderer, mAsset->get("player2_body.png"));
|
||||||
|
mTexturePlayer2Legs = new LTexture(mRenderer, mAsset->get("player2_legs.png"));
|
||||||
|
mTexturePlayer2Death = new LTexture(mRenderer, mAsset->get("player2_death.png"));
|
||||||
|
|
||||||
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||||
mTextScoreBoard = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer);
|
mTextScoreBoard = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer);
|
||||||
@@ -82,12 +84,12 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
m1000Bitmap = new SmartSprite();
|
m1000Bitmap = new SmartSprite();
|
||||||
m2500Bitmap = new SmartSprite();
|
m2500Bitmap = new SmartSprite();
|
||||||
m5000Bitmap = new SmartSprite();
|
m5000Bitmap = new SmartSprite();
|
||||||
mSpriteBackground = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mTextureGameBG, mRenderer);
|
mSpriteBackground = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mTextureGameBG, mRenderer);
|
||||||
mSpriteGetReady = new Sprite(0, PLAY_AREA_CENTER_Y - 10, 109, 20, mTextureGameText, mRenderer);
|
mSpriteGetReady = new Sprite(0, PLAY_AREA_CENTER_Y - 10, 109, 20, mTextureGameText, mRenderer);
|
||||||
mSpriteGradient = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mTextureGameBG, mRenderer);
|
mSpriteGradient = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mTextureGameBG, mRenderer);
|
||||||
mSpriteGrass = new Sprite(0, 85, SCREEN_WIDTH, 6, mTextureGameBG, mRenderer);
|
mSpriteGrass = new Sprite(0, 85, GAME_WIDTH, 6, mTextureGameBG, mRenderer);
|
||||||
mSpritePowerMeter = new Sprite(PLAY_AREA_CENTER_X - 20, 170, 40, 8, mTextureGameBG, mRenderer);
|
mSpritePowerMeter = new Sprite(PLAY_AREA_CENTER_X - 20, 170, 40, 8, mTextureGameBG, mRenderer);
|
||||||
mSpriteScoreBoard = new Sprite(0, 160, SCREEN_WIDTH, 32, mTextureGameBG, mRenderer);
|
mSpriteScoreBoard = new Sprite(0, 160, GAME_WIDTH, 32, mTextureGameBG, mRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
@@ -505,10 +507,10 @@ void Game::init()
|
|||||||
m5000Bitmap->setDestY(0);
|
m5000Bitmap->setDestY(0);
|
||||||
|
|
||||||
// Los fondos
|
// Los fondos
|
||||||
mGradientRect[0] = {0, 192, SCREEN_WIDTH, SCREEN_HEIGHT};
|
mGradientRect[0] = {0, 192, GAME_WIDTH, GAME_HEIGHT};
|
||||||
mGradientRect[1] = {256, 192, SCREEN_WIDTH, SCREEN_HEIGHT};
|
mGradientRect[1] = {256, 192, GAME_WIDTH, GAME_HEIGHT};
|
||||||
mGradientRect[2] = {0, 384, SCREEN_WIDTH, SCREEN_HEIGHT};
|
mGradientRect[2] = {0, 384, GAME_WIDTH, GAME_HEIGHT};
|
||||||
mGradientRect[3] = {256, 384, SCREEN_WIDTH, SCREEN_HEIGHT};
|
mGradientRect[3] = {256, 384, GAME_WIDTH, GAME_HEIGHT};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Game'
|
// Carga los recursos necesarios para la sección 'Game'
|
||||||
@@ -516,23 +518,6 @@ bool Game::loadMedia()
|
|||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
// Texturas
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer1Legs, mAsset->get("player1_legs.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer1Head, mAsset->get("player1_head.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer1Body, mAsset->get("player1_body.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer1Death, mAsset->get("player1_death.png"), mRenderer);
|
|
||||||
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer2Legs, mAsset->get("player2_legs.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer2Head, mAsset->get("player2_head.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer2Body, mAsset->get("player2_body.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTexturePlayer2Death, mAsset->get("player2_death.png"), mRenderer);
|
|
||||||
|
|
||||||
success &= loadTextureFromFile(mTextureBalloon, mAsset->get("balloon.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTextureBullet, mAsset->get("bullet.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTextureGameBG, mAsset->get("game_bg.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTextureItems, mAsset->get("items.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTextureGameText, mAsset->get("game_text.png"), mRenderer);
|
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
mSoundBalloon = JA_LoadSound(mAsset->get("balloon.wav").c_str());
|
mSoundBalloon = JA_LoadSound(mAsset->get("balloon.wav").c_str());
|
||||||
mSoundBubble1 = JA_LoadSound(mAsset->get("bubble1.wav").c_str());
|
mSoundBubble1 = JA_LoadSound(mAsset->get("bubble1.wav").c_str());
|
||||||
@@ -1738,9 +1723,9 @@ void Game::updateDeath()
|
|||||||
// Rebote en los laterales
|
// Rebote en los laterales
|
||||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() > 0)
|
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() > 0)
|
||||||
{
|
{
|
||||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getPosX() > (SCREEN_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth()))
|
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getPosX() > (GAME_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth()))
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setPosX(SCREEN_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth());
|
mSmartSprite[mPlayer[i]->mDeathIndex]->setPosX(GAME_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth());
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setVelX(mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() * (-1));
|
mSmartSprite[mPlayer[i]->mDeathIndex]->setVelX(mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() * (-1));
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setDestX(mSmartSprite[mPlayer[i]->mDeathIndex]->getDestX() * (-1));
|
mSmartSprite[mPlayer[i]->mDeathIndex]->setDestX(mSmartSprite[mPlayer[i]->mDeathIndex]->getDestX() * (-1));
|
||||||
}
|
}
|
||||||
@@ -1807,7 +1792,7 @@ void Game::renderDeathFade(int counter)
|
|||||||
{
|
{
|
||||||
rect[i].x = 0;
|
rect[i].x = 0;
|
||||||
rect[i].y = i * 16;
|
rect[i].y = i * 16;
|
||||||
rect[i].w = SCREEN_WIDTH;
|
rect[i].w = GAME_WIDTH;
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
rect[i].h = h;
|
rect[i].h = h;
|
||||||
else
|
else
|
||||||
@@ -1817,7 +1802,7 @@ void Game::renderDeathFade(int counter)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
SDL_Rect rect = {0, 0, GAME_WIDTH, GAME_HEIGHT};
|
||||||
SDL_RenderFillRect(mRenderer, &rect);
|
SDL_RenderFillRect(mRenderer, &rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2519,7 +2504,7 @@ void Game::throwCoffee(int x, int y)
|
|||||||
mSmartSprite[index]->setAccelX(0.0f);
|
mSmartSprite[index]->setAccelX(0.0f);
|
||||||
mSmartSprite[index]->setAccelY(0.2f);
|
mSmartSprite[index]->setAccelY(0.2f);
|
||||||
mSmartSprite[index]->setDestX(x + (mSmartSprite[index]->getVelX() * 50));
|
mSmartSprite[index]->setDestX(x + (mSmartSprite[index]->getVelX() * 50));
|
||||||
mSmartSprite[index]->setDestY(SCREEN_HEIGHT + 1);
|
mSmartSprite[index]->setDestY(GAME_HEIGHT + 1);
|
||||||
mSmartSprite[index]->setEnabled(true);
|
mSmartSprite[index]->setEnabled(true);
|
||||||
mSmartSprite[index]->setEnabledTimer(1);
|
mSmartSprite[index]->setEnabledTimer(1);
|
||||||
mSmartSprite[index]->setSpriteClip(80, 16, 16, 16);
|
mSmartSprite[index]->setSpriteClip(80, 16, 16, 16);
|
||||||
@@ -2543,8 +2528,8 @@ void Game::throwPlayer(int x, int y, int index)
|
|||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setVelY(-5.0f);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setVelY(-5.0f);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setAccelX(0.0f);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setAccelX(0.0f);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setAccelY(0.2f);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setAccelY(0.2f);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setDestX(SCREEN_WIDTH * sentit);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setDestX(GAME_WIDTH * sentit);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setDestY(SCREEN_HEIGHT + 1);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setDestY(GAME_HEIGHT + 1);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setEnabled(true);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setEnabled(true);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setEnabledTimer(1);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setEnabledTimer(1);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setSpriteClip(0, 0, 24, 24);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setSpriteClip(0, 0, 24, 24);
|
||||||
@@ -2775,7 +2760,7 @@ void Game::updateBackground()
|
|||||||
mClouds2b->setPosX(mClouds2b->getWidth());
|
mClouds2b->setPosX(mClouds2b->getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
mSpriteGrass->setSpriteClip(256, 85 + (6 * (mCounter / 20 % 2)), SCREEN_WIDTH, 6);
|
mSpriteGrass->setSpriteClip(256, 85 + (6 * (mCounter / 20 % 2)), GAME_WIDTH, 6);
|
||||||
|
|
||||||
if (mEffect.shake)
|
if (mEffect.shake)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *mAsset
|
|||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
mItemTexture = new LTexture(mRenderer);
|
mItemTexture = new LTexture(mRenderer);
|
||||||
mSprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mItemTexture, mRenderer);
|
mSprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, mItemTexture, mRenderer);
|
||||||
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH, GAME_HEIGHT);
|
||||||
if (mBackbuffer == nullptr)
|
if (mBackbuffer == nullptr)
|
||||||
{
|
{
|
||||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
@@ -135,7 +135,7 @@ void Instructions::run(Uint8 mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pinta en pantalla
|
// Pinta en pantalla
|
||||||
SDL_Rect window = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
SDL_Rect window = {0, 0, GAME_WIDTH, GAME_HEIGHT};
|
||||||
SDL_Rect srcRect = {0, 0, 16, 16};
|
SDL_Rect srcRect = {0, 0, 16, 16};
|
||||||
|
|
||||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
||||||
@@ -166,7 +166,7 @@ void Instructions::run(Uint8 mode)
|
|||||||
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
mText->writeShadowed(84, 156, mLang->getText(21), shdwTxtColor);
|
||||||
|
|
||||||
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
|
if ((mode == INSTRUCTIONS_MODE_MANUAL) && (mCounter % 50 > 14))
|
||||||
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, SCREEN_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
mText->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - 12, mLang->getText(22), 1, orangeColor, 1, shdwTxtColor);
|
||||||
|
|
||||||
// Disquito
|
// Disquito
|
||||||
mSprite->setPos(destRect1);
|
mSprite->setPos(destRect1);
|
||||||
@@ -214,7 +214,7 @@ void Instructions::run(Uint8 mode)
|
|||||||
|
|
||||||
// Establece la ventana del backbuffer
|
// Establece la ventana del backbuffer
|
||||||
if (mode == INSTRUCTIONS_MODE_AUTO)
|
if (mode == INSTRUCTIONS_MODE_AUTO)
|
||||||
window.y = std::max(8, SCREEN_HEIGHT - mCounter + 100);
|
window.y = std::max(8, GAME_HEIGHT - mCounter + 100);
|
||||||
else
|
else
|
||||||
window.y = 0;
|
window.y = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void Intro::init()
|
|||||||
mBitmap[0]->setAccelY(0.0f);
|
mBitmap[0]->setAccelY(0.0f);
|
||||||
mBitmap[0]->setSpriteClip(0, 0, 128, 96);
|
mBitmap[0]->setSpriteClip(0, 0, 128, 96);
|
||||||
|
|
||||||
mBitmap[1]->setPosX(SCREEN_WIDTH);
|
mBitmap[1]->setPosX(GAME_WIDTH);
|
||||||
mBitmap[1]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
mBitmap[1]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
||||||
mBitmap[1]->setVelX(-1.0f);
|
mBitmap[1]->setVelX(-1.0f);
|
||||||
mBitmap[1]->setVelY(0.0f);
|
mBitmap[1]->setVelY(0.0f);
|
||||||
@@ -110,7 +110,7 @@ void Intro::init()
|
|||||||
mBitmap[2]->setEnabledTimer(250);
|
mBitmap[2]->setEnabledTimer(250);
|
||||||
|
|
||||||
mBitmap[3]->setPosX(SCREEN_CENTER_X - 64);
|
mBitmap[3]->setPosX(SCREEN_CENTER_X - 64);
|
||||||
mBitmap[3]->setPosY(SCREEN_HEIGHT);
|
mBitmap[3]->setPosY(GAME_HEIGHT);
|
||||||
mBitmap[3]->setVelX(0.0f);
|
mBitmap[3]->setVelX(0.0f);
|
||||||
mBitmap[3]->setVelY(-0.7f);
|
mBitmap[3]->setVelY(-0.7f);
|
||||||
mBitmap[3]->setAccelX(0.0f);
|
mBitmap[3]->setAccelX(0.0f);
|
||||||
@@ -125,7 +125,7 @@ void Intro::init()
|
|||||||
mBitmap[4]->setAccelY(0.3f);
|
mBitmap[4]->setAccelY(0.3f);
|
||||||
mBitmap[4]->setSpriteClip(0, 192, 128, 96);
|
mBitmap[4]->setSpriteClip(0, 192, 128, 96);
|
||||||
|
|
||||||
mBitmap[5]->setPosX(SCREEN_WIDTH);
|
mBitmap[5]->setPosX(GAME_WIDTH);
|
||||||
mBitmap[5]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
mBitmap[5]->setPosY(SCREEN_FIRST_QUARTER_Y - 24);
|
||||||
mBitmap[5]->setVelX(-0.7f);
|
mBitmap[5]->setVelX(-0.7f);
|
||||||
mBitmap[5]->setVelY(0.0f);
|
mBitmap[5]->setVelY(0.0f);
|
||||||
@@ -140,7 +140,7 @@ void Intro::init()
|
|||||||
mWriter[i]->setId(6 + i);
|
mWriter[i]->setId(6 + i);
|
||||||
mWriter[i]->setIntroEvents(&mEvents[0]);
|
mWriter[i]->setIntroEvents(&mEvents[0]);
|
||||||
mWriter[i]->setPosX(BLOCK * 0);
|
mWriter[i]->setPosX(BLOCK * 0);
|
||||||
mWriter[i]->setPosY(SCREEN_HEIGHT - (BLOCK * 6));
|
mWriter[i]->setPosY(GAME_HEIGHT - (BLOCK * 6));
|
||||||
mWriter[i]->setKerning(-1);
|
mWriter[i]->setKerning(-1);
|
||||||
mWriter[i]->setEnabled(false);
|
mWriter[i]->setEnabled(false);
|
||||||
mWriter[i]->setEnabledTimer(180);
|
mWriter[i]->setEnabledTimer(180);
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
|||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
texture = new LTexture(renderer,asset->get("logo.png");
|
texture = new LTexture(renderer, asset->get("logo.png"));
|
||||||
sprite = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, texture, renderer);
|
sprite = new Sprite(0, 0, GAME_WIDTH, GAME_HEIGHT, texture, renderer);
|
||||||
|
|
||||||
// Crea un backbuffer para el renderizador
|
// Crea un backbuffer para el renderizador
|
||||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH, SCREEN_HEIGHT);
|
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH, GAME_HEIGHT);
|
||||||
if (backbuffer == nullptr)
|
if (backbuffer == nullptr)
|
||||||
{
|
{
|
||||||
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("Backbuffer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
@@ -91,7 +91,7 @@ void Logo::checkEventHandler()
|
|||||||
// Dibuja el fade
|
// Dibuja el fade
|
||||||
void Logo::renderFade()
|
void Logo::renderFade()
|
||||||
{
|
{
|
||||||
const SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
const SDL_Rect rect = {0, 0, GAME_WIDTH, GAME_HEIGHT};
|
||||||
const int fadeLenght = END_LOGO - INIT_FADE;
|
const int fadeLenght = END_LOGO - INIT_FADE;
|
||||||
|
|
||||||
// Dibuja el fade
|
// Dibuja el fade
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#define PLAYER_STATUS_FIRING_RIGHT 2
|
#define PLAYER_STATUS_FIRING_RIGHT 2
|
||||||
#define PLAYER_STATUS_FIRING_NO 3
|
#define PLAYER_STATUS_FIRING_NO 3
|
||||||
|
|
||||||
|
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
|
||||||
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
|
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
|
||||||
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
|
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
|
||||||
|
|
||||||
@@ -37,7 +38,6 @@
|
|||||||
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
|
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
|
||||||
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
|
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
|
||||||
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
|
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
|
||||||
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
|
|
||||||
|
|
||||||
// Variables del jugador
|
// Variables del jugador
|
||||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||||
|
|||||||
@@ -1,133 +1,363 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "const.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
mWindow = window;
|
this->window = window;
|
||||||
mRenderer = renderer;
|
this->renderer = renderer;
|
||||||
mOptions = options;
|
this->options = options;
|
||||||
|
|
||||||
mGameCanvasWidth = SCREEN_WIDTH;
|
gameCanvasWidth = gameInternalResX;
|
||||||
mGameCanvasHeight = SCREEN_HEIGHT;
|
gameCanvasHeight = gameInternalResY;
|
||||||
|
|
||||||
// Establece el modo de video
|
iniFade();
|
||||||
setVideoMode(mOptions->fullScreenMode);
|
iniSpectrumFade();
|
||||||
|
|
||||||
// Define el color del borde para el modo de pantalla completa
|
// Define el color del borde para el modo de pantalla completa
|
||||||
mBorderColor = {0x27, 0x27, 0x36};
|
borderColor = {0x00, 0x00, 0x00};
|
||||||
mBorderColor = {0x00, 0x00, 0x00};
|
|
||||||
|
|
||||||
// Crea la textura donde se dibujan los graficos del juego
|
// Crea la textura donde se dibujan los graficos del juego
|
||||||
mGameCanvas = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, mGameCanvasWidth, mGameCanvasHeight);
|
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||||
if (mGameCanvas == nullptr)
|
if (gameCanvas == NULL)
|
||||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
setVideoMode(options->fullScreenMode);
|
||||||
|
|
||||||
|
// Calcula los anclajes
|
||||||
|
anchor.left = 0;
|
||||||
|
anchor.right = gameCanvasWidth;
|
||||||
|
anchor.center = gameCanvasWidth / 2;
|
||||||
|
anchor.top = 0;
|
||||||
|
anchor.bottom = gameCanvasHeight;
|
||||||
|
anchor.middle = gameCanvasHeight / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen()
|
Screen::~Screen()
|
||||||
{
|
{
|
||||||
mRenderer = nullptr;
|
renderer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void Screen::clean(color_t color)
|
void Screen::clean(color_t color)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(mRenderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
||||||
SDL_RenderClear(mRenderer);
|
SDL_RenderClear(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
void Screen::start()
|
void Screen::start()
|
||||||
{
|
{
|
||||||
SDL_SetRenderTarget(mRenderer, mGameCanvas);
|
SDL_SetRenderTarget(renderer, gameCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::blit()
|
void Screen::blit()
|
||||||
{
|
{
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
// Vuelve a dejar el renderizador en modo normal
|
||||||
SDL_SetRenderTarget(mRenderer, nullptr);
|
SDL_SetRenderTarget(renderer, NULL);
|
||||||
|
|
||||||
// Borra el contenido previo
|
// Borra el contenido previo
|
||||||
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
||||||
SDL_RenderClear(mRenderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||||
SDL_RenderCopy(mRenderer, mGameCanvas, nullptr, &mDest);
|
SDL_RenderCopy(renderer, gameCanvas, NULL, &dest);
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
// Muestra por pantalla el renderizador
|
||||||
SDL_RenderPresent(mRenderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void Screen::setVideoMode(int fullScreenMode)
|
void Screen::setVideoMode(int fullScreenMode)
|
||||||
{
|
{
|
||||||
// Aplica el modo de video
|
// Aplica el modo de video
|
||||||
SDL_SetWindowFullscreen(mWindow, fullScreenMode);
|
SDL_SetWindowFullscreen(window, fullScreenMode);
|
||||||
|
|
||||||
// Si está activo el modo ventana quita el borde
|
// Si está activo el modo ventana quita el borde
|
||||||
if (fullScreenMode == 0)
|
if (fullScreenMode == 0)
|
||||||
{
|
{
|
||||||
mScreenWidth = mGameCanvasWidth;
|
if (options->borderEnabled)
|
||||||
mScreenHeight = mGameCanvasHeight;
|
{
|
||||||
mDest = {0, 0, mGameCanvasWidth, mGameCanvasHeight};
|
const int incWidth = gameCanvasWidth * options->borderSize;
|
||||||
|
const int incHeight = gameCanvasHeight * options->borderSize;
|
||||||
|
screenWidth = gameCanvasWidth + incWidth;
|
||||||
|
screenHeight = gameCanvasHeight + incHeight;
|
||||||
|
dest = {0 + (incWidth / 2), 0 + (incHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
screenWidth = gameCanvasWidth;
|
||||||
|
screenHeight = gameCanvasHeight;
|
||||||
|
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||||
|
}
|
||||||
|
|
||||||
// Modifica el tamaño del renderizador y de la ventana
|
// Modifica el tamaño del renderizador y de la ventana
|
||||||
SDL_RenderSetLogicalSize(mRenderer, mScreenWidth, mScreenHeight);
|
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||||
SDL_SetWindowSize(mWindow, mScreenWidth * mOptions->windowSize, mScreenHeight * mOptions->windowSize);
|
SDL_SetWindowSize(window, screenWidth * options->windowSize, screenHeight * options->windowSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si está activo el modo de pantalla completa añade el borde
|
// Si está activo el modo de pantalla completa añade el borde
|
||||||
if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
else if (fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
{
|
{
|
||||||
// Obten el alto y el ancho de la ventana
|
// Obten el alto y el ancho de la ventana
|
||||||
SDL_GetWindowSize(mWindow, &mScreenWidth, &mScreenHeight);
|
SDL_GetWindowSize(window, &screenWidth, &screenHeight);
|
||||||
|
|
||||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||||
if (mOptions->integerScale)
|
if (options->integerScale)
|
||||||
{
|
{
|
||||||
// Calcula el tamaño de la escala máxima
|
// Calcula el tamaño de la escala máxima
|
||||||
int scale = 0;
|
int scale = 0;
|
||||||
while (((mGameCanvasWidth * (scale + 1)) <= mScreenWidth) && ((mGameCanvasHeight * (scale + 1)) <= mScreenHeight))
|
while (((gameCanvasWidth * (scale + 1)) <= screenWidth) && ((gameCanvasHeight * (scale + 1)) <= screenHeight))
|
||||||
{
|
{
|
||||||
scale++;
|
scale++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDest.w = mGameCanvasWidth * scale;
|
dest.w = gameCanvasWidth * scale;
|
||||||
mDest.h = mGameCanvasHeight * scale;
|
dest.h = gameCanvasHeight * scale;
|
||||||
mDest.x = (mScreenWidth - mDest.w) / 2;
|
dest.x = (screenWidth - dest.w) / 2;
|
||||||
mDest.y = (mScreenHeight - mDest.h) / 2;
|
dest.y = (screenHeight - dest.h) / 2;
|
||||||
}
|
}
|
||||||
else if (mOptions->keepAspect)
|
else if (options->keepAspect)
|
||||||
{
|
{
|
||||||
float ratio = (float)mGameCanvasWidth / (float)mGameCanvasHeight;
|
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||||
if ((mScreenWidth - mGameCanvasWidth) >= (mScreenHeight - mGameCanvasHeight))
|
if ((screenWidth - gameCanvasWidth) >= (screenHeight - gameCanvasHeight))
|
||||||
{
|
{
|
||||||
mDest.h = mScreenHeight;
|
dest.h = screenHeight;
|
||||||
mDest.w = (int)((mScreenHeight * ratio) + 0.5f);
|
dest.w = (int)((screenHeight * ratio) + 0.5f);
|
||||||
mDest.x = (mScreenWidth - mDest.w) / 2;
|
dest.x = (screenWidth - dest.w) / 2;
|
||||||
mDest.y = (mScreenHeight - mDest.h) / 2;
|
dest.y = (screenHeight - dest.h) / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mDest.w = mScreenWidth;
|
dest.w = screenWidth;
|
||||||
mDest.h = (int)((mScreenWidth / ratio) + 0.5f);
|
dest.h = (int)((screenWidth / ratio) + 0.5f);
|
||||||
mDest.x = (mScreenWidth - mDest.w) / 2;
|
dest.x = (screenWidth - dest.w) / 2;
|
||||||
mDest.y = (mScreenHeight - mDest.h) / 2;
|
dest.y = (screenHeight - dest.h) / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mDest.w = mScreenWidth;
|
dest.w = screenWidth;
|
||||||
mDest.h = mScreenHeight;
|
dest.h = screenHeight;
|
||||||
mDest.x = mDest.y = 0;
|
dest.x = dest.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica el tamaño del renderizador
|
// Modifica el tamaño del renderizador
|
||||||
SDL_RenderSetLogicalSize(mRenderer, mScreenWidth, mScreenHeight);
|
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
options->fullScreenMode = fullScreenMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camibia entre pantalla completa y ventana
|
||||||
|
void Screen::switchVideoMode()
|
||||||
|
{
|
||||||
|
if (options->fullScreenMode == 0)
|
||||||
|
{
|
||||||
|
options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options->fullScreenMode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setVideoMode(options->fullScreenMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el tamaño de la ventana
|
||||||
|
void Screen::setWindowSize(int size)
|
||||||
|
{
|
||||||
|
options->windowSize = size;
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
void Screen::setBorderColor(color_t color)
|
||||||
|
{
|
||||||
|
borderColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el tipo de mezcla
|
||||||
|
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer, blendMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el tamaño del borde
|
||||||
|
void Screen::setBorderSize(float s)
|
||||||
|
{
|
||||||
|
options->borderSize = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si se ha de ver el borde en el modo ventana
|
||||||
|
void Screen::setBorderEnabled(bool value)
|
||||||
|
{
|
||||||
|
options->borderEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia entre borde visible y no visible
|
||||||
|
void Screen::switchBorder()
|
||||||
|
{
|
||||||
|
options->borderEnabled = !options->borderEnabled;
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa el fade
|
||||||
|
void Screen::setFade()
|
||||||
|
{
|
||||||
|
fade = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el fade
|
||||||
|
bool Screen::fadeEnded()
|
||||||
|
{
|
||||||
|
if (fade || fadeCounter > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa el spectrum fade
|
||||||
|
void Screen::setspectrumFade()
|
||||||
|
{
|
||||||
|
spectrumFade = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el spectrum fade
|
||||||
|
bool Screen::spectrumFadeEnded()
|
||||||
|
{
|
||||||
|
if (spectrumFade || spectrumFadeCounter > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade
|
||||||
|
void Screen::iniFade()
|
||||||
|
{
|
||||||
|
fade = false;
|
||||||
|
fadeCounter = 0;
|
||||||
|
fadeLenght = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el fade
|
||||||
|
void Screen::updateFade()
|
||||||
|
{
|
||||||
|
if (!fade)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fadeCounter++;
|
||||||
|
if (fadeCounter > fadeLenght)
|
||||||
|
{
|
||||||
|
iniFade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
void Screen::renderFade()
|
||||||
|
{
|
||||||
|
if (!fade)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||||
|
color_t color = {0, 0, 0};
|
||||||
|
const float step = (float)fadeCounter / (float)fadeLenght;
|
||||||
|
const int alpha = 0 + (255 - 0) * step;
|
||||||
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
||||||
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade spectrum
|
||||||
|
void Screen::iniSpectrumFade()
|
||||||
|
{
|
||||||
|
spectrumFade = false;
|
||||||
|
spectrumFadeCounter = 0;
|
||||||
|
spectrumFadeLenght = 50;
|
||||||
|
|
||||||
|
spectrumColor.clear();
|
||||||
|
|
||||||
|
color_t c;
|
||||||
|
c = stringToColor("black");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("blue");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("red");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("magenta");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("green");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("cyan");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("yellow");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
|
||||||
|
c = stringToColor("bright_white");
|
||||||
|
spectrumColor.push_back(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el spectrum fade
|
||||||
|
void Screen::updateSpectrumFade()
|
||||||
|
{
|
||||||
|
if (!spectrumFade)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
spectrumFadeCounter++;
|
||||||
|
if (spectrumFadeCounter > spectrumFadeLenght)
|
||||||
|
{
|
||||||
|
iniSpectrumFade();
|
||||||
|
SDL_SetTextureColorMod(gameCanvas, 255, 255, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el spectrum fade
|
||||||
|
void Screen::renderSpectrumFade()
|
||||||
|
{
|
||||||
|
if (!spectrumFade)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
||||||
|
const int max = spectrumColor.size() - 1;
|
||||||
|
const int index = max + (0 - max) * step;
|
||||||
|
const color_t c = spectrumColor[index];
|
||||||
|
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza los efectos
|
||||||
|
void Screen::updateFX()
|
||||||
|
{
|
||||||
|
updateFade();
|
||||||
|
updateSpectrumFade();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja los efectos
|
||||||
|
void Screen::renderFX()
|
||||||
|
{
|
||||||
|
renderFade();
|
||||||
|
renderSpectrumFade();
|
||||||
}
|
}
|
||||||
105
source/screen.h
105
source/screen.h
@@ -2,35 +2,77 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#ifndef SCREEN_H
|
#ifndef SCREEN_H
|
||||||
#define SCREEN_H
|
#define SCREEN_H
|
||||||
|
|
||||||
|
#define FILTER_NEAREST 0
|
||||||
|
#define FILTER_LINEAL 1
|
||||||
|
|
||||||
|
struct anchor_t
|
||||||
|
{
|
||||||
|
int left; // Parte izquierda de la pantalla de juego
|
||||||
|
int right; // Parte drecha de la pantalla de juego
|
||||||
|
int center; // Parte central horizontal de la pantalla de juego
|
||||||
|
int top; // Parte superior de la pantalla de juego
|
||||||
|
int bottom; // Parte infoerior de la pantalla de juego
|
||||||
|
int middle; // Parte central vertical de la pantalla de juego
|
||||||
|
};
|
||||||
|
|
||||||
// Clase Screen
|
// Clase Screen
|
||||||
class Screen
|
class Screen
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SDL_Window *mWindow; // Ventana de la aplicación
|
SDL_Window *window; // Ventana de la aplicación
|
||||||
SDL_Renderer *mRenderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
SDL_Texture *mGameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||||
options_t *mOptions; // Variable con todas las opciones del programa
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
int mScreenWidth; // Ancho de la pantalla
|
int screenWidth; // Ancho de la pantalla o ventana
|
||||||
int mScreenHeight; // Alto de la pantalla
|
int screenHeight; // Alto de la pantalla o ventana
|
||||||
int mGameCanvasWidth; // Ancho de la textura donde se dibuja el juego
|
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||||
int mGameCanvasHeight; // Alto 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
|
||||||
SDL_Rect mDest; // Coordenadas donde se va a dibujar la textura del juego
|
anchor_t anchor; // Variable con los anclajes de la pantalla
|
||||||
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
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
|
||||||
|
|
||||||
|
// EFECTOS
|
||||||
|
bool fade; // Indica si esta activo el efecto de fade
|
||||||
|
int fadeCounter; // Temporizador para el efecto de fade
|
||||||
|
int fadeLenght; // Duración del fade
|
||||||
|
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
||||||
|
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
||||||
|
int spectrumFadeLenght; // Duración del fade spectrum
|
||||||
|
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade
|
||||||
|
void iniFade();
|
||||||
|
|
||||||
|
// Actualiza el fade
|
||||||
|
void updateFade();
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
void renderFade();
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade spectrum
|
||||||
|
void iniSpectrumFade();
|
||||||
|
|
||||||
|
// Actualiza el spectrum fade
|
||||||
|
void updateSpectrumFade();
|
||||||
|
|
||||||
|
// Dibuja el spectrum fade
|
||||||
|
void renderSpectrumFade();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Screen();
|
~Screen();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void clean(color_t color);
|
void clean(color_t color = {0x00, 0x00, 0x00});
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
void start();
|
void start();
|
||||||
@@ -40,6 +82,45 @@ public:
|
|||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void setVideoMode(int fullScreenMode);
|
void setVideoMode(int fullScreenMode);
|
||||||
|
|
||||||
|
// Camibia entre pantalla completa y ventana
|
||||||
|
void switchVideoMode();
|
||||||
|
|
||||||
|
// Cambia el tamaño de la ventana
|
||||||
|
void setWindowSize(int size);
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
void setBorderColor(color_t color);
|
||||||
|
|
||||||
|
// Cambia el tipo de mezcla
|
||||||
|
void setBlendMode(SDL_BlendMode blendMode);
|
||||||
|
|
||||||
|
// Establece el tamaño del borde
|
||||||
|
void setBorderSize(float s);
|
||||||
|
|
||||||
|
// Establece si se ha de ver el borde en el modo ventana
|
||||||
|
void setBorderEnabled(bool value);
|
||||||
|
|
||||||
|
// Cambia entre borde visible y no visible
|
||||||
|
void switchBorder();
|
||||||
|
|
||||||
|
// Activa el fade
|
||||||
|
void setFade();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el fade
|
||||||
|
bool fadeEnded();
|
||||||
|
|
||||||
|
// Activa el spectrum fade
|
||||||
|
void setspectrumFade();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el spectrum fade
|
||||||
|
bool spectrumFadeEnded();
|
||||||
|
|
||||||
|
// Actualiza los efectos
|
||||||
|
void updateFX();
|
||||||
|
|
||||||
|
// Dibuja los efectos
|
||||||
|
void renderFX();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,20 +32,20 @@ void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
|||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
setEnabledTimer(0);
|
setEnabledTimer(0);
|
||||||
|
|
||||||
mIsOnDestination = false;
|
onDestination = false;
|
||||||
mDestX = 0;
|
destX = 0;
|
||||||
mDestY = 0;
|
destY = 0;
|
||||||
|
|
||||||
setRotate(false);
|
setRotate(false);
|
||||||
setRotateSpeed(0);
|
setRotateSpeed(0);
|
||||||
setRotateAmount(0.0);
|
setRotateAmount(0.0);
|
||||||
|
|
||||||
mCounter = 0;
|
counter = 0;
|
||||||
|
|
||||||
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
|
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
|
||||||
mId = -1;
|
id = -1;
|
||||||
|
|
||||||
mIntroEvents = nullptr;
|
introEvents = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone a cero los elementos del objeto
|
// Pone a cero los elementos del objeto
|
||||||
@@ -57,55 +57,55 @@ void SmartSprite::erase()
|
|||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool SmartSprite::isEnabled()
|
bool SmartSprite::isEnabled()
|
||||||
{
|
{
|
||||||
return mEnabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setEnabled(bool state)
|
void SmartSprite::setEnabled(bool state)
|
||||||
{
|
{
|
||||||
mEnabled = state;
|
enabled = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint16 SmartSprite::getEnabledTimer()
|
Uint16 SmartSprite::getEnabledTimer()
|
||||||
{
|
{
|
||||||
return mEnabledCounter;
|
return enabledCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setEnabledTimer(Uint16 time)
|
void SmartSprite::setEnabledTimer(Uint16 time)
|
||||||
{
|
{
|
||||||
mEnabledCounter = time;
|
enabledCounter = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setDestX(int value)
|
void SmartSprite::setDestX(int value)
|
||||||
{
|
{
|
||||||
mDestX = value;
|
destX = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setDestY(int value)
|
void SmartSprite::setDestY(int value)
|
||||||
{
|
{
|
||||||
mDestY = value;
|
destY = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int SmartSprite::getDestX()
|
int SmartSprite::getDestX()
|
||||||
{
|
{
|
||||||
return mDestX;
|
return destX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int SmartSprite::getDestY()
|
int SmartSprite::getDestY()
|
||||||
{
|
{
|
||||||
return mDestY;
|
return destY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||||
bool SmartSprite::update()
|
bool SmartSprite::update()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
MovingSprite::update();
|
MovingSprite::update();
|
||||||
|
|
||||||
@@ -113,10 +113,10 @@ bool SmartSprite::update()
|
|||||||
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si ha llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosX() > mDestX)
|
if (getPosX() > destX)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
setPosX(mDestX);
|
setPosX(destX);
|
||||||
|
|
||||||
// Lo detiene
|
// Lo detiene
|
||||||
setVelX(0.0f);
|
setVelX(0.0f);
|
||||||
@@ -127,10 +127,10 @@ bool SmartSprite::update()
|
|||||||
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si ha llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosX() < mDestX)
|
if (getPosX() < destX)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
setPosX(mDestX);
|
setPosX(destX);
|
||||||
|
|
||||||
// Lo detiene
|
// Lo detiene
|
||||||
setVelX(0.0f);
|
setVelX(0.0f);
|
||||||
@@ -142,10 +142,10 @@ bool SmartSprite::update()
|
|||||||
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si ha llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosY() > mDestY)
|
if (getPosY() > destY)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
setPosY(mDestY);
|
setPosY(destY);
|
||||||
|
|
||||||
// Lo detiene
|
// Lo detiene
|
||||||
setVelY(0.0f);
|
setVelY(0.0f);
|
||||||
@@ -156,10 +156,10 @@ bool SmartSprite::update()
|
|||||||
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
||||||
{
|
{
|
||||||
// Comprueba si ha llegado al destino
|
// Comprueba si ha llegado al destino
|
||||||
if (getPosY() < mDestY)
|
if (getPosY() < destY)
|
||||||
{
|
{
|
||||||
// Lo coloca en posición
|
// Lo coloca en posición
|
||||||
setPosY(mDestY);
|
setPosY(destY);
|
||||||
|
|
||||||
// Lo detiene
|
// Lo detiene
|
||||||
setVelY(0.0f);
|
setVelY(0.0f);
|
||||||
@@ -168,58 +168,58 @@ bool SmartSprite::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha llegado a su destino
|
// Comprueba si ha llegado a su destino
|
||||||
if ((getPosX() == mDestX) && (getPosY() == mDestY))
|
if ((getPosX() == destX) && (getPosY() == destY))
|
||||||
mIsOnDestination = true;
|
onDestination = true;
|
||||||
else
|
else
|
||||||
mIsOnDestination = false;
|
onDestination = false;
|
||||||
|
|
||||||
// Si esta en el destino comprueba su contador
|
// Si esta en el destino comprueba su contador
|
||||||
if (mIsOnDestination)
|
if (onDestination)
|
||||||
{
|
{
|
||||||
// Si el contador es mayor que cero, lo decrementa
|
// Si el contador es mayor que cero, lo decrementa
|
||||||
if (mEnabledCounter > 0)
|
if (enabledCounter > 0)
|
||||||
{
|
{
|
||||||
mEnabledCounter--;
|
enabledCounter--;
|
||||||
}
|
}
|
||||||
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
|
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
|
||||||
else if (mEnabledCounter == 0)
|
else if (enabledCounter == 0)
|
||||||
{
|
{
|
||||||
if (mId < 0)
|
if (id < 0)
|
||||||
{
|
{
|
||||||
mEnabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mIntroEvents[mId] = EVENT_COMPLETED;
|
introEvents[id] = EVENT_COMPLETED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mIsOnDestination;
|
return onDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool SmartSprite::isOnDestination()
|
bool SmartSprite::isOnDestination()
|
||||||
{
|
{
|
||||||
return mIsOnDestination;
|
return onDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void SmartSprite::render()
|
void SmartSprite::render()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (enabled)
|
||||||
MovingSprite::render();
|
MovingSprite::render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setId(int id)
|
void SmartSprite::setId(int id)
|
||||||
{
|
{
|
||||||
mId = id;
|
id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void SmartSprite::setIntroEvents(Uint8 *value)
|
void SmartSprite::setIntroEvents(Uint8 *value)
|
||||||
{
|
{
|
||||||
mIntroEvents = value;
|
introEvents = value;
|
||||||
}
|
}
|
||||||
@@ -11,13 +11,13 @@
|
|||||||
class SmartSprite : public AnimatedSprite
|
class SmartSprite : public AnimatedSprite
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool mEnabled; // Indica si esta habilitado
|
bool enabled; // Indica si esta habilitado
|
||||||
bool mIsOnDestination; // Indica si está en el destino
|
bool onDestination; // Indica si está en el destino
|
||||||
int mDestX; // Posicion de destino en el eje X
|
int destX; // Posicion de destino en el eje X
|
||||||
int mDestY; // Posicion de destino en el eje Y
|
int destY; // Posicion de destino en el eje Y
|
||||||
int mId; // Identificador
|
int id; // Identificador
|
||||||
Uint16 mEnabledCounter; // Contador para deshabilitarlo
|
Uint16 enabledCounter; // Contador para deshabilitarlo
|
||||||
Uint8 *mIntroEvents; // Dirección del array de eventos donde notificar el estado
|
Uint8 *introEvents; // Dirección del array de eventos donde notificar el estado
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|||||||
@@ -17,21 +17,19 @@ Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *
|
|||||||
mFade = new Fade(renderer);
|
mFade = new Fade(renderer);
|
||||||
mTitleTexture = new LTexture(mRenderer);
|
mTitleTexture = new LTexture(mRenderer);
|
||||||
mItemsTexture = new LTexture(mRenderer);
|
mItemsTexture = new LTexture(mRenderer);
|
||||||
mTextTexture = new LTexture(mRenderer);
|
|
||||||
mTextTexture2 = new LTexture(mRenderer);
|
|
||||||
mCoffeeBitmap = new SmartSprite();
|
mCoffeeBitmap = new SmartSprite();
|
||||||
mCrisisBitmap = new SmartSprite();
|
mCrisisBitmap = new SmartSprite();
|
||||||
mDustBitmapL = new AnimatedSprite();
|
mDustBitmapL = new AnimatedSprite();
|
||||||
mDustBitmapR = new AnimatedSprite();
|
mDustBitmapR = new AnimatedSprite();
|
||||||
mTile = new Sprite();
|
mTile = new Sprite();
|
||||||
mGradient = new Sprite();
|
mGradient = new Sprite();
|
||||||
mText = new Text(mAsset->get("smb2.txt"), mTextTexture, mRenderer);
|
mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer);
|
||||||
mText2 = new Text(mAsset->get("8bithud.txt"), mTextTexture2, mRenderer);
|
mText2 = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer);
|
||||||
mMenu.title = new Menu(mRenderer, mText, mInput, mAsset);
|
mMenu.title = new Menu(mRenderer, mText, mInput, mAsset);
|
||||||
mMenu.options = new Menu(mRenderer, mText, mInput, mAsset);
|
mMenu.options = new Menu(mRenderer, mText, mInput, mAsset);
|
||||||
|
|
||||||
// Crea la textura para el mosaico de fondo
|
// Crea la textura para el mosaico de fondo
|
||||||
mBackground = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2);
|
mBackground = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH * 2, GAME_HEIGHT * 2);
|
||||||
if (mBackground == nullptr)
|
if (mBackground == nullptr)
|
||||||
{
|
{
|
||||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||||
@@ -243,8 +241,8 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar
|
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar
|
||||||
mBackgroundWindow.x = 128;
|
mBackgroundWindow.x = 128;
|
||||||
mBackgroundWindow.y = 96;
|
mBackgroundWindow.y = 96;
|
||||||
mBackgroundWindow.w = SCREEN_WIDTH;
|
mBackgroundWindow.w = GAME_WIDTH;
|
||||||
mBackgroundWindow.h = SCREEN_HEIGHT;
|
mBackgroundWindow.h = GAME_HEIGHT;
|
||||||
|
|
||||||
// Inicializa los valores del vector con los valores del seno
|
// Inicializa los valores del vector con los valores del seno
|
||||||
for (int i = 0; i < 360; i++)
|
for (int i = 0; i < 360; i++)
|
||||||
@@ -862,7 +860,7 @@ section_t Title::run(Uint8 subsection)
|
|||||||
mCrisisBitmap->render();
|
mCrisisBitmap->render();
|
||||||
|
|
||||||
// Texto con el copyright y versión
|
// Texto con el copyright y versión
|
||||||
mText2->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, SCREEN_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor);
|
mText2->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMenuVisible == true)
|
if (mMenuVisible == true)
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ private:
|
|||||||
JA_Sound mSound; // Sonido con el impacto del título
|
JA_Sound mSound; // Sonido con el impacto del título
|
||||||
LTexture *mItemsTexture; // Textura con los gráficos de los items para las instrucciones
|
LTexture *mItemsTexture; // Textura con los gráficos de los items para las instrucciones
|
||||||
LTexture *mTitleTexture; // Textura con los graficos para el titulo
|
LTexture *mTitleTexture; // Textura con los graficos para el titulo
|
||||||
LTexture *mTextTexture; // Textura con los gráficos para el texto
|
|
||||||
LTexture *mTextTexture2; // Textura con los gráficos para el texto
|
|
||||||
SDL_Event *mEventHandler; // Manejador de eventos
|
SDL_Event *mEventHandler; // Manejador de eventos
|
||||||
SDL_Rect mBackgroundWindow; // Ventana visible para la textura de fondo del titulo
|
SDL_Rect mBackgroundWindow; // Ventana visible para la textura de fondo del titulo
|
||||||
SDL_Texture *mBackground; // Textura dibujar el fondo del titulo
|
SDL_Texture *mBackground; // Textura dibujar el fondo del titulo
|
||||||
|
|||||||
517
source/utils.cpp
517
source/utils.cpp
@@ -1,10 +1,11 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||||
{
|
{
|
||||||
int deltaX = x2 - x1;
|
const int deltaX = x2 - x1;
|
||||||
int deltaY = y2 - y1;
|
const int deltaY = y2 - y1;
|
||||||
return deltaX * deltaX + deltaY * deltaY;
|
return deltaX * deltaX + deltaY * deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +18,10 @@ bool checkCollision(circle_t &a, circle_t &b)
|
|||||||
|
|
||||||
// Si la distancia entre el centro de los circulos es inferior a la suma de sus radios
|
// Si la distancia entre el centro de los circulos es inferior a la suma de sus radios
|
||||||
if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared))
|
if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared))
|
||||||
return true; // Los circulos han colisionado
|
{
|
||||||
|
// Los circulos han colisionado
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// En caso contrario
|
// En caso contrario
|
||||||
return false;
|
return false;
|
||||||
@@ -26,10 +30,10 @@ bool checkCollision(circle_t &a, circle_t &b)
|
|||||||
// Detector de colisiones entre un circulo y un rectangulo
|
// Detector de colisiones entre un circulo y un rectangulo
|
||||||
bool checkCollision(circle_t &a, SDL_Rect &b)
|
bool checkCollision(circle_t &a, SDL_Rect &b)
|
||||||
{
|
{
|
||||||
//Closest point on collision box
|
// Closest point on collision box
|
||||||
int cX, cY;
|
int cX, cY;
|
||||||
|
|
||||||
//Find closest x offset
|
// Find closest x offset
|
||||||
if (a.x < b.x)
|
if (a.x < b.x)
|
||||||
{
|
{
|
||||||
cX = b.x;
|
cX = b.x;
|
||||||
@@ -43,7 +47,7 @@ bool checkCollision(circle_t &a, SDL_Rect &b)
|
|||||||
cX = a.x;
|
cX = a.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Find closest y offset
|
// Find closest y offset
|
||||||
if (a.y < b.y)
|
if (a.y < b.y)
|
||||||
{
|
{
|
||||||
cY = b.y;
|
cY = b.y;
|
||||||
@@ -57,33 +61,33 @@ bool checkCollision(circle_t &a, SDL_Rect &b)
|
|||||||
cY = a.y;
|
cY = a.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the closest point is inside the circle_t
|
// If the closest point is inside the circle_t
|
||||||
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
|
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
|
||||||
{
|
{
|
||||||
//This box and the circle_t have collided
|
// This box and the circle_t have collided
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the shapes have not collided
|
// If the shapes have not collided
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detector de colisiones entre un dos rectangulos
|
// Detector de colisiones entre dos rectangulos
|
||||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
||||||
{
|
{
|
||||||
//Calculate the sides of rect A
|
// Calcula las caras del rectangulo a
|
||||||
int leftA = a.x;
|
const int leftA = a.x;
|
||||||
int rightA = a.x + a.w;
|
const int rightA = a.x + a.w;
|
||||||
int topA = a.y;
|
const int topA = a.y;
|
||||||
int bottomA = a.y + a.h;
|
const int bottomA = a.y + a.h;
|
||||||
|
|
||||||
//Calculate the sides of rect B
|
// Calcula las caras del rectangulo b
|
||||||
int leftB = b.x;
|
const int leftB = b.x;
|
||||||
int rightB = b.x + b.w;
|
const int rightB = b.x + b.w;
|
||||||
int topB = b.y;
|
const int topB = b.y;
|
||||||
int bottomB = b.y + b.h;
|
const int bottomB = b.y + b.h;
|
||||||
|
|
||||||
//If any of the sides from A are outside of B
|
// Si cualquiera de las caras de a está fuera de b
|
||||||
if (bottomA <= topB)
|
if (bottomA <= topB)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -104,18 +108,473 @@ bool checkCollision(SDL_Rect &a, SDL_Rect &b)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If none of the sides from A are outside B
|
// Si ninguna de las caras está fuera de b
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga un archivo de imagen en una textura
|
// Detector de colisiones entre un punto y un rectangulo
|
||||||
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer)
|
bool checkCollision(SDL_Point &p, SDL_Rect &r)
|
||||||
{
|
{
|
||||||
bool success = true;
|
// Comprueba si el punto está a la izquierda del rectangulo
|
||||||
if (!texture->loadFromFile(path, renderer))
|
if (p.x < r.x)
|
||||||
{
|
{
|
||||||
printf("Failed to load %s texture!\n", path.c_str());
|
return false;
|
||||||
success = false;
|
}
|
||||||
|
|
||||||
|
// Comprueba si el punto está a la derecha del rectangulo
|
||||||
|
if (p.x > r.x + r.w)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el punto está por encima del rectangulo
|
||||||
|
if (p.y < r.y)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el punto está por debajo del rectangulo
|
||||||
|
if (p.y > r.y + r.h)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si no está fuera, es que está dentro
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea horizontal y un rectangulo
|
||||||
|
bool checkCollision(h_line_t &l, SDL_Rect &r)
|
||||||
|
{
|
||||||
|
// Comprueba si la linea esta por encima del rectangulo
|
||||||
|
if (l.y < r.y)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si la linea esta por debajo del rectangulo
|
||||||
|
if (l.y >= r.y + r.h)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el inicio de la linea esta a la derecha del rectangulo
|
||||||
|
if (l.x1 >= r.x + r.w)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el final de la linea esta a la izquierda del rectangulo
|
||||||
|
if (l.x2 < r.x)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si ha llegado hasta aquí, hay colisión
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea vertical y un rectangulo
|
||||||
|
bool checkCollision(v_line_t &l, SDL_Rect &r)
|
||||||
|
{
|
||||||
|
// Comprueba si la linea esta por la izquierda del rectangulo
|
||||||
|
if (l.x < r.x)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si la linea esta por la derecha del rectangulo
|
||||||
|
if (l.x >= r.x + r.w)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el inicio de la linea esta debajo del rectangulo
|
||||||
|
if (l.y1 >= r.y + r.h)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el final de la linea esta encima del rectangulo
|
||||||
|
if (l.y2 < r.y)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si ha llegado hasta aquí, hay colisión
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea horizontal y un punto
|
||||||
|
bool checkCollision(h_line_t &l, SDL_Point &p)
|
||||||
|
{
|
||||||
|
// Comprueba si el punto esta sobre la linea
|
||||||
|
if (p.y > l.y)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el punto esta bajo la linea
|
||||||
|
if (p.y < l.y)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el punto esta a la izquierda de la linea
|
||||||
|
if (p.x < l.x1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si el punto esta a la derecha de la linea
|
||||||
|
if (p.x > l.x2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si ha llegado aquí, hay colisión
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre dos lineas
|
||||||
|
SDL_Point checkCollision(line_t &l1, line_t &l2)
|
||||||
|
{
|
||||||
|
const float x1 = l1.x1;
|
||||||
|
const float y1 = l1.y1;
|
||||||
|
const float x2 = l1.x2;
|
||||||
|
const float y2 = l1.y2;
|
||||||
|
|
||||||
|
const float x3 = l2.x1;
|
||||||
|
const float y3 = l2.y1;
|
||||||
|
const float x4 = l2.x2;
|
||||||
|
const float y4 = l2.y2;
|
||||||
|
|
||||||
|
// calculate the direction of the lines
|
||||||
|
float uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
|
||||||
|
float uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
|
||||||
|
|
||||||
|
// if uA and uB are between 0-1, lines are colliding
|
||||||
|
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1)
|
||||||
|
{
|
||||||
|
// Calcula la intersección
|
||||||
|
const float x = x1 + (uA * (x2 - x1));
|
||||||
|
const float y = y1 + (uA * (y2 - y1));
|
||||||
|
|
||||||
|
return {(int)round(x), (int)round(y)};
|
||||||
|
}
|
||||||
|
return {-1, -1};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre dos lineas
|
||||||
|
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2)
|
||||||
|
{
|
||||||
|
const float x1 = l1.x1;
|
||||||
|
const float y1 = l1.y1;
|
||||||
|
const float x2 = l1.x2;
|
||||||
|
const float y2 = l1.y2;
|
||||||
|
|
||||||
|
const float x3 = l2.x;
|
||||||
|
const float y3 = l2.y1;
|
||||||
|
const float x4 = l2.x;
|
||||||
|
const float y4 = l2.y2;
|
||||||
|
|
||||||
|
// calculate the direction of the lines
|
||||||
|
float uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
|
||||||
|
float uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
|
||||||
|
|
||||||
|
// if uA and uB are between 0-1, lines are colliding
|
||||||
|
if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1)
|
||||||
|
{
|
||||||
|
// Calcula la intersección
|
||||||
|
const float x = x1 + (uA * (x2 - x1));
|
||||||
|
const float y = y1 + (uA * (y2 - y1));
|
||||||
|
|
||||||
|
return {(int)x, (int)y};
|
||||||
|
}
|
||||||
|
return {-1, -1};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea diagonal y una vertical
|
||||||
|
/*bool checkCollision(d_line_t &l1, v_line_t &l2)
|
||||||
|
{
|
||||||
|
// Normaliza la linea diagonal
|
||||||
|
normalizeLine(l1);
|
||||||
|
|
||||||
|
// Comprueba si la linea vertical esta a la izquierda de la linea diagonal
|
||||||
|
if (l2.x < l1.x1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si la linea vertical esta a la derecha de la linea diagonal
|
||||||
|
if (l2.x > l1.x2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inacabada
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Normaliza una linea diagonal
|
||||||
|
void normalizeLine(d_line_t &l)
|
||||||
|
{
|
||||||
|
// Las lineas diagonales van de izquierda a derecha
|
||||||
|
// x2 mayor que x1
|
||||||
|
if (l.x2 < l.x1)
|
||||||
|
{
|
||||||
|
const int x = l.x1;
|
||||||
|
const int y = l.y1;
|
||||||
|
l.x1 = l.x2;
|
||||||
|
l.y1 = l.y2;
|
||||||
|
l.x2 = x;
|
||||||
|
l.y2 = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detector de colisiones entre un punto y una linea diagonal
|
||||||
|
bool checkCollision(SDL_Point &p, d_line_t &l)
|
||||||
|
{
|
||||||
|
// Comprueba si el punto está en alineado con la linea
|
||||||
|
if (abs(p.x - l.x1) != abs(p.y - l.y1))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si está a la derecha de la linea
|
||||||
|
if (p.x > l.x1 && p.x > l.x2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si está a la izquierda de la linea
|
||||||
|
if (p.x < l.x1 && p.x < l.x2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si está por encima de la linea
|
||||||
|
if (p.y > l.y1 && p.y > l.y2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si está por debajo de la linea
|
||||||
|
if (p.y < l.y1 && p.y < l.y2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// En caso contrario, el punto está en la linea
|
||||||
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
/*const int m = (l.y2 - l.y1) / (l.x2 - l.x1);
|
||||||
|
const int c = 0;
|
||||||
|
|
||||||
|
// Comprueba si p cumple la ecuación de la linea
|
||||||
|
if (p.y == ((m * p.x) + c))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve un color_t a partir de un string
|
||||||
|
color_t stringToColor(std::string str)
|
||||||
|
{
|
||||||
|
const std::string palette = "spectrum";
|
||||||
|
|
||||||
|
if (palette == "spectrum")
|
||||||
|
{
|
||||||
|
if (str == "black")
|
||||||
|
{
|
||||||
|
return {0x00, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_black")
|
||||||
|
{
|
||||||
|
return {0x00, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "blue")
|
||||||
|
{
|
||||||
|
return {0x00, 0x00, 0xd8};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_blue")
|
||||||
|
{
|
||||||
|
return {0x00, 0x00, 0xFF};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "red")
|
||||||
|
{
|
||||||
|
return {0xd8, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_red")
|
||||||
|
{
|
||||||
|
return {0xFF, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "magenta")
|
||||||
|
{
|
||||||
|
return {0xd8, 0x00, 0xd8};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_magenta")
|
||||||
|
{
|
||||||
|
return {0xFF, 0x00, 0xFF};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "green")
|
||||||
|
{
|
||||||
|
return {0x00, 0xd8, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_green")
|
||||||
|
{
|
||||||
|
return {0x00, 0xFF, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "cyan")
|
||||||
|
{
|
||||||
|
return {0x00, 0xd8, 0xd8};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_cyan")
|
||||||
|
{
|
||||||
|
return {0x00, 0xFF, 0xFF};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "yellow")
|
||||||
|
{
|
||||||
|
return {0xd8, 0xd8, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_yellow")
|
||||||
|
{
|
||||||
|
return {0xFF, 0xFF, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "white")
|
||||||
|
{
|
||||||
|
return {0xd8, 0xd8, 0xd8};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_white")
|
||||||
|
{
|
||||||
|
return {0xFF, 0xFF, 0xFF};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{ // zxarne
|
||||||
|
if (str == "black")
|
||||||
|
{
|
||||||
|
return {0x00, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_black")
|
||||||
|
{
|
||||||
|
return {0x3C, 0x35, 0x1F};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "blue")
|
||||||
|
{
|
||||||
|
return {0x31, 0x33, 0x90};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_blue")
|
||||||
|
{
|
||||||
|
return {0x15, 0x59, 0xDB};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "red")
|
||||||
|
{
|
||||||
|
return {0xA7, 0x32, 0x11};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_red")
|
||||||
|
{
|
||||||
|
return {0xD8, 0x55, 0x25};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "magenta")
|
||||||
|
{
|
||||||
|
return {0xA1, 0x55, 0x89};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_magenta")
|
||||||
|
{
|
||||||
|
return {0xCD, 0x7A, 0x50};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "green")
|
||||||
|
{
|
||||||
|
return {0x62, 0x9A, 0x31};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_green")
|
||||||
|
{
|
||||||
|
return {0x9C, 0xD3, 0x3C};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "cyan")
|
||||||
|
{
|
||||||
|
return {0x28, 0xA4, 0xCB};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_cyan")
|
||||||
|
{
|
||||||
|
return {0x65, 0xDC, 0xD6};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "yellow")
|
||||||
|
{
|
||||||
|
return {0xE8, 0xBC, 0x50};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_yellow")
|
||||||
|
{
|
||||||
|
return {0xF1, 0xE7, 0x82};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "white")
|
||||||
|
{
|
||||||
|
return {0xBF, 0xBF, 0xBD};
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (str == "bright_white")
|
||||||
|
{
|
||||||
|
return {0xF2, 0xF1, 0xED};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {0x00, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convierte una cadena en un valor booleano
|
||||||
|
bool stringToBool(std::string str)
|
||||||
|
{
|
||||||
|
if (str == "true")
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convierte un valor booleano en una cadena
|
||||||
|
std::string boolToString(bool value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "false";
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,30 @@ struct circle_t
|
|||||||
int r;
|
int r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Estructura para definir una linea horizontal
|
||||||
|
struct h_line_t
|
||||||
|
{
|
||||||
|
int x1, x2, y;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para definir una linea vertical
|
||||||
|
struct v_line_t
|
||||||
|
{
|
||||||
|
int x, y1, y2;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para definir una linea diagonal
|
||||||
|
struct d_line_t
|
||||||
|
{
|
||||||
|
int x1, y1, x2, y2;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para definir una linea
|
||||||
|
struct line_t
|
||||||
|
{
|
||||||
|
int x1, y1, x2, y2;
|
||||||
|
};
|
||||||
|
|
||||||
// Estructura para definir un color
|
// Estructura para definir un color
|
||||||
struct color_t
|
struct color_t
|
||||||
{
|
{
|
||||||
@@ -72,6 +96,8 @@ struct options_t
|
|||||||
int screenHeight; // Alto de la pantalla/ventana
|
int screenHeight; // Alto de la pantalla/ventana
|
||||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
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 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
|
||||||
|
float borderSize; // Porcentaje de borde que se añade a lo ventana
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
@@ -84,9 +110,39 @@ bool checkCollision(circle_t &a, circle_t &b);
|
|||||||
bool checkCollision(circle_t &a, SDL_Rect &b);
|
bool checkCollision(circle_t &a, SDL_Rect &b);
|
||||||
|
|
||||||
// Detector de colisiones entre un dos rectangulos
|
// Detector de colisiones entre un dos rectangulos
|
||||||
bool checkCollision(SDL_Rect a, SDL_Rect b);
|
bool checkCollision(SDL_Rect &a, SDL_Rect &b);
|
||||||
|
|
||||||
// Carga un archivo de imagen en una textura
|
// Detector de colisiones entre un punto y un rectangulo
|
||||||
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer);
|
bool checkCollision(SDL_Point &p, SDL_Rect &r);
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea horizontal y un rectangulo
|
||||||
|
bool checkCollision(h_line_t &l, SDL_Rect &r);
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea vertical y un rectangulo
|
||||||
|
bool checkCollision(v_line_t &l, SDL_Rect &r);
|
||||||
|
|
||||||
|
// Detector de colisiones entre una linea horizontal y un punto
|
||||||
|
bool checkCollision(h_line_t &l, SDL_Point &p);
|
||||||
|
|
||||||
|
// Detector de colisiones entre dos lineas
|
||||||
|
SDL_Point checkCollision(line_t &l1, line_t &l2);
|
||||||
|
|
||||||
|
// Detector de colisiones entre dos lineas
|
||||||
|
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2);
|
||||||
|
|
||||||
|
// Detector de colisiones entre un punto y una linea diagonal
|
||||||
|
bool checkCollision(SDL_Point &p, d_line_t &l);
|
||||||
|
|
||||||
|
// Normaliza una linea diagonal
|
||||||
|
void normalizeLine(d_line_t &l);
|
||||||
|
|
||||||
|
// Devuelve un color_t a partir de un string
|
||||||
|
color_t stringToColor(std::string str);
|
||||||
|
|
||||||
|
// Convierte una cadena en un valor booleano
|
||||||
|
bool stringToBool(std::string str);
|
||||||
|
|
||||||
|
// Convierte un valor booleano en una cadena
|
||||||
|
std::string boolToString(bool value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user