Modificado el bucle principal
This commit is contained in:
@@ -8,6 +8,18 @@
|
||||
// Textos
|
||||
#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 UP = 0;
|
||||
@@ -161,16 +173,6 @@ const Uint8 TOTAL_MUSIC = 3;
|
||||
|
||||
///////////////////////////////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
|
||||
const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 960
|
||||
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 720
|
||||
|
||||
@@ -147,7 +147,7 @@ bool Director::initSDL()
|
||||
printf("%i joysticks were found.\n", SDL_NumJoysticks());
|
||||
std::cout << SDL_JoystickNumButtons(gameController) << " buttons\n";
|
||||
|
||||
//Get controller haptic device
|
||||
// Get controller haptic device
|
||||
controllerHaptic = SDL_HapticOpenFromJoystick(gameController);
|
||||
if (controllerHaptic == NULL)
|
||||
{
|
||||
@@ -157,7 +157,7 @@ bool Director::initSDL()
|
||||
{
|
||||
printf("Haptics detected\n");
|
||||
|
||||
//Get initialize rumble
|
||||
// Get initialize rumble
|
||||
if (SDL_HapticRumbleInit(controllerHaptic) < 0)
|
||||
{
|
||||
printf("Warning: Unable to initialize rumble!\nSDL Error: %s\n", SDL_GetError());
|
||||
@@ -212,7 +212,7 @@ bool Director::initSDL()
|
||||
void Director::initObjects()
|
||||
{
|
||||
eventHandler = new SDL_Event();
|
||||
text.white = new Text("",nullptr,nullptr);
|
||||
text.white = new Text("", nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Borra los objetos del programa
|
||||
@@ -347,18 +347,6 @@ bool Director::initResourceList()
|
||||
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
|
||||
bool Director::loadMedia(Uint8 section)
|
||||
{
|
||||
@@ -681,4 +669,38 @@ void Director::renderGame()
|
||||
|
||||
// Muestra el backbuffer en pantalla
|
||||
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_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
|
||||
_resource resource; // Contiene todos los objetos y variables asociados a recursos
|
||||
_options options; // Contiene todas las opciones del programa
|
||||
@@ -100,13 +100,6 @@ private:
|
||||
_section section; // Seccion actual del programa
|
||||
bool quit; // Indica si hay que terminar el programa
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(std::string _path);
|
||||
|
||||
// Destructor
|
||||
~Director();
|
||||
|
||||
// Inicializa todas las variables
|
||||
void init(std::string _path);
|
||||
|
||||
@@ -140,9 +133,6 @@ public:
|
||||
// Inicializa la variable con los ficheros de recursos
|
||||
bool initResourceList();
|
||||
|
||||
// Carga un archivo de imagen en una textura
|
||||
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer);
|
||||
|
||||
// Carga los recursos necesarios
|
||||
bool loadMedia(Uint8 section);
|
||||
|
||||
@@ -178,6 +168,16 @@ public:
|
||||
|
||||
// Actualiza la lógica del juego
|
||||
void updateGame();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(std::string _path);
|
||||
|
||||
// Destructor
|
||||
~Director();
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,20 +27,23 @@ int main(int argc, char *args[])
|
||||
// Crea el objeto director
|
||||
Director *director = new Director(args[0]);
|
||||
|
||||
// Comprueba si existen todos los ficheros de recursos
|
||||
if (!director->initResourceList())
|
||||
return -1;
|
||||
/* // Comprueba si existen todos los ficheros de recursos
|
||||
if (!director->initResourceList())
|
||||
return -1;
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
if (!director->initSDL())
|
||||
return -1;
|
||||
// Arranca SDL y crea la ventana
|
||||
if (!director->initSDL())
|
||||
return -1;
|
||||
|
||||
director->initGame();
|
||||
while (director->isRunning())
|
||||
{
|
||||
director->runGame();
|
||||
}
|
||||
director->quitGame();
|
||||
director->initGame();
|
||||
while (director->isRunning())
|
||||
{
|
||||
director->runGame();
|
||||
}
|
||||
director->quitGame(); */
|
||||
|
||||
// Bucle principal
|
||||
director->run();
|
||||
|
||||
// Libera todos los recursos y cierra SDL
|
||||
delete director;
|
||||
|
||||
Reference in New Issue
Block a user