forked from jaildesigner-jailgames/coffee_crisis
code reorganized
This commit is contained in:
105
source/main.cpp
105
source/main.cpp
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
This source code copyrighted by JailDesigner (2020)
|
||||
started on Castalla 15-07-2020.
|
||||
Using some sample source code from Lazy Foo' Productions
|
||||
*/
|
||||
|
||||
/*Descripción del enfoque utilizado para crear el juego.
|
||||
/*
|
||||
Descripción del enfoque utilizado para crear el juego.
|
||||
|
||||
El programa contine una serie de clases/objetos básicos: la clase sprite
|
||||
permite dibujar partes de un fichero png en pantalla. La clase AnimatedSprite
|
||||
@@ -37,11 +37,11 @@ un tipo asociado diferente a NO_KIND
|
||||
*/
|
||||
|
||||
#include "ifdefs.h"
|
||||
#include "const.h"
|
||||
#include "gamedirector.h"
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "const.h"
|
||||
#include "gamedirector.h"
|
||||
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
@@ -49,82 +49,33 @@ int main(int argc, char *args[])
|
||||
srand(time(nullptr));
|
||||
|
||||
// Crea el objeto gameDirector
|
||||
GameDirector *gameDirector = new GameDirector();
|
||||
GameDirector *gameDirector = new GameDirector(args[0]);
|
||||
printf("Starting the game...\n\n");
|
||||
|
||||
// Establece el valor de la variable con el path del ejecutable
|
||||
gameDirector->setExecutablePath(args[0]);
|
||||
|
||||
// Inicializa la lista de ficheros
|
||||
gameDirector->setFileList();
|
||||
|
||||
// Comprueba que existen todos los ficheros
|
||||
if (!gameDirector->checkFileList())
|
||||
// Mientras no se quiera salir del juego
|
||||
while (!(gameDirector->exit()))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
if (!gameDirector->initSDL())
|
||||
{
|
||||
printf("Failed to initialize!\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Carga los recursos
|
||||
if (!gameDirector->loadMedia(GAME_STATE_INIT))
|
||||
switch (gameDirector->getProgSection())
|
||||
{
|
||||
printf("Failed to load media!\n");
|
||||
case PROG_SECTION_LOGO:
|
||||
gameDirector->runLogo();
|
||||
break;
|
||||
case PROG_SECTION_INTRO:
|
||||
gameDirector->runIntro();
|
||||
break;
|
||||
case PROG_SECTION_TITLE:
|
||||
gameDirector->runTitle(gameDirector->getSubsection());
|
||||
break;
|
||||
case PROG_SECTION_GAME:
|
||||
gameDirector->runGame();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicializa el objeto gameDirector
|
||||
gameDirector->init(false);
|
||||
printf("Starting the game...\n\n");
|
||||
|
||||
// Mientras no se quiera salir del juego
|
||||
while (!(gameDirector->getGameStatus() == GAME_STATE_QUIT))
|
||||
{
|
||||
switch (gameDirector->getGameStatus())
|
||||
{
|
||||
case GAME_STATE_LOGO:
|
||||
gameDirector->loadMedia(GAME_STATE_LOGO);
|
||||
gameDirector->runLogo();
|
||||
gameDirector->unLoadMedia(GAME_STATE_LOGO);
|
||||
break;
|
||||
case GAME_STATE_INTRO:
|
||||
gameDirector->loadMedia(GAME_STATE_INTRO);
|
||||
gameDirector->runIntro();
|
||||
gameDirector->unLoadMedia(GAME_STATE_INTRO);
|
||||
break;
|
||||
case GAME_STATE_TITLE:
|
||||
gameDirector->loadMedia(GAME_STATE_TITLE);
|
||||
gameDirector->runTitle();
|
||||
gameDirector->unLoadMedia(GAME_STATE_TITLE);
|
||||
break;
|
||||
case GAME_STATE_PLAYING:
|
||||
gameDirector->loadMedia(GAME_STATE_PLAYING);
|
||||
gameDirector->runGame();
|
||||
gameDirector->unLoadMedia(GAME_STATE_PLAYING);
|
||||
break;
|
||||
case GAME_STATE_GAME_OVER_SCREEN:
|
||||
gameDirector->loadMedia(GAME_STATE_GAME_OVER_SCREEN);
|
||||
gameDirector->runGameOverScreen();
|
||||
gameDirector->unLoadMedia(GAME_STATE_GAME_OVER_SCREEN);
|
||||
break;
|
||||
case GAME_STATE_INSTRUCTIONS:
|
||||
gameDirector->loadMedia(GAME_STATE_INSTRUCTIONS);
|
||||
gameDirector->runInstructions();
|
||||
gameDirector->unLoadMedia(GAME_STATE_INSTRUCTIONS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Libera todos los recursos y cierra SDL
|
||||
delete gameDirector;
|
||||
printf("Shutting down the game...\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Libera todos los recursos y cierra SDL
|
||||
delete gameDirector;
|
||||
gameDirector = nullptr;
|
||||
printf("Shutting down the game...\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user