Modificado el bucle principal
This commit is contained in:
@@ -8,6 +8,18 @@
|
|||||||
// Textos
|
// Textos
|
||||||
#define WINDOW_CAPTION "Volcano (©2016,2022 JailDesigner v0.6)"
|
#define WINDOW_CAPTION "Volcano (©2016,2022 JailDesigner v0.6)"
|
||||||
|
|
||||||
|
// Tamaño de bloque
|
||||||
|
#define BLOCK 8
|
||||||
|
#define HALF_BLOCK 4
|
||||||
|
|
||||||
|
// Tamaño de la pantalla real
|
||||||
|
#define SCREEN_WIDTH 320
|
||||||
|
#define SCREEN_HEIGHT 240
|
||||||
|
|
||||||
|
// Tamaño de la pantalla virtual
|
||||||
|
#define GAMECANVAS_WIDTH 320
|
||||||
|
#define GAMECANVAS_HEIGHT 240
|
||||||
|
|
||||||
const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido
|
const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido
|
||||||
|
|
||||||
const Uint8 UP = 0;
|
const Uint8 UP = 0;
|
||||||
@@ -161,16 +173,6 @@ const Uint8 TOTAL_MUSIC = 3;
|
|||||||
|
|
||||||
///////////////////////////////COFFEE CRISIS//////////////////////////////////////////////
|
///////////////////////////////COFFEE CRISIS//////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Tamaño de bloque
|
|
||||||
const Uint8 BLOCK = 8;
|
|
||||||
const Uint8 HALF_BLOCK = BLOCK / 2;
|
|
||||||
|
|
||||||
// Tamaño de la pantalla real
|
|
||||||
const int SCREEN_WIDTH = 320;
|
|
||||||
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4; // 240
|
|
||||||
|
|
||||||
// Tamaño de la pantalla que se muestra
|
// Tamaño de la pantalla que se muestra
|
||||||
const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 960
|
const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 960
|
||||||
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 720
|
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 720
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ bool Director::initSDL()
|
|||||||
printf("%i joysticks were found.\n", SDL_NumJoysticks());
|
printf("%i joysticks were found.\n", SDL_NumJoysticks());
|
||||||
std::cout << SDL_JoystickNumButtons(gameController) << " buttons\n";
|
std::cout << SDL_JoystickNumButtons(gameController) << " buttons\n";
|
||||||
|
|
||||||
//Get controller haptic device
|
// Get controller haptic device
|
||||||
controllerHaptic = SDL_HapticOpenFromJoystick(gameController);
|
controllerHaptic = SDL_HapticOpenFromJoystick(gameController);
|
||||||
if (controllerHaptic == NULL)
|
if (controllerHaptic == NULL)
|
||||||
{
|
{
|
||||||
@@ -157,7 +157,7 @@ bool Director::initSDL()
|
|||||||
{
|
{
|
||||||
printf("Haptics detected\n");
|
printf("Haptics detected\n");
|
||||||
|
|
||||||
//Get initialize rumble
|
// Get initialize rumble
|
||||||
if (SDL_HapticRumbleInit(controllerHaptic) < 0)
|
if (SDL_HapticRumbleInit(controllerHaptic) < 0)
|
||||||
{
|
{
|
||||||
printf("Warning: Unable to initialize rumble!\nSDL Error: %s\n", SDL_GetError());
|
printf("Warning: Unable to initialize rumble!\nSDL Error: %s\n", SDL_GetError());
|
||||||
@@ -212,7 +212,7 @@ bool Director::initSDL()
|
|||||||
void Director::initObjects()
|
void Director::initObjects()
|
||||||
{
|
{
|
||||||
eventHandler = new SDL_Event();
|
eventHandler = new SDL_Event();
|
||||||
text.white = new Text("",nullptr,nullptr);
|
text.white = new Text("", nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Borra los objetos del programa
|
// Borra los objetos del programa
|
||||||
@@ -347,18 +347,6 @@ bool Director::initResourceList()
|
|||||||
return checkResourceList();
|
return checkResourceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga un archivo de imagen en una textura
|
|
||||||
bool Director::loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer)
|
|
||||||
{
|
|
||||||
bool success = true;
|
|
||||||
if (!texture->loadFromFile(path, renderer))
|
|
||||||
{
|
|
||||||
printf("Failed to load %s texture!\n", path.c_str());
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carga los recursos necesarios
|
// Carga los recursos necesarios
|
||||||
bool Director::loadMedia(Uint8 section)
|
bool Director::loadMedia(Uint8 section)
|
||||||
{
|
{
|
||||||
@@ -681,4 +669,38 @@ void Director::renderGame()
|
|||||||
|
|
||||||
// Muestra el backbuffer en pantalla
|
// Muestra el backbuffer en pantalla
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
void Director::run()
|
||||||
|
{
|
||||||
|
bool quit = false;
|
||||||
|
|
||||||
|
// Comprueba si existen todos los ficheros de recursos
|
||||||
|
if (!initResourceList())
|
||||||
|
{
|
||||||
|
quit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arranca SDL y crea la ventana
|
||||||
|
if ((!quit) && (!initSDL()))
|
||||||
|
{
|
||||||
|
quit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables del juego
|
||||||
|
if (!quit)
|
||||||
|
{
|
||||||
|
initGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle del juego
|
||||||
|
if (!quit)
|
||||||
|
{
|
||||||
|
while (isRunning())
|
||||||
|
{
|
||||||
|
runGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
quitGame();
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ private:
|
|||||||
SDL_Joystick *gameController; // Manejador para el mando 1
|
SDL_Joystick *gameController; // Manejador para el mando 1
|
||||||
SDL_Haptic *controllerHaptic; // Manejador para la vibración del mando
|
SDL_Haptic *controllerHaptic; // Manejador para la vibración del mando
|
||||||
|
|
||||||
_game game; // Contiene las variables de la sección de juego
|
_game game; // Contiene las variables de la sección de juego
|
||||||
//_menu menu; // Variable con los objetos menu
|
//_menu menu; // Variable con los objetos menu
|
||||||
_resource resource; // Contiene todos los objetos y variables asociados a recursos
|
_resource resource; // Contiene todos los objetos y variables asociados a recursos
|
||||||
_options options; // Contiene todas las opciones del programa
|
_options options; // Contiene todas las opciones del programa
|
||||||
@@ -100,13 +100,6 @@ private:
|
|||||||
_section section; // Seccion actual del programa
|
_section section; // Seccion actual del programa
|
||||||
bool quit; // Indica si hay que terminar el programa
|
bool quit; // Indica si hay que terminar el programa
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Director(std::string _path);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Director();
|
|
||||||
|
|
||||||
// Inicializa todas las variables
|
// Inicializa todas las variables
|
||||||
void init(std::string _path);
|
void init(std::string _path);
|
||||||
|
|
||||||
@@ -140,9 +133,6 @@ public:
|
|||||||
// Inicializa la variable con los ficheros de recursos
|
// Inicializa la variable con los ficheros de recursos
|
||||||
bool initResourceList();
|
bool initResourceList();
|
||||||
|
|
||||||
// Carga un archivo de imagen en una textura
|
|
||||||
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer);
|
|
||||||
|
|
||||||
// Carga los recursos necesarios
|
// Carga los recursos necesarios
|
||||||
bool loadMedia(Uint8 section);
|
bool loadMedia(Uint8 section);
|
||||||
|
|
||||||
@@ -178,6 +168,16 @@ public:
|
|||||||
|
|
||||||
// Actualiza la lógica del juego
|
// Actualiza la lógica del juego
|
||||||
void updateGame();
|
void updateGame();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Director(std::string _path);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Director();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,20 +27,23 @@ int main(int argc, char *args[])
|
|||||||
// Crea el objeto director
|
// Crea el objeto director
|
||||||
Director *director = new Director(args[0]);
|
Director *director = new Director(args[0]);
|
||||||
|
|
||||||
// Comprueba si existen todos los ficheros de recursos
|
/* // Comprueba si existen todos los ficheros de recursos
|
||||||
if (!director->initResourceList())
|
if (!director->initResourceList())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Arranca SDL y crea la ventana
|
// Arranca SDL y crea la ventana
|
||||||
if (!director->initSDL())
|
if (!director->initSDL())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
director->initGame();
|
director->initGame();
|
||||||
while (director->isRunning())
|
while (director->isRunning())
|
||||||
{
|
{
|
||||||
director->runGame();
|
director->runGame();
|
||||||
}
|
}
|
||||||
director->quitGame();
|
director->quitGame(); */
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
director->run();
|
||||||
|
|
||||||
// Libera todos los recursos y cierra SDL
|
// Libera todos los recursos y cierra SDL
|
||||||
delete director;
|
delete director;
|
||||||
|
|||||||
Reference in New Issue
Block a user