Files
thepool/source/main.cpp
Raimon Zamora b6e9310a38 - [NEW] Menú de redefinició de tecles acabat
- [NEW] Les tecles es guarden al arxiu de config
2024-07-09 09:41:53 +02:00

134 lines
3.9 KiB
C++

#include "jgame.h"
#include "jdraw.h"
#include "jfile.h"
#include "jinput.h"
#include "editor.h"
#include "console.h"
#include "string.h"
#include "config.h"
#include <SDL2/SDL.h>
#include "m_game.h"
#include "m_menu.h"
#include "m_logo.h"
#include "m_ingame.h"
#include "m_menu_tecles.h"
#include "m_menu_audio.h"
#define M_LOGO 0
#define M_MENU 1
#define M_GAME 2
#define M_INGAME 3
#define M_MENU_TECLES 4
#define M_MENU_AUDIO 5
int current_module = M_LOGO;
int zoom = 3;
bool fullscreen = false;
char tmp[100];
void loadConfig()
{
file::setConfigFolder("thepool");
if (strcmp(file::getConfigValue("music").c_str(), "no")==0) config::setMusic(false);
const char *so = file::getConfigValue("sound").c_str();
if (strcmp(so, "basic")==0)
config::setSound(SOUND_BASIC);
else if (strcmp(so, "none")==0)
config::setSound(SOUND_NONE);
std::string txt_zoom = file::getConfigValue("zoom");
if (txt_zoom!="") zoom = SDL_atoi(txt_zoom.c_str());
std::string txt_fullscreen = file::getConfigValue("fullscreen");
if (txt_fullscreen=="yes") fullscreen = true;
static const char* nomtecles[6] = {"keyup", "keydown", "keyleft", "keyright", "keyjump", "keypick"};
for (int i=0; i<6; ++i)
{
const int value = SDL_atoi( file::getConfigValue(nomtecles[i]).c_str() );
if (value != 0) config::defineKey(i, value);
}
}
void game::init()
{
if (game::getParams(1) && strcmp(game::getParams(1), "editor")==0) editor::setDevMode();
if (editor::isDevMode())
draw::init("The Pool", 520, 240, zoom);
else {
loadConfig();
draw::init("The Pool", 320, 240, zoom, fullscreen);
console::init();
}
draw::loadPalette("test.gif");
if (editor::isDevMode()) {
current_module = M_GAME;
modules::game::init();
} else
modules::logo::init();
}
bool game::loop()
{
if (input::keyPressed(SDL_SCANCODE_F1)) {
draw::decZoom();
zoom = draw::getZoom();
file::setConfigValue("zoom", SDL_itoa(zoom, tmp, 10));
}
if (input::keyPressed(SDL_SCANCODE_F2)) {
draw::incZoom();
zoom = draw::getZoom();
file::setConfigValue("zoom", SDL_itoa(zoom, tmp, 10));
}
if (input::keyPressed(SDL_SCANCODE_F3)) {
draw::toggleFullscreen();
fullscreen = draw::getFullscreen();
file::setConfigValue("fullscreen", fullscreen?"yes":"no");
}
int option;
switch(current_module)
{
case M_LOGO:
if (!modules::logo::loop()) { modules::menu::init(); current_module = M_MENU; }
break;
case M_MENU:
option = modules::menu::loop();
if (option != OPTION_NONE) {
if (option == OPTION_EIXIR) return false;
if (option == OPTION_JUGAR) { modules::game::init(); current_module = M_GAME; }
if (option == OPTION_TECLES) { modules::menu_tecles::init(); current_module = M_MENU_TECLES; }
if (option == OPTION_AUDIO) { modules::menu_audio::init(); current_module = M_MENU_AUDIO; }
}
break;
case M_GAME:
if (!modules::game::loop()) { modules::ingame::init(); current_module = M_INGAME; }
break;
case M_INGAME:
option = modules::ingame::loop();
if (option != INGAME_NONE) {
if (option == INGAME_EIXIR) { modules::menu::init(); current_module = M_MENU; }
if (option == INGAME_CONTINUAR) { current_module = M_GAME; }
}
break;
case M_MENU_TECLES:
if (modules::menu_tecles::loop() == MENU_TECLES_TORNAR) {
modules::menu::init(); current_module = M_MENU;
}
break;
case M_MENU_AUDIO:
if (modules::menu_audio::loop() == MENU_AUDIO_TORNAR) {
modules::menu::init(); current_module = M_MENU;
}
break;
};
return true;
}