Trabajando en prog.cpp
This commit is contained in:
173
source/prog.cpp
173
source/prog.cpp
@@ -3,10 +3,183 @@
|
||||
// Constructor
|
||||
Prog::Prog(std::string executablePath)
|
||||
{
|
||||
// Establece las opciones por defecto
|
||||
options = new options_t;
|
||||
options->fullScreenMode = 0;
|
||||
options->windowSize = 1;
|
||||
options->filter = FILTER_NEAREST;
|
||||
options->vSync = true;
|
||||
options->screenWidth = 320;
|
||||
options->screenHeight = 240;
|
||||
options->integerScale = true;
|
||||
options->keepAspect = true;
|
||||
|
||||
// Crea los objetos
|
||||
asset = new Asset(executablePath);
|
||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||
screen = new Screen(renderer,320,240,320,240);
|
||||
|
||||
// Inicializa las variables
|
||||
section.name = PROG_SECTION_GAME;
|
||||
|
||||
initSDL();
|
||||
initJailAudio();
|
||||
}
|
||||
|
||||
Prog::~Prog()
|
||||
{
|
||||
delete asset;
|
||||
delete input;
|
||||
delete options;
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
// Inicializa JailAudio
|
||||
void Prog::initJailAudio()
|
||||
{
|
||||
JA_Init(48000, AUDIO_S16, 2);
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
bool Prog::initSDL()
|
||||
{
|
||||
// Indicador de éxito
|
||||
bool success = true;
|
||||
|
||||
// Inicializa SDL
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicia el generador de numeros aleatorios
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Establece el filtro de la textura
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->filter).c_str()))
|
||||
{
|
||||
printf("Warning: Nearest texture filtering not enabled!\n");
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
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 (window == NULL)
|
||||
{
|
||||
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
||||
if (options->vSync)
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
else
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
if (renderer == NULL)
|
||||
{
|
||||
printf("Renderer could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicializa el color de renderizado
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(renderer, options->screenWidth, options->screenHeight);
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return success;
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros de recursos
|
||||
bool Prog::setFileList()
|
||||
{
|
||||
// Ficheros binarios
|
||||
asset->add("/data/volcano.map", data);
|
||||
asset->add("/data/config.bin", data, false);
|
||||
asset->add("/data/gamecontrollerdb.txt", data);
|
||||
|
||||
// Texturas
|
||||
asset->add("/media/gfx/actors.png", bitmap);
|
||||
asset->add("/media/gfx/bg_surface.png", bitmap);
|
||||
asset->add("/media/gfx/filter.png", bitmap);
|
||||
asset->add("/media/gfx/hud.png", bitmap);
|
||||
asset->add("/media/gfx/menu_animation.png", bitmap);
|
||||
asset->add("/media/gfx/menu.png", bitmap);
|
||||
asset->add("/media/gfx/player.png", bitmap);
|
||||
asset->add("/media/gfx/tiles_surface.png", bitmap);
|
||||
asset->add("/media/gfx/tiles_volcano.png", bitmap);
|
||||
|
||||
// Sonidos
|
||||
asset->add("/media/sound/sound_player_coin.wav", sound);
|
||||
asset->add("/media/sound/sound_player_death.wav", sound);
|
||||
asset->add("/media/sound/sound_drop_enemy.wav", sound);
|
||||
asset->add("/media/sound/sound_drop_splat.wav", sound);
|
||||
asset->add("/media/sound/sound_player_jump.wav", sound);
|
||||
asset->add("/media/sound/sound_menu_logo.wav", sound);
|
||||
asset->add("/media/sound/sound_menu_start.wav", sound);
|
||||
|
||||
// Musicas
|
||||
asset->add("/media/music/music_menu.ogg", music);
|
||||
asset->add("/media/music/music_surface.ogg", music);
|
||||
asset->add("/media/music/music_volcano.ogg", music);
|
||||
|
||||
return asset->check();
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 Prog::getSection()
|
||||
{
|
||||
return section.name;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Prog::setSection(section_t section)
|
||||
{
|
||||
this->section = section;
|
||||
}
|
||||
|
||||
void Prog::runGame()
|
||||
{
|
||||
game = new Game();
|
||||
//setSection(game->run());
|
||||
section.name = PROG_SECTION_QUIT;
|
||||
setSection(section);
|
||||
delete game;
|
||||
}
|
||||
|
||||
void Prog::run()
|
||||
{
|
||||
// Bucle principal
|
||||
while (!(getSection() == PROG_SECTION_QUIT))
|
||||
{
|
||||
switch (getSection())
|
||||
{
|
||||
case PROG_SECTION_LOGO:
|
||||
//runLogo();
|
||||
break;
|
||||
case PROG_SECTION_INTRO:
|
||||
//runIntro();
|
||||
break;
|
||||
case PROG_SECTION_TITLE:
|
||||
//runTitle();
|
||||
break;
|
||||
case PROG_SECTION_GAME:
|
||||
runGame();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user