Compare commits
2 Commits
b092d3f86a
...
c8bebfd2d9
| Author | SHA1 | Date | |
|---|---|---|---|
| c8bebfd2d9 | |||
| 35e7abcd3c |
BIN
data/config/config.bin
Normal file
BIN
data/config/score.bin
Normal file
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 795 B After Width: | Height: | Size: 795 B |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 785 B After Width: | Height: | Size: 785 B |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 654 B After Width: | Height: | Size: 654 B |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
@@ -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);
|
||||||
|
|||||||
@@ -2,22 +2,11 @@
|
|||||||
#include "balloon.h"
|
#include "balloon.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon::Balloon()
|
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
mSprite = new AnimatedSprite();
|
mSprite = new AnimatedSprite();
|
||||||
disable();
|
disable();
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Balloon::~Balloon()
|
|
||||||
{
|
|
||||||
delete mSprite;
|
|
||||||
mSprite = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializador
|
|
||||||
void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
|
|
||||||
{
|
|
||||||
const Uint8 NUM_FRAMES_BALLON = 10;
|
const Uint8 NUM_FRAMES_BALLON = 10;
|
||||||
const Uint8 NUM_FRAMES_BALLON_POP = 12;
|
const Uint8 NUM_FRAMES_BALLON_POP = 12;
|
||||||
const Uint8 NUM_FRAMES_BALLON_BORN = 10;
|
const Uint8 NUM_FRAMES_BALLON_BORN = 10;
|
||||||
@@ -435,6 +424,13 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
|
|||||||
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Balloon::~Balloon()
|
||||||
|
{
|
||||||
|
delete mSprite;
|
||||||
|
mSprite = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void Balloon::allignTo(int x)
|
void Balloon::allignTo(int x)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -146,14 +146,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Balloon();
|
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Balloon();
|
~Balloon();
|
||||||
|
|
||||||
// Inicializador
|
|
||||||
void init(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
|
|
||||||
|
|
||||||
// Centra el globo en la posición X
|
// Centra el globo en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,175 +177,100 @@ bool Director::initSDL()
|
|||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
bool Director::setFileList()
|
bool Director::setFileList()
|
||||||
{
|
{
|
||||||
// Ficheros binarios
|
// Ficheros de configuración
|
||||||
mAsset->add("data/score.bin", data, false);
|
asset->add("data/config/score.bin", t_data, false);
|
||||||
mAsset->add("data/demo.bin", data);
|
asset->add("data/config/demo.bin", t_data);
|
||||||
mAsset->add("data/config.bin", data, false);
|
asset->add("data/config/config.bin", t_data, false);
|
||||||
|
asset->add("data/config/gamecontrollerdb.txt", t_data);
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
mAsset->add("media/music/intro.ogg", music);
|
asset->add("data/music/intro.ogg", t_music);
|
||||||
mAsset->add("media/music/playing.ogg", music);
|
asset->add("data/music/playing.ogg", t_music);
|
||||||
mAsset->add("media/music/title.ogg", music);
|
asset->add("data/music/title.ogg", t_music);
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
mAsset->add("media/sound/balloon.wav", sound);
|
asset->add("data/sound/balloon.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble1.wav", sound);
|
asset->add("data/sound/bubble1.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble2.wav", sound);
|
asset->add("data/sound/bubble2.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble3.wav", sound);
|
asset->add("data/sound/bubble3.wav", t_sound);
|
||||||
mAsset->add("media/sound/bubble4.wav", sound);
|
asset->add("data/sound/bubble4.wav", t_sound);
|
||||||
mAsset->add("media/sound/bullet.wav", sound);
|
asset->add("data/sound/bullet.wav", t_sound);
|
||||||
mAsset->add("media/sound/coffeeout.wav", sound);
|
asset->add("data/sound/coffeeout.wav", t_sound);
|
||||||
mAsset->add("media/sound/hiscore.wav", sound);
|
asset->add("data/sound/hiscore.wav", t_sound);
|
||||||
mAsset->add("media/sound/itemdrop.wav", sound);
|
asset->add("data/sound/itemdrop.wav", t_sound);
|
||||||
mAsset->add("media/sound/itempickup.wav", sound);
|
asset->add("data/sound/itempickup.wav", t_sound);
|
||||||
mAsset->add("media/sound/menu_cancel.wav", sound);
|
asset->add("data/sound/menu_cancel.wav", t_sound);
|
||||||
mAsset->add("media/sound/menu_move.wav", sound);
|
asset->add("data/sound/menu_move.wav", t_sound);
|
||||||
mAsset->add("media/sound/menu_select.wav", sound);
|
asset->add("data/sound/menu_select.wav", t_sound);
|
||||||
mAsset->add("media/sound/player_collision.wav", sound);
|
asset->add("data/sound/player_collision.wav", t_sound);
|
||||||
mAsset->add("media/sound/stage_change.wav", sound);
|
asset->add("data/sound/stage_change.wav", t_sound);
|
||||||
mAsset->add("media/sound/title.wav", sound);
|
asset->add("data/sound/title.wav", t_sound);
|
||||||
mAsset->add("media/sound/clock.wav", sound);
|
asset->add("data/sound/clock.wav", t_sound);
|
||||||
mAsset->add("media/sound/powerball.wav", sound);
|
asset->add("data/sound/powerball.wav", t_sound);
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
mAsset->add("media/gfx/balloon.png", bitmap);
|
asset->add("data/gfx/balloon.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/bullet.png", bitmap);
|
asset->add("data/gfx/bullet.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/game_bg.png", bitmap);
|
asset->add("data/gfx/game_bg.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/game_text.png", bitmap);
|
asset->add("data/gfx/game_text.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/intro.png", bitmap);
|
asset->add("data/gfx/intro.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/items.png", bitmap);
|
asset->add("data/gfx/items.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/logo.png", bitmap);
|
asset->add("data/gfx/logo.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_body.png", bitmap);
|
asset->add("data/gfx/player1_body.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_death.png", bitmap);
|
asset->add("data/gfx/player1_death.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_legs.png", bitmap);
|
asset->add("data/gfx/player1_legs.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/title.png", bitmap);
|
asset->add("data/gfx/title.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player1_head.png", bitmap);
|
asset->add("data/gfx/player1_head.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_body.png", bitmap);
|
asset->add("data/gfx/player2_body.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_death.png", bitmap);
|
asset->add("data/gfx/player2_death.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_legs.png", bitmap);
|
asset->add("data/gfx/player2_legs.png", t_bitmap);
|
||||||
mAsset->add("media/gfx/player2_head.png", bitmap);
|
asset->add("data/gfx/player2_head.png", t_bitmap);
|
||||||
|
|
||||||
// Fuentes
|
// Fuentes
|
||||||
mAsset->add("media/font/8bithud.png", font);
|
asset->add("data/font/8bithud.png", t_font);
|
||||||
mAsset->add("media/font/8bithud.txt", font);
|
asset->add("data/font/8bithud.txt", t_font);
|
||||||
mAsset->add("media/font/nokia.png", font);
|
asset->add("data/font/nokia.png", t_font);
|
||||||
mAsset->add("media/font/nokia_big2.png", font);
|
asset->add("data/font/nokia_big2.png", t_font);
|
||||||
mAsset->add("media/font/nokia.txt", font);
|
asset->add("data/font/nokia.txt", t_font);
|
||||||
mAsset->add("media/font/nokia2.png", font);
|
asset->add("data/font/nokia2.png", t_font);
|
||||||
mAsset->add("media/font/nokia2.txt", font);
|
asset->add("data/font/nokia2.txt", t_font);
|
||||||
mAsset->add("media/font/nokia_big2.txt", font);
|
asset->add("data/font/nokia_big2.txt", t_font);
|
||||||
mAsset->add("media/font/smb2_big.png", font);
|
asset->add("data/font/smb2_big.png", t_font);
|
||||||
mAsset->add("media/font/smb2_big.txt", font);
|
asset->add("data/font/smb2_big.txt", t_font);
|
||||||
mAsset->add("media/font/smb2.png", font);
|
asset->add("data/font/smb2.png", t_font);
|
||||||
mAsset->add("media/font/smb2.txt", font);
|
asset->add("data/font/smb2.txt", t_font);
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
mAsset->add("media/lang/es_ES.txt", lang);
|
asset->add("data/lang/es_ES.txt", t_lang);
|
||||||
mAsset->add("media/lang/en_UK.txt", lang);
|
asset->add("data/lang/en_UK.txt", t_lang);
|
||||||
mAsset->add("media/lang/ba_BA.txt", lang);
|
asset->add("data/lang/ba_BA.txt", t_lang);
|
||||||
|
|
||||||
// DATA
|
return asset->check();
|
||||||
mAsset->add("data/gamecontrollerdb.txt", data);
|
|
||||||
|
|
||||||
return mAsset->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 +286,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 +313,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 +347,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 +381,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
|
||||||
|
|||||||
409
source/game.cpp
@@ -24,7 +24,21 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
mDifficulty = mOptions->difficulty;
|
mDifficulty = mOptions->difficulty;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
// Vector de jugadores
|
||||||
|
if (mNumPlayers == 1)
|
||||||
|
{
|
||||||
|
Player *player = new Player(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer1Legs, mTexturePlayer1Body, mTexturePlayer1Head, mTexturePlayer1Death, mRenderer);
|
||||||
|
players.push_back(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (mNumPlayers == 2)
|
||||||
|
{
|
||||||
|
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer1Legs, mTexturePlayer1Body, mTexturePlayer1Head, mTexturePlayer1Death, mRenderer);
|
||||||
|
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer2Legs, mTexturePlayer2Body, mTexturePlayer2Head, mTexturePlayer2Death, mRenderer);
|
||||||
|
players.push_back(player1);
|
||||||
|
players.push_back(player2);
|
||||||
|
}
|
||||||
|
/*for (int i = 0; i < mNumPlayers; i++)
|
||||||
{
|
{
|
||||||
mPlayer[i] = new Player();
|
mPlayer[i] = new Player();
|
||||||
}
|
}
|
||||||
@@ -41,27 +55,29 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
|
|
||||||
for (int i = 0; i < MAX_ITEMS; i++)
|
for (int i = 0; i < MAX_ITEMS; i++)
|
||||||
{
|
{
|
||||||
mItem[i] = new Item();
|
mItem[i] = new Item(mTextureItems, mRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MAX_SMART_SPRITES; i++)
|
for (int i = 0; i < MAX_SMART_SPRITES; i++)
|
||||||
{
|
{
|
||||||
mSmartSprite[i] = new SmartSprite();
|
mSmartSprite[i] = new SmartSprite(nullptr, mRenderer);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
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);
|
||||||
@@ -79,15 +95,17 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
|
|||||||
mClouds1b = new MovingSprite(256, 0, 256, 52, -0.4f, 0.0f, 0.0f, 0.0f, mTextureGameBG, mRenderer);
|
mClouds1b = new MovingSprite(256, 0, 256, 52, -0.4f, 0.0f, 0.0f, 0.0f, mTextureGameBG, mRenderer);
|
||||||
mClouds2a = new MovingSprite(0, 52, 256, 32, -0.2f, 0.0f, 0.0f, 0.0f, mTextureGameBG, mRenderer);
|
mClouds2a = new MovingSprite(0, 52, 256, 32, -0.2f, 0.0f, 0.0f, 0.0f, mTextureGameBG, mRenderer);
|
||||||
mClouds2b = new MovingSprite(256, 52, 256, 32, -0.2f, 0.0f, 0.0f, 0.0f, mTextureGameBG, mRenderer);
|
mClouds2b = new MovingSprite(256, 52, 256, 32, -0.2f, 0.0f, 0.0f, 0.0f, mTextureGameBG, mRenderer);
|
||||||
m1000Bitmap = new SmartSprite();
|
|
||||||
m2500Bitmap = new SmartSprite();
|
m1000Bitmap = new SmartSprite(mTextureGameText, mRenderer);
|
||||||
m5000Bitmap = new SmartSprite();
|
m2500Bitmap = new SmartSprite(mTextureGameText, mRenderer);
|
||||||
mSpriteBackground = new Sprite(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, mTextureGameBG, mRenderer);
|
m5000Bitmap = new SmartSprite(mTextureGameText, 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()
|
||||||
@@ -103,35 +121,30 @@ Game::~Game()
|
|||||||
mLang = nullptr;
|
mLang = nullptr;
|
||||||
mInput = nullptr;
|
mInput = nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
for (auto player : players)
|
||||||
{
|
{
|
||||||
delete mPlayer[i];
|
delete player;
|
||||||
mPlayer[i] = nullptr;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_BALLOONS; i++)
|
for (auto ballon : ballons)
|
||||||
{
|
{
|
||||||
delete mBalloon[i];
|
delete ballon;
|
||||||
mBalloon[i] = nullptr;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_BULLETS; i++)
|
for (auto bullet : bullets)
|
||||||
{
|
{
|
||||||
delete mBullet[i];
|
delete bullet;
|
||||||
mBullet[i] = nullptr;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_ITEMS; i++)
|
for (auto item : items)
|
||||||
{
|
{
|
||||||
delete mItem[i];
|
delete item;
|
||||||
mItem[i] = nullptr;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_SMART_SPRITES; i++)
|
for (auto smartSprite : smartSprites)
|
||||||
{
|
{
|
||||||
delete mSmartSprite[i];
|
delete smartSprite;
|
||||||
mSmartSprite[i] = nullptr;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
mTextureBalloon->unload();
|
mTextureBalloon->unload();
|
||||||
delete mTextureBalloon;
|
delete mTextureBalloon;
|
||||||
@@ -275,7 +288,9 @@ void Game::initSin()
|
|||||||
{
|
{
|
||||||
// Vector con los valores del seno para 360 grados
|
// Vector con los valores del seno para 360 grados
|
||||||
for (int i = 0; i < 360; i++)
|
for (int i = 0; i < 360; i++)
|
||||||
|
{
|
||||||
mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Game'
|
// Inicializa las variables necesarias para la sección 'Game'
|
||||||
@@ -426,18 +441,6 @@ void Game::init()
|
|||||||
mSpriteScoreBoard->setSpriteClip(0, 160, 256, 32);
|
mSpriteScoreBoard->setSpriteClip(0, 160, 256, 32);
|
||||||
mSpritePowerMeter->setSpriteClip(256, 192 - 8, 40, 8);
|
mSpritePowerMeter->setSpriteClip(256, 192 - 8, 40, 8);
|
||||||
|
|
||||||
// Vector de jugadores
|
|
||||||
if (mNumPlayers == 1)
|
|
||||||
{
|
|
||||||
mPlayer[0]->init(PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer1Legs, mTexturePlayer1Body, mTexturePlayer1Head, mTexturePlayer1Death, mRenderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (mNumPlayers == 2)
|
|
||||||
{
|
|
||||||
mPlayer[0]->init((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer1Legs, mTexturePlayer1Body, mTexturePlayer1Head, mTexturePlayer1Death, mRenderer);
|
|
||||||
mPlayer[1]->init((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, mTexturePlayer2Legs, mTexturePlayer2Body, mTexturePlayer2Head, mTexturePlayer2Death, mRenderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos globo
|
// Establece a cero todos los valores del vector de objetos globo
|
||||||
resetBalloons();
|
resetBalloons();
|
||||||
|
|
||||||
@@ -457,7 +460,7 @@ void Game::init()
|
|||||||
mSpriteGetReady->setSpriteClip(0, 0, 109, 20);
|
mSpriteGetReady->setSpriteClip(0, 0, 109, 20);
|
||||||
|
|
||||||
// Inicializa el bitmap de 1000 puntos
|
// Inicializa el bitmap de 1000 puntos
|
||||||
m1000Bitmap->init(mTextureGameText, mRenderer);
|
m1000Bitmap->init();
|
||||||
m1000Bitmap->setPosX(0);
|
m1000Bitmap->setPosX(0);
|
||||||
m1000Bitmap->setPosY(0);
|
m1000Bitmap->setPosY(0);
|
||||||
m1000Bitmap->setWidth(26);
|
m1000Bitmap->setWidth(26);
|
||||||
@@ -473,7 +476,7 @@ void Game::init()
|
|||||||
m1000Bitmap->setDestY(0);
|
m1000Bitmap->setDestY(0);
|
||||||
|
|
||||||
// Inicializa el bitmap de 2500 puntos
|
// Inicializa el bitmap de 2500 puntos
|
||||||
m2500Bitmap->init(mTextureGameText, mRenderer);
|
m2500Bitmap->init();
|
||||||
m2500Bitmap->setPosX(0);
|
m2500Bitmap->setPosX(0);
|
||||||
m2500Bitmap->setPosY(0);
|
m2500Bitmap->setPosY(0);
|
||||||
m2500Bitmap->setWidth(28);
|
m2500Bitmap->setWidth(28);
|
||||||
@@ -489,7 +492,7 @@ void Game::init()
|
|||||||
m2500Bitmap->setDestY(0);
|
m2500Bitmap->setDestY(0);
|
||||||
|
|
||||||
// Inicializa el bitmap de 5000 puntos
|
// Inicializa el bitmap de 5000 puntos
|
||||||
m5000Bitmap->init(mTextureGameText, mRenderer);
|
m5000Bitmap->init();
|
||||||
m5000Bitmap->setPosX(0);
|
m5000Bitmap->setPosX(0);
|
||||||
m5000Bitmap->setPosY(0);
|
m5000Bitmap->setPosY(0);
|
||||||
m5000Bitmap->setWidth(28);
|
m5000Bitmap->setWidth(28);
|
||||||
@@ -505,10 +508,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 +519,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());
|
||||||
@@ -1512,11 +1498,12 @@ void Game::setHiScore(Uint32 score)
|
|||||||
void Game::updateHiScore()
|
void Game::updateHiScore()
|
||||||
{
|
{
|
||||||
// Si la puntuación actual es mayor que la máxima puntuación
|
// Si la puntuación actual es mayor que la máxima puntuación
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
for (auto player : players)
|
||||||
if (mPlayer[i]->getScore() > mHiScore)
|
// for (int i = 0; i < mNumPlayers; i++)
|
||||||
|
if (player->getScore() > mHiScore)
|
||||||
{
|
{
|
||||||
// Actualiza la máxima puntuación
|
// Actualiza la máxima puntuación
|
||||||
mHiScore = mPlayer[i]->getScore();
|
mHiScore = player->getScore();
|
||||||
|
|
||||||
// Almacena la máxima puntuación en el fichero junto con un checksum
|
// Almacena la máxima puntuación en el fichero junto con un checksum
|
||||||
mScoreDataFile[0] = mHiScore;
|
mScoreDataFile[0] = mHiScore;
|
||||||
@@ -1589,21 +1576,21 @@ void Game::renderScoreBoard()
|
|||||||
|
|
||||||
// PLAYER1 - SCORE
|
// PLAYER1 - SCORE
|
||||||
mTextScoreBoard->writeCentered(offsetLeft, offset1, mLang->getText(53));
|
mTextScoreBoard->writeCentered(offsetLeft, offset1, mLang->getText(53));
|
||||||
mTextScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(mPlayer[0]->getScore()));
|
mTextScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players[0]->getScore()));
|
||||||
|
|
||||||
// PLAYER1 - MULT
|
// PLAYER1 - MULT
|
||||||
mTextScoreBoard->writeCentered(offsetLeft, offset3, mLang->getText(55));
|
mTextScoreBoard->writeCentered(offsetLeft, offset3, mLang->getText(55));
|
||||||
mTextScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(mPlayer[0]->getScoreMultiplier()).substr(0, 3));
|
mTextScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players[0]->getScoreMultiplier()).substr(0, 3));
|
||||||
|
|
||||||
if (mNumPlayers == 2)
|
if (mNumPlayers == 2)
|
||||||
{
|
{
|
||||||
// PLAYER2 - SCORE
|
// PLAYER2 - SCORE
|
||||||
mTextScoreBoard->writeCentered(offsetRight, offset1, mLang->getText(54));
|
mTextScoreBoard->writeCentered(offsetRight, offset1, mLang->getText(54));
|
||||||
mTextScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(mPlayer[1]->getScore()));
|
mTextScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players[1]->getScore()));
|
||||||
|
|
||||||
// PLAYER2 - MULT
|
// PLAYER2 - MULT
|
||||||
mTextScoreBoard->writeCentered(offsetRight, offset3, mLang->getText(55));
|
mTextScoreBoard->writeCentered(offsetRight, offset3, mLang->getText(55));
|
||||||
mTextScoreBoard->writeCentered(offsetRight, offset4, std::to_string(mPlayer[1]->getScoreMultiplier()).substr(0, 3));
|
mTextScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players[1]->getScoreMultiplier()).substr(0, 3));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1635,24 +1622,29 @@ void Game::renderScoreBoard()
|
|||||||
// Actualiza las variables del jugador
|
// Actualiza las variables del jugador
|
||||||
void Game::updatePlayer()
|
void Game::updatePlayer()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
for (auto player : players)
|
||||||
|
// for (int i = 0; i < mNumPlayers; i++)
|
||||||
{
|
{
|
||||||
mPlayer[i]->update();
|
player->update();
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos
|
// Comprueba la colisión entre el jugador y los globos
|
||||||
if (checkPlayerBalloonCollision(i))
|
if (checkPlayerBalloonCollision(player))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->isAlive())
|
if (player->isAlive())
|
||||||
{
|
{
|
||||||
if (mDemo.enabled)
|
if (mDemo.enabled)
|
||||||
|
{
|
||||||
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_INSTRUCTIONS};
|
mSection = {PROG_SECTION_TITLE, TITLE_SECTION_INSTRUCTIONS};
|
||||||
|
}
|
||||||
else
|
else
|
||||||
killPlayer(i);
|
{
|
||||||
|
killPlayer(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las colisiones entre el jugador y los items
|
// Comprueba las colisiones entre el jugador y los items
|
||||||
checkPlayerItemCollision(i);
|
checkPlayerItemCollision(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1672,11 +1664,12 @@ void Game::updateStage()
|
|||||||
destroyAllBalloons(); // Destruye a todos los enemigos
|
destroyAllBalloons(); // Destruye a todos los enemigos
|
||||||
mStage[mCurrentStage].currentPower = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos lo globos
|
mStage[mCurrentStage].currentPower = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos lo globos
|
||||||
mMenaceCurrent = 255; // Sube el nivel de amenaza para que no cree mas globos
|
mMenaceCurrent = 255; // Sube el nivel de amenaza para que no cree mas globos
|
||||||
for (int i = 0; i < mNumPlayers; i++) // Añade un millon de puntos a los jugadores que queden vivos
|
for (auto player : players)
|
||||||
|
// for (int i = 0; i < mNumPlayers; i++) // Añade un millon de puntos a los jugadores que queden vivos
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->isAlive())
|
if (player->isAlive())
|
||||||
{
|
{
|
||||||
mPlayer[i]->addScore(1000000);
|
player->addScore(1000000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
@@ -1711,47 +1704,48 @@ void Game::updateDeath()
|
|||||||
{
|
{
|
||||||
// Comprueba si todos los jugadores estan muertos
|
// Comprueba si todos los jugadores estan muertos
|
||||||
bool allAreDead = true;
|
bool allAreDead = true;
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
for (auto player : players)
|
||||||
|
// for (int i = 0; i < mNumPlayers; i++)
|
||||||
{
|
{
|
||||||
allAreDead &= (!mPlayer[i]->isAlive());
|
allAreDead &= (!player->isAlive());
|
||||||
|
|
||||||
if (!mPlayer[i]->isAlive())
|
if (!player->isAlive())
|
||||||
{
|
{
|
||||||
// Animación
|
// Animación
|
||||||
if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 0)
|
if ((player->getDeathCounter() / 5) % 4 == 0)
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
|
smartSprites[player->mDeathIndex]->setSpriteClip(24 * 0, 24, 24, 24);
|
||||||
}
|
}
|
||||||
else if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 1)
|
else if ((player->getDeathCounter() / 5) % 4 == 1)
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 1, 24, 24, 24);
|
smartSprites[player->mDeathIndex]->setSpriteClip(24 * 1, 24, 24, 24);
|
||||||
}
|
}
|
||||||
else if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 2)
|
else if ((player->getDeathCounter() / 5) % 4 == 2)
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 2, 24, 24, 24);
|
smartSprites[player->mDeathIndex]->setSpriteClip(24 * 2, 24, 24, 24);
|
||||||
}
|
}
|
||||||
else if ((mPlayer[i]->getDeathCounter() / 5) % 4 == 3)
|
else if ((player->getDeathCounter() / 5) % 4 == 3)
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setSpriteClip(24 * 3, 24, 24, 24);
|
smartSprites[player->mDeathIndex]->setSpriteClip(24 * 3, 24, 24, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebote en los laterales
|
// Rebote en los laterales
|
||||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() > 0)
|
if (smartSprites[player->mDeathIndex]->getVelX() > 0)
|
||||||
{
|
{
|
||||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getPosX() > (SCREEN_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth()))
|
if (smartSprites[player->mDeathIndex]->getPosX() > (GAME_WIDTH - smartSprites[player->mDeathIndex]->getWidth()))
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setPosX(SCREEN_WIDTH - mSmartSprite[mPlayer[i]->mDeathIndex]->getWidth());
|
smartSprites[player->mDeathIndex]->setPosX(GAME_WIDTH - smartSprites[player->mDeathIndex]->getWidth());
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setVelX(mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() * (-1));
|
smartSprites[player->mDeathIndex]->setVelX(smartSprites[player->mDeathIndex]->getVelX() * (-1));
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setDestX(mSmartSprite[mPlayer[i]->mDeathIndex]->getDestX() * (-1));
|
smartSprites[player->mDeathIndex]->setDestX(smartSprites[player->mDeathIndex]->getDestX() * (-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (mSmartSprite[mPlayer[i]->mDeathIndex]->getPosX() < 0)
|
if (smartSprites[player->mDeathIndex]->getPosX() < 0)
|
||||||
{
|
{
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setPosX(0);
|
smartSprites[player->mDeathIndex]->setPosX(0);
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setVelX(mSmartSprite[mPlayer[i]->mDeathIndex]->getVelX() * (-1));
|
smartSprites[player->mDeathIndex]->setVelX(smartSprites[player->mDeathIndex]->getVelX() * (-1));
|
||||||
mSmartSprite[mPlayer[i]->mDeathIndex]->setDestX(mSmartSprite[mPlayer[i]->mDeathIndex]->getDestX() * (-1));
|
smartSprites[player->mDeathIndex]->setDestX(smartSprites[player->mDeathIndex]->getDestX() * (-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1807,7 +1801,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 +1811,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1825,37 +1819,29 @@ void Game::renderDeathFade(int counter)
|
|||||||
// Actualiza los globos
|
// Actualiza los globos
|
||||||
void Game::updateBalloons()
|
void Game::updateBalloons()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_BALLOONS; i++)
|
for (auto balloon : balloons)
|
||||||
mBalloon[i]->update();
|
// for (int i = 0; i < MAX_BALLOONS; i++)
|
||||||
|
balloon->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta en pantalla todos los globos activos
|
// Pinta en pantalla todos los globos activos
|
||||||
void Game::renderBalloons()
|
void Game::renderBalloons()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_BALLOONS; i++)
|
for (auto balloon : balloons)
|
||||||
|
// for (int i = 0; i < MAX_BALLOONS; i++)
|
||||||
{
|
{
|
||||||
mBalloon[i]->render();
|
balloon->render();
|
||||||
if ((mDebug.enabled) && (mBalloon[i]->isPopping() == false))
|
if ((mDebug.enabled) && (balloon->isPopping() == false))
|
||||||
mText->writeCentered(mBalloon[i]->getPosX() + (mBalloon[i]->getWidth() / 2), mBalloon[i]->getPosY() - 8, std::to_string(i));
|
mText->writeCentered(balloon->getPosX() + (balloon->getWidth() / 2), balloon->getPosY() - 8, std::to_string(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de globos
|
|
||||||
Uint8 Game::getBalloonFreeIndex()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < MAX_BALLOONS; i++)
|
|
||||||
if (!mBalloon[i]->isEnabled())
|
|
||||||
return i;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea un globo nuevo en el vector de globos
|
// Crea un globo nuevo en el vector de globos
|
||||||
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture)
|
Uint8 Game::createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture)
|
||||||
{
|
{
|
||||||
const Uint8 index = getBalloonFreeIndex();
|
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
|
||||||
mBalloon[index]->init(x, y, kind, velx, speed, creationtimer, texture, mRenderer);
|
balloons.push_back(b);
|
||||||
return index;
|
return (Uint8)(balloons.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea una PowerBall
|
// Crea una PowerBall
|
||||||
@@ -1870,7 +1856,9 @@ void Game::createPowerBall()
|
|||||||
const int x[3] = {left, center, right};
|
const int x[3] = {left, center, right};
|
||||||
const int posX = x[rand() % 3];
|
const int posX = x[rand() % 3];
|
||||||
|
|
||||||
mBalloon[getBalloonFreeIndex()]->init(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, mTextureBalloon, mRenderer);
|
Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, mTextureBalloon, mRenderer);
|
||||||
|
balloons.push_back(b);
|
||||||
|
|
||||||
mPowerBallEnabled = true;
|
mPowerBallEnabled = true;
|
||||||
mPowerBallCounter = POWERBALL_COUNTER;
|
mPowerBallCounter = POWERBALL_COUNTER;
|
||||||
}
|
}
|
||||||
@@ -1878,16 +1866,25 @@ void Game::createPowerBall()
|
|||||||
// Establece a cero todos los valores del vector de objetos globo
|
// Establece a cero todos los valores del vector de objetos globo
|
||||||
void Game::resetBalloons()
|
void Game::resetBalloons()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_BALLOONS; i++)
|
for (auto balloon : balloons)
|
||||||
mBalloon[i]->disable();
|
// for (int i = 0; i < MAX_BALLOONS; i++)
|
||||||
|
{
|
||||||
|
balloon->disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la velocidad de los globos
|
// Establece la velocidad de los globos
|
||||||
void Game::setBalloonSpeed(float speed)
|
void Game::setBalloonSpeed(float speed)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_BALLOONS; i++)
|
for (auto balloon : balloons)
|
||||||
if (mBalloon[i]->isEnabled())
|
|
||||||
mBalloon[i]->setSpeed(speed);
|
// for (int i = 0; i < MAX_BALLOONS; i++)
|
||||||
|
{
|
||||||
|
if (balloon->isEnabled())
|
||||||
|
{
|
||||||
|
balloon->setSpeed(speed);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incrementa la velocidad de los globos
|
// Incrementa la velocidad de los globos
|
||||||
@@ -1966,7 +1963,7 @@ void Game::updateBalloonSpeed()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||||
void Game::popBalloon(Uint8 index)
|
void Game::popBalloon(Balloon *balloon)
|
||||||
{
|
{
|
||||||
// Aumenta el poder de la fase
|
// Aumenta el poder de la fase
|
||||||
increaseStageCurrentPower(1);
|
increaseStageCurrentPower(1);
|
||||||
@@ -2174,62 +2171,67 @@ bool Game::checkPlayerBalloonCollision(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los items
|
// Comprueba la colisión entre el jugador y los items
|
||||||
void Game::checkPlayerItemCollision(int index)
|
void Game::checkPlayerItemCollision(Player *player)
|
||||||
{
|
{
|
||||||
if (mPlayer[index]->isAlive())
|
if (!player->isAlive())
|
||||||
for (int i = 0; i < MAX_ITEMS; i++)
|
{
|
||||||
{
|
return;
|
||||||
if (mItem[i]->isEnabled())
|
}
|
||||||
{
|
|
||||||
if (checkCollision(mPlayer[index]->getCollider(), mItem[i]->getCollider()))
|
|
||||||
{
|
|
||||||
switch (mItem[i]->getClass())
|
|
||||||
{
|
|
||||||
case ITEM_POINTS_1_DISK:
|
|
||||||
mPlayer[index]->addScore(1000);
|
|
||||||
updateHiScore();
|
|
||||||
createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m1000Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m1000Bitmap);
|
|
||||||
JA_PlaySound(mSoundItemPickup);
|
|
||||||
break;
|
|
||||||
case ITEM_POINTS_2_GAVINA:
|
|
||||||
mPlayer[index]->addScore(2500);
|
|
||||||
updateHiScore();
|
|
||||||
createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m2500Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m2500Bitmap);
|
|
||||||
JA_PlaySound(mSoundItemPickup);
|
|
||||||
break;
|
|
||||||
case ITEM_POINTS_3_PACMAR:
|
|
||||||
mPlayer[index]->addScore(5000);
|
|
||||||
updateHiScore();
|
|
||||||
createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m5000Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m5000Bitmap);
|
|
||||||
JA_PlaySound(mSoundItemPickup);
|
|
||||||
break;
|
|
||||||
case ITEM_CLOCK:
|
|
||||||
enableTimeStopItem();
|
|
||||||
JA_PlaySound(mSoundItemPickup);
|
|
||||||
break;
|
|
||||||
case ITEM_COFFEE:
|
|
||||||
if (mPlayer[index]->getCoffees() == 2)
|
|
||||||
{
|
|
||||||
mPlayer[index]->addScore(5000);
|
|
||||||
updateHiScore();
|
|
||||||
createItemScoreSprite(mItem[i]->getPosX() + (mItem[i]->getWidth() / 2) - (m5000Bitmap->getWidth() / 2), mPlayer[index]->getPosY(), m5000Bitmap);
|
|
||||||
}
|
|
||||||
mPlayer[index]->giveExtraHit();
|
|
||||||
JA_PlaySound(mSoundItemPickup);
|
|
||||||
break;
|
|
||||||
case ITEM_COFFEE_MACHINE:
|
|
||||||
mPlayer[index]->setPowerUp(true);
|
|
||||||
JA_PlaySound(mSoundItemPickup);
|
|
||||||
mCoffeeMachineEnabled = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
for (auto item : items)
|
||||||
break;
|
// for (int i = 0; i < MAX_ITEMS; i++)
|
||||||
|
{
|
||||||
|
if (item->isEnabled())
|
||||||
|
{
|
||||||
|
if (checkCollision(player->getCollider(), item->getCollider()))
|
||||||
|
{
|
||||||
|
switch (item->getClass())
|
||||||
|
{
|
||||||
|
case ITEM_POINTS_1_DISK:
|
||||||
|
player->addScore(1000);
|
||||||
|
updateHiScore();
|
||||||
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (m1000Bitmap->getWidth() / 2), player->getPosY(), m1000Bitmap);
|
||||||
|
JA_PlaySound(mSoundItemPickup);
|
||||||
|
break;
|
||||||
|
case ITEM_POINTS_2_GAVINA:
|
||||||
|
player->addScore(2500);
|
||||||
|
updateHiScore();
|
||||||
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (m2500Bitmap->getWidth() / 2), player->getPosY(), m2500Bitmap);
|
||||||
|
JA_PlaySound(mSoundItemPickup);
|
||||||
|
break;
|
||||||
|
case ITEM_POINTS_3_PACMAR:
|
||||||
|
player->addScore(5000);
|
||||||
|
updateHiScore();
|
||||||
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (m5000Bitmap->getWidth() / 2), player->getPosY(), m5000Bitmap);
|
||||||
|
JA_PlaySound(mSoundItemPickup);
|
||||||
|
break;
|
||||||
|
case ITEM_CLOCK:
|
||||||
|
enableTimeStopItem();
|
||||||
|
JA_PlaySound(mSoundItemPickup);
|
||||||
|
break;
|
||||||
|
case ITEM_COFFEE:
|
||||||
|
if (player->getCoffees() == 2)
|
||||||
|
{
|
||||||
|
player->addScore(5000);
|
||||||
|
updateHiScore();
|
||||||
|
createItemScoreSprite(item->getPosX() + (item->getWidth() / 2) - (m5000Bitmap->getWidth() / 2), player->getPosY(), m5000Bitmap);
|
||||||
}
|
}
|
||||||
mItem[i]->erase();
|
player->giveExtraHit();
|
||||||
|
JA_PlaySound(mSoundItemPickup);
|
||||||
|
break;
|
||||||
|
case ITEM_COFFEE_MACHINE:
|
||||||
|
player->setPowerUp(true);
|
||||||
|
JA_PlaySound(mSoundItemPickup);
|
||||||
|
mCoffeeMachineEnabled = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
item->erase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba y procesa la colisión entre las balas y los globos
|
// Comprueba y procesa la colisión entre las balas y los globos
|
||||||
@@ -2456,7 +2458,7 @@ Uint8 Game::dropItem()
|
|||||||
// Crea un objeto item
|
// Crea un objeto item
|
||||||
void Game::createItem(int x, int y, Uint8 kind)
|
void Game::createItem(int x, int y, Uint8 kind)
|
||||||
{
|
{
|
||||||
mItem[getItemFreeIndex()]->init(kind, x, y, mTextureItems, mRenderer);
|
mItem[getItemFreeIndex()]->init(kind, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
// Crea un objeto SmartSprite para mostrar la puntuación al coger un objeto
|
||||||
@@ -2509,7 +2511,7 @@ void Game::throwCoffee(int x, int y)
|
|||||||
{
|
{
|
||||||
const Uint8 index = getSmartSpriteFreeIndex();
|
const Uint8 index = getSmartSpriteFreeIndex();
|
||||||
|
|
||||||
mSmartSprite[index]->init(mTextureItems, mRenderer);
|
mSmartSprite[index]->init();
|
||||||
mSmartSprite[index]->setPosX(x - 8);
|
mSmartSprite[index]->setPosX(x - 8);
|
||||||
mSmartSprite[index]->setPosY(y - 8);
|
mSmartSprite[index]->setPosY(y - 8);
|
||||||
mSmartSprite[index]->setWidth(16);
|
mSmartSprite[index]->setWidth(16);
|
||||||
@@ -2519,7 +2521,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);
|
||||||
@@ -2534,7 +2536,8 @@ void Game::throwPlayer(int x, int y, int index)
|
|||||||
const int sentit = ((rand() % 2) ? 1 : -1);
|
const int sentit = ((rand() % 2) ? 1 : -1);
|
||||||
|
|
||||||
mPlayer[index]->mDeathIndex = getSmartSpriteFreeIndex();
|
mPlayer[index]->mDeathIndex = getSmartSpriteFreeIndex();
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->init(mPlayer[index]->getDeadTexture(), mRenderer);
|
// mSmartSprite[mPlayer[index]->mDeathIndex]->init(mPlayer[index]->getDeadTexture(), mRenderer);
|
||||||
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setTexture(mPlayer[index]->getDeadTexture());
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setPosX(x);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setPosX(x);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setPosY(y);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setPosY(y);
|
||||||
mSmartSprite[mPlayer[index]->mDeathIndex]->setWidth(24);
|
mSmartSprite[mPlayer[index]->mDeathIndex]->setWidth(24);
|
||||||
@@ -2543,8 +2546,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);
|
||||||
@@ -2587,12 +2590,12 @@ void Game::resetSmartSprites()
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_SMART_SPRITES; i++)
|
for (int i = 0; i < MAX_SMART_SPRITES; i++)
|
||||||
{
|
{
|
||||||
mSmartSprite[i]->erase();
|
mSmartSprite[i]->init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Acciones a realizar cuando el jugador muere
|
// Acciones a realizar cuando el jugador muere
|
||||||
void Game::killPlayer(int index)
|
void Game::killPlayer(Player *player)
|
||||||
{
|
{
|
||||||
if (!mPlayer[index]->isInvulnerable())
|
if (!mPlayer[index]->isInvulnerable())
|
||||||
{
|
{
|
||||||
@@ -2775,7 +2778,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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,29 +132,34 @@ private:
|
|||||||
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
Screen *mScreen; // Objeto encargado de dibujar en pantalla
|
||||||
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
Input *mInput; // Manejador de entrada
|
||||||
|
|
||||||
int mNumPlayers; // Numero de jugadores
|
// Player *mPlayer[2]; // Vector con los jugadores jugador
|
||||||
Player *mPlayer[2]; // Vector con los jugadores jugador
|
// Balloon *mBalloon[MAX_BALLOONS]; // Vector con los objetos globo
|
||||||
Input *mInput; // Manejador de entrada
|
// Bullet *mBullet[MAX_BULLETS]; // Vector con los objetos bala
|
||||||
|
// Item *mItem[MAX_ITEMS]; // Vector con los objetos item
|
||||||
|
// SmartSprite *mSmartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites
|
||||||
|
|
||||||
Balloon *mBalloon[MAX_BALLOONS]; // Vector con los objetos globo
|
int mNumPlayers; // Numero de jugadores
|
||||||
Bullet *mBullet[MAX_BULLETS]; // Vector con los objetos bala
|
std::vector<Player *> players; // Vector con los jugadores
|
||||||
Item *mItem[MAX_ITEMS]; // Vector con los objetos item
|
std::vector<Balloon *> balloons; // Vector con los globos
|
||||||
SmartSprite *mSmartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites
|
std::vector<Bullet *> bullets; // Vector con las balas
|
||||||
|
std::vector<Item *> items; // Vector con los items
|
||||||
|
std::vector<SmartSprite *> smartSprites; // Vector con los smartsprites
|
||||||
|
|
||||||
LTexture *mTextureBalloon; // Textura para los enemigos
|
LTexture *mTextureBalloon; // Textura para los enemigos
|
||||||
LTexture *mTextureBullet; // Textura para las balas
|
LTexture *mTextureBullet; // Textura para las balas
|
||||||
LTexture *mTextureGameBG; // Textura para el fondo del juego
|
LTexture *mTextureGameBG; // Textura para el fondo del juego
|
||||||
LTexture *mTextureGameText; // Textura para los sprites con textos
|
LTexture *mTextureGameText; // Textura para los sprites con textos
|
||||||
LTexture *mTextureItems; // Textura para los items
|
LTexture *mTextureItems; // Textura para los items
|
||||||
LTexture *mTexturePlayer1Head; // Textura para la cabeza del jugador1
|
LTexture *mTexturePlayer1Head; // Textura para la cabeza del jugador1
|
||||||
LTexture *mTexturePlayer1Body; // Textura para el cuerpo del jugador1
|
LTexture *mTexturePlayer1Body; // Textura para el cuerpo del jugador1
|
||||||
LTexture *mTexturePlayer1Death; // Textura para la animación de muerte del jugador1
|
LTexture *mTexturePlayer1Death; // Textura para la animación de muerte del jugador1
|
||||||
LTexture *mTexturePlayer1Legs; // Textura para las piernas del jugador
|
LTexture *mTexturePlayer1Legs; // Textura para las piernas del jugador
|
||||||
LTexture *mTexturePlayer2Head; // Textura para la cabeza del jugador2
|
LTexture *mTexturePlayer2Head; // Textura para la cabeza del jugador2
|
||||||
LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2
|
LTexture *mTexturePlayer2Body; // Textura para el cuerpo del jugador2
|
||||||
LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2
|
LTexture *mTexturePlayer2Death; // Textura para la animación de muerte del jugador2
|
||||||
LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador
|
LTexture *mTexturePlayer2Legs; // Textura para las piernas del jugador
|
||||||
|
|
||||||
Text *mText; // Fuente para los textos del juego
|
Text *mText; // Fuente para los textos del juego
|
||||||
Text *mTextBig; // Fuente de texto grande
|
Text *mTextBig; // Fuente de texto grande
|
||||||
@@ -311,9 +316,6 @@ private:
|
|||||||
// Pinta en pantalla todos los globos activos
|
// Pinta en pantalla todos los globos activos
|
||||||
void renderBalloons();
|
void renderBalloons();
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de globos
|
|
||||||
Uint8 getBalloonFreeIndex();
|
|
||||||
|
|
||||||
// Crea un globo nuevo en el vector de globos
|
// Crea un globo nuevo en el vector de globos
|
||||||
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
|
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
|
||||||
|
|
||||||
@@ -336,10 +338,10 @@ private:
|
|||||||
void updateBalloonSpeed();
|
void updateBalloonSpeed();
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
|
||||||
void popBalloon(Uint8 index);
|
void popBalloon(Balloon *balloon);
|
||||||
|
|
||||||
// Explosiona un globo. Lo destruye
|
// Explosiona un globo. Lo destruye
|
||||||
void destroyBalloon(Uint8 index);
|
void destroyBalloon(Balloon *balloon);
|
||||||
|
|
||||||
// Explosiona todos los globos
|
// Explosiona todos los globos
|
||||||
void popAllBalloons();
|
void popAllBalloons();
|
||||||
@@ -357,10 +359,10 @@ private:
|
|||||||
Uint8 countBalloons();
|
Uint8 countBalloons();
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos activos
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
bool checkPlayerBalloonCollision(int index);
|
bool checkPlayerBalloonCollision(Player *player);
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los items
|
// Comprueba la colisión entre el jugador y los items
|
||||||
void checkPlayerItemCollision(int index);
|
void checkPlayerItemCollision(Player *player);
|
||||||
|
|
||||||
// Comprueba la colisión entre las balas y los globos
|
// Comprueba la colisión entre las balas y los globos
|
||||||
void checkBulletBalloonCollision();
|
void checkBulletBalloonCollision();
|
||||||
@@ -371,9 +373,6 @@ private:
|
|||||||
// Pinta las balas activas
|
// Pinta las balas activas
|
||||||
void renderBullets();
|
void renderBullets();
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de balas
|
|
||||||
Uint8 getBulletFreeIndex();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos bala
|
// Establece a cero todos los valores del vector de objetos bala
|
||||||
void resetBullets();
|
void resetBullets();
|
||||||
|
|
||||||
@@ -386,9 +385,6 @@ private:
|
|||||||
// Pinta los items activos
|
// Pinta los items activos
|
||||||
void renderItems();
|
void renderItems();
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de items
|
|
||||||
Uint8 getItemFreeIndex();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos item
|
// Establece a cero todos los valores del vector de objetos item
|
||||||
void resetItems();
|
void resetItems();
|
||||||
|
|
||||||
@@ -419,14 +415,11 @@ private:
|
|||||||
// Pinta los SmartSprites activos
|
// Pinta los SmartSprites activos
|
||||||
void renderSmartSprites();
|
void renderSmartSprites();
|
||||||
|
|
||||||
// Devuelve el primer indice no activo del vector de SmartSprites
|
|
||||||
Uint8 getSmartSpriteFreeIndex();
|
|
||||||
|
|
||||||
// Establece a cero todos los valores del vector de objetos SmafrtSprite
|
// Establece a cero todos los valores del vector de objetos SmafrtSprite
|
||||||
void resetSmartSprites();
|
void resetSmartSprites();
|
||||||
|
|
||||||
// Acciones a realizar cuando el jugador muere
|
// Acciones a realizar cuando el jugador muere
|
||||||
void killPlayer(int index);
|
void killPlayer(Player *player);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint8 getSubsection();
|
Uint8 getSubsection();
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ 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,mAsset->get("items.png"));
|
||||||
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());
|
||||||
@@ -50,22 +50,9 @@ Instructions::~Instructions()
|
|||||||
mBackbuffer = nullptr;
|
mBackbuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los recursos necesarios para la sección 'Instructions'
|
|
||||||
bool Instructions::loadMedia()
|
|
||||||
{
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
success &= loadTextureFromFile(mItemTexture, mAsset->get("items.png"), mRenderer);
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables necesarias para la sección 'Instructions'
|
// Inicializa las variables necesarias para la sección 'Instructions'
|
||||||
void Instructions::init()
|
void Instructions::init()
|
||||||
{
|
{
|
||||||
// Carga los recursos
|
|
||||||
loadMedia();
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
mSection.name = SELF;
|
mSection.name = SELF;
|
||||||
mTicks = 0;
|
mTicks = 0;
|
||||||
@@ -135,7 +122,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 +153,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 +201,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;
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ private:
|
|||||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
bool mManualQuit; // Indica si se quiere salir del modo manual
|
bool mManualQuit; // Indica si se quiere salir del modo manual
|
||||||
|
|
||||||
// Carga los recursos
|
|
||||||
bool loadMedia();
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang)
|
|||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
mBitmapTexture = new LTexture(mRenderer);
|
mBitmapTexture = new LTexture(mRenderer,mAsset->get("intro.png"));
|
||||||
mText = new Text(mAsset->get("nokia.png"), mAsset->get("nokia.txt"), mRenderer);
|
mText = new Text(mAsset->get("nokia.png"), mAsset->get("nokia.txt"), mRenderer);
|
||||||
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||||
{
|
{
|
||||||
mBitmap[i] = new SmartSprite();
|
mBitmap[i] = new SmartSprite(mBitmapTexture, mRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
|
||||||
@@ -67,12 +67,14 @@ void Intro::init()
|
|||||||
|
|
||||||
// Inicializa el vector de eventos de la intro
|
// Inicializa el vector de eventos de la intro
|
||||||
for (int i = 0; i < INTRO_TOTAL_EVENTS; i++)
|
for (int i = 0; i < INTRO_TOTAL_EVENTS; i++)
|
||||||
|
{
|
||||||
mEvents[i] = EVENT_WAITING;
|
mEvents[i] = EVENT_WAITING;
|
||||||
|
}
|
||||||
|
|
||||||
// Inicializa los bitmaps de la intro
|
// Inicializa los bitmaps de la intro
|
||||||
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
for (int i = 0; i < INTRO_TOTAL_BITMAPS; i++)
|
||||||
{
|
{
|
||||||
mBitmap[i]->init(mBitmapTexture, mRenderer);
|
mBitmap[i]->init();
|
||||||
mBitmap[i]->setId(i);
|
mBitmap[i]->setId(i);
|
||||||
mBitmap[i]->setIntroEvents(&mEvents[0]);
|
mBitmap[i]->setIntroEvents(&mEvents[0]);
|
||||||
mBitmap[i]->setWidth(128);
|
mBitmap[i]->setWidth(128);
|
||||||
@@ -91,7 +93,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 +112,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 +127,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 +142,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);
|
||||||
@@ -191,9 +193,6 @@ bool Intro::loadMedia()
|
|||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
// Texturas
|
|
||||||
success &= loadTextureFromFile(mBitmapTexture, mAsset->get("intro.png"), mRenderer);
|
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
mMusic = JA_LoadMusic(mAsset->get("intro.ogg").c_str());
|
mMusic = JA_LoadMusic(mAsset->get("intro.ogg").c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,23 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer)
|
Item::Item(LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
mSprite = new AnimatedSprite(texture, renderer);
|
mSprite = new AnimatedSprite(texture, renderer);
|
||||||
mClass = NO_KIND;
|
init(NO_KIND, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
mClass = value;
|
// Destructor
|
||||||
|
Item::~Item()
|
||||||
|
{
|
||||||
|
delete mSprite;
|
||||||
|
mSprite = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void Item::init(Uint8 type, float x, float y)
|
||||||
|
{
|
||||||
|
mClass = type;
|
||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
mTimeToLive = 600;
|
mTimeToLive = 600;
|
||||||
mPosX = x;
|
mPosX = x;
|
||||||
@@ -32,7 +43,7 @@ Item::Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *rende
|
|||||||
mSprite->setPosX(mPosX);
|
mSprite->setPosX(mPosX);
|
||||||
mSprite->setPosY(mPosY);
|
mSprite->setPosY(mPosY);
|
||||||
|
|
||||||
switch (value)
|
switch (type)
|
||||||
{
|
{
|
||||||
case NO_KIND:
|
case NO_KIND:
|
||||||
mEnabled = false;
|
mEnabled = false;
|
||||||
@@ -93,13 +104,6 @@ Item::Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *rende
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Item::~Item()
|
|
||||||
{
|
|
||||||
delete mSprite;
|
|
||||||
mSprite = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Centra el objeto en la posición X
|
// Centra el objeto en la posición X
|
||||||
void Item::allignTo(int x)
|
void Item::allignTo(int x)
|
||||||
{
|
{
|
||||||
@@ -195,7 +199,7 @@ void Item::move()
|
|||||||
// Pone a cero todos los valores del objeto
|
// Pone a cero todos los valores del objeto
|
||||||
void Item::erase()
|
void Item::erase()
|
||||||
{
|
{
|
||||||
//init(NO_KIND, 0, 0, nullptr, nullptr);
|
// init(NO_KIND, 0, 0, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto a su posicion, animación y controla los contadores
|
// Actualiza el objeto a su posicion, animación y controla los contadores
|
||||||
@@ -205,7 +209,7 @@ void Item::update()
|
|||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
shiftColliders();
|
shiftColliders();
|
||||||
mSprite->animate(0);
|
mSprite->animate();
|
||||||
updateTimeToLive();
|
updateTimeToLive();
|
||||||
checkTimeToLive();
|
checkTimeToLive();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,14 @@ public:
|
|||||||
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
|
Uint16 mTimeToLive; // Temporizador con el tiempo que el objeto está presente
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item(Uint8 value, float x, float y, LTexture *texture, SDL_Renderer *renderer);
|
Item(LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Item();
|
~Item();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init(Uint8 type, float x, float y);
|
||||||
|
|
||||||
// Centra el objeto en la posición X
|
// Centra el objeto en la posición X
|
||||||
void allignTo(int x);
|
void allignTo(int x);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -907,3 +907,12 @@ void Menu::setBackgroundType(int value)
|
|||||||
{
|
{
|
||||||
backgroundType = value;
|
backgroundType = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece la fuente de texto que se utilizará
|
||||||
|
void Menu::setText(std::string font_png, std::string font_txt)
|
||||||
|
{
|
||||||
|
if (!text)
|
||||||
|
{
|
||||||
|
text = new Text(asset->get(font_png), asset->get(font_txt), renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -217,8 +217,8 @@ public:
|
|||||||
// Establece el tipo de fondo del menu
|
// Establece el tipo de fondo del menu
|
||||||
void setBackgroundType(int value);
|
void setBackgroundType(int value);
|
||||||
|
|
||||||
|
// Establece la fuente de texto que se utilizará
|
||||||
// hacer procedimientos para establecer el titulo, la x, la y, la tipografia y el tipo de fondo
|
void setText(std::string font_png, std::string font_txt);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,11 +2,20 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player()
|
Player::Player(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
mSpriteLegs = new AnimatedSprite();
|
mSpriteLegs = new AnimatedSprite(textureLegs, renderer);
|
||||||
mSpriteBody = new AnimatedSprite();
|
mSpriteBody = new AnimatedSprite(textureBody, renderer);
|
||||||
mSpriteHead = new AnimatedSprite();
|
mSpriteHead = new AnimatedSprite(textureHead, renderer);
|
||||||
|
|
||||||
|
// Copia punteros
|
||||||
|
mPlayerDeadTexture = textureDead;
|
||||||
|
|
||||||
|
// Establece la posición inicial del jugador
|
||||||
|
mPosX = x;
|
||||||
|
mPosY = y;
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -23,11 +32,8 @@ Player::~Player()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer)
|
void Player::init()
|
||||||
{
|
{
|
||||||
// Copia punteros
|
|
||||||
mPlayerDeadTexture = textureDead;
|
|
||||||
|
|
||||||
// Inicializa variables de estado
|
// Inicializa variables de estado
|
||||||
mAlive = true;
|
mAlive = true;
|
||||||
mDeathCounter = DEATH_COUNTER;
|
mDeathCounter = DEATH_COUNTER;
|
||||||
@@ -47,10 +53,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
mWidth = 3 * BLOCK;
|
mWidth = 3 * BLOCK;
|
||||||
mHeight = 3 * BLOCK;
|
mHeight = 3 * BLOCK;
|
||||||
|
|
||||||
// Establece la posición inicial del jugador
|
|
||||||
mPosX = x;
|
|
||||||
mPosY = y;
|
|
||||||
|
|
||||||
// Establece el tamaño del circulo de colisión
|
// Establece el tamaño del circulo de colisión
|
||||||
mCollider.r = 7;
|
mCollider.r = 7;
|
||||||
|
|
||||||
@@ -75,8 +77,8 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
|
|||||||
|
|
||||||
// Inicia el sprite
|
// Inicia el sprite
|
||||||
mSpriteLegs->init();
|
mSpriteLegs->init();
|
||||||
mSpriteBody->init(textureBody, renderer);
|
mSpriteBody->init();
|
||||||
mSpriteHead->init(textureHead, renderer);
|
mSpriteHead->init();
|
||||||
|
|
||||||
// Establece el alto y ancho del sprite
|
// Establece el alto y ancho del sprite
|
||||||
mSpriteLegs->setWidth(mWidth);
|
mSpriteLegs->setWidth(mWidth);
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -97,13 +97,13 @@ public:
|
|||||||
Uint16 mPowerUpCounter; // Temporizador para el modo PowerUp
|
Uint16 mPowerUpCounter; // Temporizador para el modo PowerUp
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player();
|
Player(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Player();
|
~Player();
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
void init(float x, int y, LTexture *textureLegs, LTexture *textureBody, LTexture *textureHead, LTexture *textureDead, SDL_Renderer *renderer);
|
void init();
|
||||||
|
|
||||||
// Actua en consecuencia de la entrada recibida
|
// Actua en consecuencia de la entrada recibida
|
||||||
void setInput(Uint8 input);
|
void setInput(Uint8 input);
|
||||||
|
|||||||
@@ -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
@@ -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
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
#include "smartsprite.h"
|
#include "smartsprite.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SmartSprite::SmartSprite()
|
SmartSprite::SmartSprite(LTexture *texture, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
|
setTexture(texture);
|
||||||
|
setRenderer(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -12,11 +14,8 @@ SmartSprite::~SmartSprite()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
void SmartSprite::init()
|
||||||
{
|
{
|
||||||
setTexture(texture);
|
|
||||||
setRenderer(renderer);
|
|
||||||
|
|
||||||
setPosX(0);
|
setPosX(0);
|
||||||
setPosY(0);
|
setPosY(0);
|
||||||
setWidth(0);
|
setWidth(0);
|
||||||
@@ -32,80 +31,74 @@ 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
|
|
||||||
void SmartSprite::erase()
|
|
||||||
{
|
|
||||||
init(nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 +106,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 +120,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 +135,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 +149,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 +161,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,26 +11,23 @@
|
|||||||
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
|
||||||
SmartSprite();
|
SmartSprite(LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~SmartSprite();
|
~SmartSprite();
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void init(LTexture *texture, SDL_Renderer *renderer);
|
void init();
|
||||||
|
|
||||||
// Pone a cero los elementos del objeto
|
|
||||||
void erase();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
|||||||
@@ -15,23 +15,24 @@ Title::Title(SDL_Window *window, SDL_Renderer *renderer, Screen *screen, Input *
|
|||||||
// Reserva memoria para los punteros propios
|
// Reserva memoria para los punteros propios
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
mFade = new Fade(renderer);
|
mFade = new Fade(renderer);
|
||||||
mTitleTexture = new LTexture(mRenderer);
|
|
||||||
mItemsTexture = new LTexture(mRenderer);
|
mTitleTexture = new LTexture(mRenderer, mAsset->get("title.png"));
|
||||||
mTextTexture = new LTexture(mRenderer);
|
mItemsTexture = new LTexture(mRenderer, mAsset->get("items.png"));
|
||||||
mTextTexture2 = new LTexture(mRenderer);
|
|
||||||
mCoffeeBitmap = new SmartSprite();
|
mCoffeeBitmap = new SmartSprite(mTitleTexture, mRenderer);
|
||||||
mCrisisBitmap = new SmartSprite();
|
mCrisisBitmap = new SmartSprite(mTitleTexture, mRenderer);
|
||||||
mDustBitmapL = new AnimatedSprite();
|
mDustBitmapL = new AnimatedSprite(mTitleTexture, mRenderer);
|
||||||
mDustBitmapR = new AnimatedSprite();
|
mDustBitmapR = new AnimatedSprite(mTitleTexture, mRenderer);
|
||||||
|
|
||||||
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, mInput, mAsset);
|
||||||
mMenu.options = new Menu(mRenderer, mText, mInput, mAsset);
|
mMenu.options = new Menu(mRenderer, 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());
|
||||||
@@ -69,14 +70,6 @@ Title::~Title()
|
|||||||
delete mItemsTexture;
|
delete mItemsTexture;
|
||||||
mItemsTexture = nullptr;
|
mItemsTexture = nullptr;
|
||||||
|
|
||||||
mTextTexture->unload();
|
|
||||||
delete mTextTexture;
|
|
||||||
mTextTexture = nullptr;
|
|
||||||
|
|
||||||
mTextTexture2->unload();
|
|
||||||
delete mTextTexture2;
|
|
||||||
mTextTexture2 = nullptr;
|
|
||||||
|
|
||||||
delete mCoffeeBitmap;
|
delete mCoffeeBitmap;
|
||||||
mCoffeeBitmap = nullptr;
|
mCoffeeBitmap = nullptr;
|
||||||
|
|
||||||
@@ -156,7 +149,6 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el bitmap de Coffee
|
// Inicializa el bitmap de Coffee
|
||||||
mCoffeeBitmap->init(mTitleTexture, mRenderer);
|
|
||||||
mCoffeeBitmap->setId(0);
|
mCoffeeBitmap->setId(0);
|
||||||
mCoffeeBitmap->setIntroEvents(&mEvents[0]);
|
mCoffeeBitmap->setIntroEvents(&mEvents[0]);
|
||||||
mCoffeeBitmap->setPosX(45);
|
mCoffeeBitmap->setPosX(45);
|
||||||
@@ -174,7 +166,6 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
mCoffeeBitmap->setDestY(11);
|
mCoffeeBitmap->setDestY(11);
|
||||||
|
|
||||||
// Inicializa el bitmap de Crisis
|
// Inicializa el bitmap de Crisis
|
||||||
mCrisisBitmap->init(mTitleTexture, mRenderer);
|
|
||||||
mCrisisBitmap->setId(1);
|
mCrisisBitmap->setId(1);
|
||||||
mCrisisBitmap->setIntroEvents(&mEvents[0]);
|
mCrisisBitmap->setIntroEvents(&mEvents[0]);
|
||||||
mCrisisBitmap->setPosX(60);
|
mCrisisBitmap->setPosX(60);
|
||||||
@@ -192,14 +183,12 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
mCrisisBitmap->setDestY(57);
|
mCrisisBitmap->setDestY(57);
|
||||||
|
|
||||||
// Inicializa el bitmap de DustRight
|
// Inicializa el bitmap de DustRight
|
||||||
mDustBitmapR->init(mTitleTexture, mRenderer);
|
|
||||||
mDustBitmapR->setPosX(218);
|
mDustBitmapR->setPosX(218);
|
||||||
mDustBitmapR->setPosY(47);
|
mDustBitmapR->setPosY(47);
|
||||||
mDustBitmapR->setWidth(16);
|
mDustBitmapR->setWidth(16);
|
||||||
mDustBitmapR->setHeight(14);
|
mDustBitmapR->setHeight(14);
|
||||||
mDustBitmapR->setCurrentFrame(0);
|
mDustBitmapR->setCurrentFrame(0);
|
||||||
mDustBitmapR->setAnimationCounter(0);
|
mDustBitmapR->setAnimationCounter(0);
|
||||||
mDustBitmapR->setAnimationNumFrames(0, 7);
|
|
||||||
mDustBitmapR->setAnimationSpeed(0, 8);
|
mDustBitmapR->setAnimationSpeed(0, 8);
|
||||||
mDustBitmapR->setAnimationLoop(0, false);
|
mDustBitmapR->setAnimationLoop(0, false);
|
||||||
mDustBitmapR->setAnimationFrames(0, 0, 160 + (mDustBitmapR->getWidth() * 0), 80, mDustBitmapR->getWidth(), mDustBitmapR->getHeight());
|
mDustBitmapR->setAnimationFrames(0, 0, 160 + (mDustBitmapR->getWidth() * 0), 80, mDustBitmapR->getWidth(), mDustBitmapR->getHeight());
|
||||||
@@ -211,14 +200,12 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
mDustBitmapR->setAnimationFrames(0, 6, 160 + (mDustBitmapR->getWidth() * 6), 80, mDustBitmapR->getWidth(), mDustBitmapR->getHeight());
|
mDustBitmapR->setAnimationFrames(0, 6, 160 + (mDustBitmapR->getWidth() * 6), 80, mDustBitmapR->getWidth(), mDustBitmapR->getHeight());
|
||||||
|
|
||||||
// Inicializa el bitmap de DustLeft
|
// Inicializa el bitmap de DustLeft
|
||||||
mDustBitmapL->init(mTitleTexture, mRenderer);
|
|
||||||
mDustBitmapL->setPosX(33);
|
mDustBitmapL->setPosX(33);
|
||||||
mDustBitmapL->setPosY(47);
|
mDustBitmapL->setPosY(47);
|
||||||
mDustBitmapL->setWidth(16);
|
mDustBitmapL->setWidth(16);
|
||||||
mDustBitmapL->setHeight(14);
|
mDustBitmapL->setHeight(14);
|
||||||
mDustBitmapL->setCurrentFrame(0);
|
mDustBitmapL->setCurrentFrame(0);
|
||||||
mDustBitmapL->setAnimationCounter(0);
|
mDustBitmapL->setAnimationCounter(0);
|
||||||
mDustBitmapL->setAnimationNumFrames(0, 7);
|
|
||||||
mDustBitmapL->setAnimationSpeed(0, 8);
|
mDustBitmapL->setAnimationSpeed(0, 8);
|
||||||
mDustBitmapL->setAnimationLoop(0, false);
|
mDustBitmapL->setAnimationLoop(0, false);
|
||||||
mDustBitmapL->setAnimationFrames(0, 0, 160 + (mDustBitmapL->getWidth() * 0), 66, mDustBitmapL->getWidth(), mDustBitmapL->getHeight());
|
mDustBitmapL->setAnimationFrames(0, 0, 160 + (mDustBitmapL->getWidth() * 0), 66, mDustBitmapL->getWidth(), mDustBitmapL->getHeight());
|
||||||
@@ -235,7 +222,9 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
|
|
||||||
// Inicializa el vector de eventos de la pantalla de titulo
|
// Inicializa el vector de eventos de la pantalla de titulo
|
||||||
for (int i = 0; i < TITLE_TOTAL_EVENTS; i++)
|
for (int i = 0; i < TITLE_TOTAL_EVENTS; i++)
|
||||||
|
{
|
||||||
mEvents[i] = EVENT_WAITING;
|
mEvents[i] = EVENT_WAITING;
|
||||||
|
}
|
||||||
|
|
||||||
// Crea el mosaico de fondo del titulo
|
// Crea el mosaico de fondo del titulo
|
||||||
createTiledBackground();
|
createTiledBackground();
|
||||||
@@ -243,27 +232,35 @@ 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++)
|
||||||
|
{
|
||||||
mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
|
||||||
|
}
|
||||||
|
|
||||||
// Inicializa los objetos de menu
|
// Inicializa los objetos de menu
|
||||||
mMenu.title->init("TITLE", 0, (14 * BLOCK) + 4, MENU_BACKGROUND_TRANSPARENT);
|
mMenu.title->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt"));
|
||||||
|
mMenu.title->setName("TITLE");
|
||||||
|
mMenu.title->setPos(0, (14 * BLOCK) + 4);
|
||||||
|
mMenu.title->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
|
||||||
mMenu.title->addItem(mLang->getText(51), 2); // 1 PLAYER
|
mMenu.title->addItem(mLang->getText(51), 2); // 1 PLAYER
|
||||||
mMenu.title->addItem(mLang->getText(52), 7); // 2 PLAYERS
|
mMenu.title->addItem(mLang->getText(52), 7); // 2 PLAYERS
|
||||||
mMenu.title->addItem(mLang->getText(1), 7); // OPTIONS
|
mMenu.title->addItem(mLang->getText(1), 7); // OPTIONS
|
||||||
mMenu.title->addItem(mLang->getText(3)); // QUIT
|
mMenu.title->addItem(mLang->getText(3)); // QUIT
|
||||||
mMenu.title->setDefaultActionWhenCancel(3);
|
mMenu.title->setDefaultActionWhenCancel(3);
|
||||||
mMenu.title->setBackgroundColor(0x30, 0x30, 0x40, 192);
|
mMenu.title->setBackgroundColor({0x30, 0x30, 0x40}, 192);
|
||||||
mMenu.title->setSelectorColor(0xe5, 0x1c, 0x23, 0);
|
mMenu.title->setSelectorColor({0xe5, 0x1c, 0x23}, 0);
|
||||||
mMenu.title->setSelectorTextColor(0xFF, 0xB4, 0x00);
|
mMenu.title->setSelectorTextColor({0xFF, 0xB4, 0x00});
|
||||||
mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
|
mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
|
||||||
mMenu.title->centerMenuElementsOnX();
|
mMenu.title->centerMenuElementsOnX();
|
||||||
|
|
||||||
mMenu.options->init("OPTIONS", 0, BLOCK, MENU_BACKGROUND_TRANSPARENT);
|
mMenu.options->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt"));
|
||||||
|
mMenu.options->setName("OPTIONS");
|
||||||
|
mMenu.options->setPos(0, BLOCK);
|
||||||
|
mMenu.options->setBackgroundType(MENU_BACKGROUND_TRANSPARENT);
|
||||||
mMenu.options->addItem(mLang->getText(59), 7); // (0) DIFFICULTY
|
mMenu.options->addItem(mLang->getText(59), 7); // (0) DIFFICULTY
|
||||||
mMenu.options->addItem(mLang->getText(62), 2, true, false, true); // (1) PLAYER 1 CONTROLS
|
mMenu.options->addItem(mLang->getText(62), 2, true, false, true); // (1) PLAYER 1 CONTROLS
|
||||||
mMenu.options->addItem(mLang->getText(69), 7, false, false); // (2) KEYBOARD
|
mMenu.options->addItem(mLang->getText(69), 7, false, false); // (2) KEYBOARD
|
||||||
@@ -279,9 +276,9 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
mMenu.options->addItem(mLang->getText(9), 2); // (12) ACCEPT
|
mMenu.options->addItem(mLang->getText(9), 2); // (12) ACCEPT
|
||||||
mMenu.options->addItem(mLang->getText(10)); // (13) CANCEL
|
mMenu.options->addItem(mLang->getText(10)); // (13) CANCEL
|
||||||
mMenu.options->setDefaultActionWhenCancel(13);
|
mMenu.options->setDefaultActionWhenCancel(13);
|
||||||
mMenu.options->setBackgroundColor(0x30, 0x30, 0x40, 192);
|
mMenu.options->setBackgroundColor({0x30, 0x30, 0x40}, 192);
|
||||||
mMenu.options->setSelectorColor(0xe5, 0x1c, 0x23, 255);
|
mMenu.options->setSelectorColor({0xe5, 0x1c, 0x23}, 255);
|
||||||
mMenu.options->setSelectorTextColor(0xFF, 0xF1, 0x76);
|
mMenu.options->setSelectorTextColor({0xFF, 0xF1, 0x76});
|
||||||
mMenu.options->centerMenuOnX(SCREEN_CENTER_X);
|
mMenu.options->centerMenuOnX(SCREEN_CENTER_X);
|
||||||
mMenu.options->centerMenuOnY(SCREEN_CENTER_Y);
|
mMenu.options->centerMenuOnY(SCREEN_CENTER_Y);
|
||||||
|
|
||||||
@@ -295,12 +292,6 @@ bool Title::loadMedia()
|
|||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
// Texturas
|
|
||||||
success &= loadTextureFromFile(mTitleTexture, mAsset->get("title.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mItemsTexture, mAsset->get("items.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTextTexture, mAsset->get("smb2.png"), mRenderer);
|
|
||||||
success &= loadTextureFromFile(mTextTexture2, mAsset->get("8bithud.png"), mRenderer);
|
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
mSound = JA_LoadSound(mAsset->get("title.wav").c_str());
|
mSound = JA_LoadSound(mAsset->get("title.wav").c_str());
|
||||||
|
|
||||||
@@ -862,7 +853,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
@@ -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
|
||||||