From 15b73f1d2c96a36766605fe52c712be1d2cb2b6a Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 29 Sep 2022 11:22:29 +0200 Subject: [PATCH] TITULO bastante avanzado, se deja para el final ya que falta ver elmodo demo y demas --- source/director.cpp | 34 +- source/input.cpp | 111 ++++--- source/input.h | 12 +- source/instructions.h | 2 +- source/title.cpp | 724 ++++++++++++++++++++---------------------- source/title.h | 74 ++--- source/utils.h | 27 +- 7 files changed, 492 insertions(+), 492 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 05e212d..29376a1 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -196,19 +196,19 @@ bool Director::setFileList() asset->add("data/gfx/intro.png", t_bitmap); asset->add("data/gfx/items.png", t_bitmap); asset->add("data/gfx/logo.png", t_bitmap); - + asset->add("data/gfx/title_bg_tile.png", t_bitmap); asset->add("data/gfx/title_coffee.png", t_bitmap); asset->add("data/gfx/title_crisis.png", t_bitmap); asset->add("data/gfx/title_dust.png", t_bitmap); asset->add("data/gfx/title_dust.ani", t_data); asset->add("data/gfx/title_gradient.png", t_bitmap); - + asset->add("data/gfx/player1_head.png", t_bitmap); asset->add("data/gfx/player1_body.png", t_bitmap); asset->add("data/gfx/player1_legs.png", t_bitmap); asset->add("data/gfx/player1_death.png", t_bitmap); - + asset->add("data/gfx/player2_head.png", t_bitmap); asset->add("data/gfx/player2_body.png", t_bitmap); asset->add("data/gfx/player2_legs.png", t_bitmap); @@ -237,7 +237,6 @@ bool Director::setFileList() asset->add("data/menu/title.men", t_data); asset->add("data/menu/options.men", t_data); - return asset->check(); } @@ -245,12 +244,23 @@ bool Director::setFileList() bool Director::loadConfigFile() { // Pone unos valores por defecto + options->input.clear(); + + input_t inp; + inp.id = 0; + inp.name = "KEYBOARD"; + inp.deviceType = INPUT_USE_KEYBOARD; + options->input.push_back(inp); + + inp.id = 0; + inp.name = "GAME CONTROLLER"; + inp.deviceType = INPUT_USE_GAMECONTROLLER; + options->input.push_back(inp); + options->fullScreenMode = 0; options->windowSize = 3; options->language = ba_BA; options->difficulty = DIFFICULTY_NORMAL; - options->input[0].deviceType = INPUT_USE_KEYBOARD; - options->input[1].deviceType = INPUT_USE_GAMECONTROLLER; options->filter = FILTER_NEAREST; options->vSync = true; options->screenWidth = GAME_WIDTH; @@ -283,8 +293,8 @@ bool Director::loadConfigFile() SDL_RWwrite(file, &options->windowSize, sizeof(options->windowSize), 1); SDL_RWwrite(file, &options->language, sizeof(options->language), 1); SDL_RWwrite(file, &options->difficulty, sizeof(options->difficulty), 1); - SDL_RWwrite(file, &options->input[0].deviceType, sizeof(options->input[0].deviceType), 1); - SDL_RWwrite(file, &options->input[1].deviceType, sizeof(options->input[1].deviceType), 1); + SDL_RWwrite(file, &options->input.at(0).deviceType, sizeof(options->input.at(0).deviceType), 1); + SDL_RWwrite(file, &options->input.at(1).deviceType, sizeof(options->input.at(1).deviceType), 1); SDL_RWwrite(file, &options->filter, sizeof(options->filter), 1); SDL_RWwrite(file, &options->vSync, sizeof(options->vSync), 1); SDL_RWwrite(file, &options->screenWidth, sizeof(options->screenWidth), 1); @@ -310,8 +320,8 @@ bool Director::loadConfigFile() SDL_RWread(file, &options->windowSize, sizeof(options->windowSize), 1); SDL_RWread(file, &options->language, sizeof(options->language), 1); SDL_RWread(file, &options->difficulty, sizeof(options->difficulty), 1); - SDL_RWread(file, &options->input[0].deviceType, sizeof(options->input[0].deviceType), 1); - SDL_RWread(file, &options->input[1].deviceType, sizeof(options->input[1].deviceType), 1); + SDL_RWread(file, &options->input.at(0).deviceType, sizeof(options->input.at(0).deviceType), 1); + SDL_RWread(file, &options->input.at(1).deviceType, sizeof(options->input.at(1).deviceType), 1); SDL_RWread(file, &options->filter, sizeof(options->filter), 1); SDL_RWread(file, &options->vSync, sizeof(options->vSync), 1); SDL_RWread(file, &options->screenWidth, sizeof(options->screenWidth), 1); @@ -359,8 +369,8 @@ bool Director::saveConfigFile() SDL_RWwrite(file, &options->windowSize, sizeof(options->windowSize), 1); SDL_RWwrite(file, &options->language, sizeof(options->language), 1); SDL_RWwrite(file, &options->difficulty, sizeof(options->difficulty), 1); - SDL_RWwrite(file, &options->input[0].deviceType, sizeof(options->input[0].deviceType), 1); - SDL_RWwrite(file, &options->input[1].deviceType, sizeof(options->input[1].deviceType), 1); + SDL_RWwrite(file, &options->input.at(0).deviceType, sizeof(options->input.at(0).deviceType), 1); + SDL_RWwrite(file, &options->input.at(1).deviceType, sizeof(options->input.at(1).deviceType), 1); SDL_RWwrite(file, &options->filter, sizeof(options->filter), 1); SDL_RWwrite(file, &options->vSync, sizeof(options->vSync), 1); SDL_RWwrite(file, &options->screenWidth, sizeof(options->screenWidth), 1); diff --git a/source/input.cpp b/source/input.cpp index bcf10d6..cc0d469 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -5,38 +5,38 @@ Input::Input(std::string file) { // Fichero gamecontrollerdb.txt - mDBpath = file; + dbPath = file; // Inicializa las variables - for (int i = 0; i < 17; i++) - { - mKeyBindings[i].scancode = 0; - mKeyBindings[i].active = false; + keyBindings_t kb; + kb.scancode = 0; + kb.active = false; + keyBindings.resize(17, kb); - mGameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID; - mGameControllerBindings[i].active = false; - } + GameControllerBindings_t gcb; + gcb.button = SDL_CONTROLLER_BUTTON_INVALID; + gcb.active = false; + gameControllerBindings.resize(17, gcb); + // Comprueba si hay un mando conectado discoverGameController(); } // Destructor Input::~Input() { - for (int i = 0; i < mNumGamepads; i++) - mConnectedControllers[i] = nullptr; } // Asigna uno de los posibles inputs a una tecla del teclado void Input::bindKey(Uint8 input, SDL_Scancode code) { - mKeyBindings[input].scancode = code; + keyBindings.at(input).scancode = code; } // Asigna uno de los posibles inputs a un botón del mando void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button) { - mGameControllerBindings[input].button = button; + gameControllerBindings.at(input).button = button; } // Comprueba si un input esta activo @@ -48,24 +48,28 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index) if (device == INPUT_USE_ANY) index = 0; - if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY)) + if (device == INPUT_USE_KEYBOARD || device == INPUT_USE_ANY) { - const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr); + const Uint8 *keyStates = SDL_GetKeyboardState(nullptr); if (repeat) { - if (mKeystates[mKeyBindings[input].scancode] != 0) + if (keyStates[keyBindings.at(input).scancode] != 0) + { successKeyboard = true; + } else + { successKeyboard = false; + } } else { - if (!mKeyBindings[input].active) + if (!keyBindings.at(input).active) { - if (mKeystates[mKeyBindings[input].scancode] != 0) + if (keyStates[keyBindings.at(input).scancode] != 0) { - mKeyBindings[input].active = true; + keyBindings.at(input).active = true; successKeyboard = true; } else @@ -75,9 +79,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index) } else { - if (mKeystates[mKeyBindings[input].scancode] == 0) + if (keyStates[keyBindings.at(input).scancode] == 0) { - mKeyBindings[input].active = false; + keyBindings.at(input).active = false; successKeyboard = false; } else @@ -93,18 +97,22 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index) { if (repeat) { - if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0) + if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings[input].button) != 0) + { successGameController = true; + } else + { successGameController = false; + } } else { - if (!mGameControllerBindings[input].active) + if (!gameControllerBindings[input].active) { - if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0) + if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings[input].button) != 0) { - mGameControllerBindings[input].active = true; + gameControllerBindings[input].active = true; successGameController = true; } else @@ -114,9 +122,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index) } else { - if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0) + if (SDL_GameControllerGetButton(connectedControllers.at(index), gameControllerBindings[input].button) == 0) { - mGameControllerBindings[input].active = false; + gameControllerBindings[input].active = false; successGameController = false; } else @@ -136,45 +144,54 @@ bool Input::discoverGameController() bool found = false; if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1) + { SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); + } - if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0) - printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError()); + if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0) + { + printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError()); + } - int nJoysticks = SDL_NumJoysticks(); - mNumGamepads = 0; + const int nJoysticks = SDL_NumJoysticks(); + numGamepads = 0; // Cuenta el numero de mandos - for (int i = 0; i < nJoysticks; i++) + for (int i = 0; i < nJoysticks; ++i) + { if (SDL_IsGameController(i)) - mNumGamepads++; + { + numGamepads++; + } + } printf("\nChecking for game controllers...\n"); - printf("%i joysticks found, %i are gamepads\n", nJoysticks, mNumGamepads); + printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads); - if (mNumGamepads > 0) + if (numGamepads > 0) { found = true; - for (int i = 0; i < mNumGamepads; i++) + for (int i = 0; i < numGamepads; i++) { // Abre el mando y lo añade a la lista SDL_GameController *pad = SDL_GameControllerOpen(i); if (SDL_GameControllerGetAttached(pad) == 1) { - mConnectedControllers.push_back(pad); - std::string separator(" #"); + connectedControllers.push_back(pad); + const std::string separator(" #"); std::string name = SDL_GameControllerNameForIndex(i); name.resize(25); name = name + separator + std::to_string(i); std::cout << name << std::endl; - mControllerNames.push_back(name); + controllerNames.push_back(name); } else + { std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; + } } - //mGameController = mConnectedControllers[0]; SDL_GameControllerEventState(SDL_ENABLE); } @@ -184,23 +201,31 @@ bool Input::discoverGameController() // Comprueba si hay algun mando conectado bool Input::gameControllerFound() { - if (mNumGamepads > 0) + if (numGamepads > 0) + { return true; + } else + { return false; + } } // Obten el nombre de un mando de juego std::string Input::getControllerName(int index) { - if (mNumGamepads > 0) - return mControllerNames[index]; + if (numGamepads > 0) + { + return controllerNames.at(index); + } else + { return ""; + } } // Obten el numero de mandos conectados int Input::getNumControllers() { - return mNumGamepads; + return numGamepads; } \ No newline at end of file diff --git a/source/input.h b/source/input.h index 5910feb..62c7865 100644 --- a/source/input.h +++ b/source/input.h @@ -41,19 +41,19 @@ private: Uint8 scancode; // Scancode asociado bool active; // Indica si está activo }; - keyBindings_t mKeyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos struct GameControllerBindings_t { SDL_GameControllerButton button; // GameControllerButton asociado bool active; // Indica si está activo }; - GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos - std::vector mConnectedControllers; // Vector con todos los mandos conectados - std::vector mControllerNames; // Vector con los nombres de los mandos - int mNumGamepads; // Numero de mandos conectados - std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt + std::vector keyBindings; // Vector con las teclas asociadas a los inputs predefinidos + std::vector gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos + std::vector connectedControllers; // Vector con todos los mandos conectados + std::vector controllerNames; // Vector con los nombres de los mandos + int numGamepads; // Numero de mandos conectados + std::string dbPath; // Ruta al archivo gamecontrollerdb.txt // Comprueba si hay un mando conectado bool discoverGameController(); diff --git a/source/instructions.h b/source/instructions.h index d76942f..3118aea 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -35,7 +35,7 @@ private: Uint16 mCounter; // Contador section_t mSection; // Estado del bucle principal para saber si continua o se sale Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa - Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa + Uint32 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa bool mManualQuit; // Indica si se quiere salir del modo manual // Actualiza las variables diff --git a/source/title.cpp b/source/title.cpp index 1153d32..27aebc4 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -4,180 +4,145 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t section) { // Copia las direcciones de los punteros - mRenderer = renderer; - mScreen = screen; - mInput = input; - mAsset = asset; - mOptions = options; - mLang = lang; + this->renderer = renderer; + this->screen = screen; + this->input = input; + this->asset = asset; + this->options = options; + this->lang = lang; // Reserva memoria para los punteros propios - mEventHandler = new SDL_Event(); - mFade = new Fade(renderer); + eventHandler = new SDL_Event(); + fade = new Fade(renderer); - dustTexture = new LTexture(mRenderer, mAsset->get("title_dust.png")); - coffeeTexture = new LTexture(mRenderer, mAsset->get("title_coffee.png")); - crisisTexture = new LTexture(mRenderer, mAsset->get("title_crisis.png")); - gradientTexture = new LTexture(mRenderer, mAsset->get("title_gradient.png")); + dustTexture = new LTexture(renderer, asset->get("title_dust.png")); + coffeeTexture = new LTexture(renderer, asset->get("title_coffee.png")); + crisisTexture = new LTexture(renderer, asset->get("title_crisis.png")); + gradientTexture = new LTexture(renderer, asset->get("title_gradient.png")); - mCoffeeBitmap = new SmartSprite(coffeeTexture, mRenderer); - mCrisisBitmap = new SmartSprite(crisisTexture, mRenderer); - mDustBitmapL = new AnimatedSprite(dustTexture, mRenderer, mAsset->get("title_dust.ani")); - mDustBitmapR = new AnimatedSprite(dustTexture, mRenderer, mAsset->get("title_dust.ani")); - mGradient = new Sprite({0, 0, 256, 192}, gradientTexture, mRenderer); + coffeeBitmap = new SmartSprite(coffeeTexture, renderer); + crisisBitmap = new SmartSprite(crisisTexture, renderer); + dustBitmapL = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani")); + dustBitmapR = new AnimatedSprite(dustTexture, renderer, asset->get("title_dust.ani")); + gradient = new Sprite({0, 0, 256, 192}, gradientTexture, renderer); - mText = new Text(mAsset->get("smb2.png"), mAsset->get("smb2.txt"), mRenderer); - mText2 = new Text(mAsset->get("8bithud.png"), mAsset->get("8bithud.txt"), mRenderer); + text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); + text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); - mMenu.title = new Menu(mRenderer, mAsset, mInput, mAsset->get("title.men")); - mMenu.options = new Menu(mRenderer, mAsset, mInput, mAsset->get("options.men")); + menu.title = new Menu(renderer, asset, input, asset->get("title.men")); + menu.options = new Menu(renderer, asset, input, asset->get("options.men")); // Sonidos - mSound = JA_LoadSound(mAsset->get("title.wav").c_str()); + crashSound = JA_LoadSound(asset->get("title.wav").c_str()); // Musicas - mMusic = JA_LoadMusic(mAsset->get("title.ogg").c_str()); + titleMusic = JA_LoadMusic(asset->get("title.ogg").c_str()); // Inicializa variables - mSection = section; - mCounter = TITLE_COUNTER; - mBackgroundCounter = 0; - mBackgroundMode = rand() % 2; - mMenuVisible = false; - mMenu.active = mMenu.title; - mNextSection.name = PROG_SECTION_GAME; - mPostFade = 0; - mTicks = 0; - mTicksSpeed = 15; - mFade->init(0x17, 0x17, 0x26); - mDemo = false; + this->section = section; + counter = TITLE_COUNTER; + backgroundCounter = 0; + backgroundMode = rand() % 2; + menuVisible = false; + menu.active = menu.title; + nextSection.name = PROG_SECTION_GAME; + postFade = 0; + ticks = 0; + ticksSpeed = 15; + fade->init(0x17, 0x17, 0x26); + demo = false; // Pone valores por defecto a las opciones de control - mOptions->input[0].id = 0; - mOptions->input[0].name = "KEYBOARD"; - mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; + options->input.clear(); - mOptions->input[1].id = 0; - mOptions->input[1].name = "GAME CONTROLLER"; - mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; + input_t i; + i.id = 0; + i.name = "KEYBOARD"; + i.deviceType = INPUT_USE_KEYBOARD; + options->input.push_back(i); + + i.id = 0; + i.name = "GAME CONTROLLER"; + i.deviceType = INPUT_USE_GAMECONTROLLER; + options->input.push_back(i); // Comprueba si hay mandos conectados checkInputDevices(); - // Pone valores por defecto - mDeviceIndex[0] = mAvailableInputDevices.size() - 1; // El último dispositivo encontrado es el teclado - mDeviceIndex[1] = 0; // El primer mando encontrado. Si no ha encontrado ninguno es el teclado + // Pone valores por defecto. El primer jugador el teclado. El segundo jugador el primer mando + deviceIndex.clear(); + deviceIndex.push_back(availableInputDevices.size() - 1); // El último dispositivo encontrado es el teclado + deviceIndex.push_back(0); // El primer mando encontrado. Si no ha encontrado ninguno es el teclado // Si ha encontrado un mando se lo asigna al segundo jugador - if (mInput->gameControllerFound()) + if (input->gameControllerFound()) { - mOptions->input[1].id = mAvailableInputDevices[mDeviceIndex[1]].id; - mOptions->input[1].name = mAvailableInputDevices[mDeviceIndex[1]].name; - mOptions->input[1].deviceType = mAvailableInputDevices[mDeviceIndex[1]].deviceType; + options->input.at(1).id = availableInputDevices.at(deviceIndex.at(1)).id; + options->input.at(1).name = availableInputDevices.at(deviceIndex.at(1)).name; + options->input.at(1).deviceType = availableInputDevices.at(deviceIndex.at(1)).deviceType; } // Inicializa el bitmap de Coffee - mCoffeeBitmap->setPosX(45); - mCoffeeBitmap->setPosY(11 - 200); - mCoffeeBitmap->setWidth(167); - mCoffeeBitmap->setHeight(46); - mCoffeeBitmap->setVelX(0.0f); - mCoffeeBitmap->setVelY(2.5f); - mCoffeeBitmap->setAccelX(0.0f); - mCoffeeBitmap->setAccelY(0.1f); - mCoffeeBitmap->setSpriteClip(0, 0, 167, 46); - mCoffeeBitmap->setEnabled(true); - mCoffeeBitmap->setEnabledCounter(0); - mCoffeeBitmap->setDestX(45); - mCoffeeBitmap->setDestY(11); + coffeeBitmap->setPosX(45); + coffeeBitmap->setPosY(11 - 200); + coffeeBitmap->setWidth(167); + coffeeBitmap->setHeight(46); + coffeeBitmap->setVelX(0.0f); + coffeeBitmap->setVelY(2.5f); + coffeeBitmap->setAccelX(0.0f); + coffeeBitmap->setAccelY(0.1f); + coffeeBitmap->setSpriteClip(0, 0, 167, 46); + coffeeBitmap->setEnabled(true); + coffeeBitmap->setEnabledCounter(0); + coffeeBitmap->setDestX(45); + coffeeBitmap->setDestY(11); // Inicializa el bitmap de Crisis - mCrisisBitmap->setPosX(60); - mCrisisBitmap->setPosY(57 + 200); - mCrisisBitmap->setWidth(137); - mCrisisBitmap->setHeight(46); - mCrisisBitmap->setVelX(0.0f); - mCrisisBitmap->setVelY(-2.5f); - mCrisisBitmap->setAccelX(0.0f); - mCrisisBitmap->setAccelY(-0.1f); - mCrisisBitmap->setSpriteClip(0, 0, 137, 46); - mCrisisBitmap->setEnabled(true); - mCrisisBitmap->setEnabledCounter(0); - mCrisisBitmap->setDestX(60); - mCrisisBitmap->setDestY(57); + crisisBitmap->setPosX(60); + crisisBitmap->setPosY(57 + 200); + crisisBitmap->setWidth(137); + crisisBitmap->setHeight(46); + crisisBitmap->setVelX(0.0f); + crisisBitmap->setVelY(-2.5f); + crisisBitmap->setAccelX(0.0f); + crisisBitmap->setAccelY(-0.1f); + crisisBitmap->setSpriteClip(0, 0, 137, 46); + crisisBitmap->setEnabled(true); + crisisBitmap->setEnabledCounter(0); + crisisBitmap->setDestX(60); + crisisBitmap->setDestY(57); // Inicializa el bitmap de DustRight - mDustBitmapR->setPosX(218); - mDustBitmapR->setPosY(47); - mDustBitmapR->setWidth(16); - mDustBitmapR->setHeight(16); - mDustBitmapR->setFlip(SDL_FLIP_HORIZONTAL); + dustBitmapR->setPosX(218); + dustBitmapR->setPosY(47); + dustBitmapR->setWidth(16); + dustBitmapR->setHeight(16); + dustBitmapR->setFlip(SDL_FLIP_HORIZONTAL); // Inicializa el bitmap de DustLeft - mDustBitmapL->setPosX(33); - mDustBitmapL->setPosY(47); - mDustBitmapL->setWidth(16); - mDustBitmapL->setHeight(16); + dustBitmapL->setPosX(33); + dustBitmapL->setPosY(47); + dustBitmapL->setWidth(16); + dustBitmapL->setHeight(16); // Inicializa el sprite con el degradado - mGradient->setSpriteClip(0, 96, 256, 192); + gradient->setSpriteClip(0, 96, 256, 192); // Crea el mosaico de fondo del titulo createTiledBackground(); // Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar - mBackgroundWindow.x = 128; - mBackgroundWindow.y = 96; - mBackgroundWindow.w = GAME_WIDTH; - mBackgroundWindow.h = GAME_HEIGHT; + backgroundWindow.x = 128; + backgroundWindow.y = 96; + backgroundWindow.w = GAME_WIDTH; + backgroundWindow.h = GAME_HEIGHT; // Inicializa los valores del vector con los valores del seno for (int i = 0; i < 360; ++i) { - mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f); + sin[i] = SDL_sinf((float)i * 3.14f / 180.0f); } - // Inicializa los objetos de menu - // mMenu.title->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt")); - // mMenu.title->setName("TITLE"); - // mMenu.title->setPos(0, (14 * BLOCK) + 4); - // mMenu.title->setBackgroundType(MENU_BACKGROUND_TRANSPARENT); - // mMenu.title->addItem(mLang->getText(51), 2); // 1 PLAYER - // mMenu.title->addItem(mLang->getText(52), 7); // 2 PLAYERS - // mMenu.title->addItem(mLang->getText(1), 7); // OPTIONS - // mMenu.title->addItem(mLang->getText(3)); // QUIT - // mMenu.title->setDefaultActionWhenCancel(3); - // mMenu.title->setBackgroundColor({0x30, 0x30, 0x40}, 192); - // mMenu.title->setSelectorColor({0xe5, 0x1c, 0x23}, 0); - // mMenu.title->setSelectorTextColor({0xFF, 0xB4, 0x00}); - // mMenu.title->centerMenuOnX(SCREEN_CENTER_X); - // mMenu.title->centerMenuElementsOnX(); - - // mMenu.options->setText(mAsset->get("smb2.png"), mAsset->get("smb2.txt")); - // mMenu.options->setName("OPTIONS"); - // mMenu.options->setPos(0, BLOCK); - // mMenu.options->setBackgroundType(MENU_BACKGROUND_TRANSPARENT); - // mMenu.options->addItem(mLang->getText(59), 7); // (0) DIFFICULTY - // mMenu.options->addItem(mLang->getText(62), 2, true, false, true); // (1) PLAYER 1 CONTROLS - // mMenu.options->addItem(mLang->getText(69), 7, false, false); // (2) KEYBOARD - // mMenu.options->addItem(mLang->getText(63), 2, true, false, true); // (3) PLAYER 2 CONTROLS - // mMenu.options->addItem(mLang->getText(70), 7, false, false); // (4) GAME CONTROLLER - // mMenu.options->addItem(mLang->getText(8), 7); // (5) LANGUAGE - // mMenu.options->addItem(mLang->getText(58), 2, true, false, true); // (6) DISPLAY MODE - // mMenu.options->addItem(mLang->getText(4), 7, false, false); // (7) WINDOW - // mMenu.options->addItem(mLang->getText(7), 2); // (8) WINDOW SIZE - // mMenu.options->addItem(mLang->getText(60), 2); // (9) FILTER - // mMenu.options->addItem(mLang->getText(61), 7); // (10) VSYNC - // mMenu.options->addItem(mLang->getText(2), 7); // (11) HOW TO PLAY - // mMenu.options->addItem(mLang->getText(9), 2); // (12) ACCEPT - // mMenu.options->addItem(mLang->getText(10)); // (13) CANCEL - // mMenu.options->setDefaultActionWhenCancel(13); - // mMenu.options->setBackgroundColor({0x30, 0x30, 0x40}, 192); - // mMenu.options->setSelectorColor({0xe5, 0x1c, 0x23}, 255); - // mMenu.options->setSelectorTextColor({0xFF, 0xF1, 0x76}); - // mMenu.options->centerMenuOnX(SCREEN_CENTER_X); - // mMenu.options->centerMenuOnY(SCREEN_CENTER_Y); - // Actualiza los textos de los menus // updateMenuLabels(); } @@ -185,8 +150,8 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, // Destructor Title::~Title() { - delete mEventHandler; - delete mFade; + delete eventHandler; + delete fade; dustTexture->unload(); delete dustTexture; @@ -200,22 +165,22 @@ Title::~Title() gradientTexture->unload(); delete gradientTexture; - delete mCoffeeBitmap; - delete mCrisisBitmap; - delete mDustBitmapL; - delete mDustBitmapR; - delete mGradient; + delete coffeeBitmap; + delete crisisBitmap; + delete dustBitmapL; + delete dustBitmapR; + delete gradient; - delete mText; - delete mText2; + delete text1; + delete text2; - delete mMenu.title; - delete mMenu.options; + delete menu.title; + delete menu.options; - JA_DeleteSound(mSound); - JA_DeleteMusic(mMusic); + JA_DeleteSound(crashSound); + JA_DeleteMusic(titleMusic); - SDL_DestroyTexture(mBackground); + SDL_DestroyTexture(background); } // Actualiza las variables del objeto @@ -225,28 +190,28 @@ void Title::update() checkEventHandler(); // Calcula la lógica de los objetos - if (SDL_GetTicks() - mTicks > mTicksSpeed) + if (SDL_GetTicks() - ticks > ticksSpeed) { // Actualiza el contador de ticks - mTicks = SDL_GetTicks(); + ticks = SDL_GetTicks(); - switch (mSection.subsection) + switch (section.subsection) { // Sección 1 - Titulo desplazandose case TITLE_SECTION_1: { // Actualiza los objetos - mCoffeeBitmap->update(); - mCrisisBitmap->update(); + coffeeBitmap->update(); + crisisBitmap->update(); // Si los objetos han llegado a su destino, cambiamos de Sección - if (mCoffeeBitmap->hasFinished() && mCrisisBitmap->hasFinished()) + if (coffeeBitmap->hasFinished() && crisisBitmap->hasFinished()) { - mSection.subsection = TITLE_SECTION_2; + section.subsection = TITLE_SECTION_2; // Pantallazo blanco - SDL_SetRenderDrawColor(mRenderer, 0xFF, 0xFF, 0xFF, 0xFF); - SDL_RenderClear(mRenderer); - SDL_RenderPresent(mRenderer); + SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); + SDL_RenderClear(renderer); + SDL_RenderPresent(renderer); } } break; @@ -263,50 +228,50 @@ void Title::update() // Reproduce la música if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) { - JA_PlayMusic(mMusic); + JA_PlayMusic(titleMusic); } // Actualiza el contador de ticks - mTicks = SDL_GetTicks(); + ticks = SDL_GetTicks(); - mDustBitmapR->update(); - mDustBitmapL->update(); + dustBitmapR->update(); + dustBitmapL->update(); // Actualiza la lógica del titulo - mMenu.active->update(); - mFade->update(); + menu.active->update(); + fade->update(); - if (mFade->hasEnded()) + if (fade->hasEnded()) { - switch (mPostFade) + switch (postFade) { case 0: // 1 PLAYER - mSection.name = PROG_SECTION_GAME; - mSection.subsection = GAME_SECTION_PLAY_1P; + section.name = PROG_SECTION_GAME; + section.subsection = GAME_SECTION_PLAY_1P; JA_StopMusic(); break; case 1: // 2 PLAYERS - mSection.name = PROG_SECTION_GAME; - mSection.subsection = GAME_SECTION_PLAY_2P; + section.name = PROG_SECTION_GAME; + section.subsection = GAME_SECTION_PLAY_2P; JA_StopMusic(); break; case 2: // QUIT - mSection.name = PROG_SECTION_QUIT; + section.name = PROG_SECTION_QUIT; JA_StopMusic(); break; case 3: // TIME OUT - mCounter = TITLE_COUNTER; - mMenu.active->reset(); - if (mDemo) + counter = TITLE_COUNTER; + menu.active->reset(); + if (demo) { runDemoGame(); runInstructions(INSTRUCTIONS_MODE_AUTO); } else - mSection.name = PROG_SECTION_LOGO; + section.name = PROG_SECTION_LOGO; break; default: @@ -318,31 +283,31 @@ void Title::update() updateBG(); // Comprueba las entradas para el menu - if (mMenuVisible == true) + if (menuVisible == true) { - mMenu.active->checkInput(); + menu.active->checkInput(); } // Comprueba si se ha seleccionado algún item del menú - if (mMenu.active->getName() == "TITLE") + if (menu.active->getName() == "TITLE") { - switch (mMenu.active->getItemSelected()) + switch (menu.active->getItemSelected()) { case 0: // 1 PLAYER - mPostFade = 0; - mFade->activateFade(); + postFade = 0; + fade->activateFade(); break; case 1: // 2 PLAYERS - mPostFade = 1; - mFade->activateFade(); + postFade = 1; + fade->activateFade(); break; case 2: // OPTIONS - mMenu.active = mMenu.options; - mOptionsPrevious = *mOptions; + menu.active = menu.options; + optionsPrevious = *options; break; case 3: // QUIT - mPostFade = 2; - mFade->activateFade(); + postFade = 2; + fade->activateFade(); break; default: @@ -351,17 +316,17 @@ void Title::update() } // Comprueba si se ha seleccionado algún item de opciones - if (mMenu.active->getName() == "OPTIONS") + if (menu.active->getName() == "OPTIONS") { - switch (mMenu.active->getItemSelected()) + switch (menu.active->getItemSelected()) { case 0: // Difficulty - if (mOptions->difficulty == DIFFICULTY_EASY) - mOptions->difficulty = DIFFICULTY_NORMAL; - else if (mOptions->difficulty == DIFFICULTY_NORMAL) - mOptions->difficulty = DIFFICULTY_HARD; + if (options->difficulty == DIFFICULTY_EASY) + options->difficulty = DIFFICULTY_NORMAL; + else if (options->difficulty == DIFFICULTY_NORMAL) + options->difficulty = DIFFICULTY_HARD; else - mOptions->difficulty = DIFFICULTY_EASY; + options->difficulty = DIFFICULTY_EASY; updateMenuLabels(); break; case 1: // PLAYER 1 CONTROLS @@ -373,43 +338,43 @@ void Title::update() updateMenuLabels(); break; case 5: // Language - mOptions->language++; - if (mOptions->language == 3) - mOptions->language = 0; + options->language++; + if (options->language == 3) + options->language = 0; updateMenuLabels(); break; case 6: // Display mode switchFullScreenModeVar(); - if (mOptions->fullScreenMode != 0) + if (options->fullScreenMode != 0) { - mMenu.options->setSelectable(8, false); - mMenu.options->setGreyed(8, true); + menu.options->setSelectable(8, false); + menu.options->setGreyed(8, true); } else { - mMenu.options->setSelectable(8, true); - mMenu.options->setGreyed(8, false); + menu.options->setSelectable(8, true); + menu.options->setGreyed(8, false); } updateMenuLabels(); break; case 8: // Windows size - mOptions->windowSize++; - if (mOptions->windowSize == 5) - mOptions->windowSize = 1; + options->windowSize++; + if (options->windowSize == 5) + options->windowSize = 1; updateMenuLabels(); break; case 9: // FILTER - if (mOptions->filter == FILTER_LINEAL) - mOptions->filter = FILTER_NEAREST; + if (options->filter == FILTER_LINEAL) + options->filter = FILTER_NEAREST; else - mOptions->filter = FILTER_LINEAL; + options->filter = FILTER_LINEAL; updateMenuLabels(); break; case 10: // VSYNC - if (mOptions->vSync) - mOptions->vSync = false; + if (options->vSync) + options->vSync = false; else - mOptions->vSync = true; + options->vSync = true; updateMenuLabels(); break; case 11: // HOW TO PLAY @@ -417,14 +382,14 @@ void Title::update() break; case 12: // ACCEPT applyOptions(); - mMenu.active->reset(); - mMenu.active = mMenu.title; + menu.active->reset(); + menu.active = menu.title; break; case 13: // CANCEL - mOptions = &mOptionsPrevious; + options = &optionsPrevious; updateMenuLabels(); - mMenu.active->reset(); - mMenu.active = mMenu.title; + menu.active->reset(); + menu.active = menu.title; break; default: @@ -432,9 +397,9 @@ void Title::update() } } - if (mMenu.active->getName() == "TITLE") + if (menu.active->getName() == "TITLE") { - mCounter--; + counter--; } } @@ -449,60 +414,60 @@ void Title::update() // Dibuja el objeto en pantalla void Title::render() { - switch (mSection.subsection) + switch (section.subsection) { // Sección 1 - Titulo desplazandose case TITLE_SECTION_1: { - mScreen->start(); // Prepara para empezar a dibujar en la textura de juego - mScreen->clean(bgColor); // Limpia la pantalla - SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, nullptr); // Dibuja el tileado de fondo - mGradient->render(); // Dibuja el degradado - mCoffeeBitmap->render(); // Dibuja los objetos - mCrisisBitmap->render(); // Dibuja los objetos - mScreen->blit(); // Vuelca el contenido del renderizador en pantalla + screen->start(); // Prepara para empezar a dibujar en la textura de juego + screen->clean(bgColor); // Limpia la pantalla + SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr); // Dibuja el tileado de fondo + gradient->render(); // Dibuja el degradado + coffeeBitmap->render(); // Dibuja los objetos + crisisBitmap->render(); // Dibuja los objetos + screen->blit(); // Vuelca el contenido del renderizador en pantalla } break; // Sección 2 - Titulo vibrando case TITLE_SECTION_2: { // Reproduce el efecto sonoro - JA_PlaySound(mSound); + JA_PlaySound(crashSound); // Agita la pantalla const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0}; - const int a = mCoffeeBitmap->getPosX(); - const int b = mCrisisBitmap->getPosX(); + const int a = coffeeBitmap->getPosX(); + const int b = crisisBitmap->getPosX(); for (int n = 0; n < 11 * 3; ++n) { // Prepara para empezar a dibujar en la textura de juego - mScreen->start(); + screen->start(); // Limpia la pantalla - mScreen->clean(bgColor); + screen->clean(bgColor); // Dibuja el tileado de fondo - SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, nullptr); + SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr); // Dibuja el degradado - mGradient->render(); + gradient->render(); // Dibuja los objetos - mCoffeeBitmap->setPosX(a + v[n / 3]); - mCrisisBitmap->setPosX(b + v[n / 3]); - mCoffeeBitmap->render(); - mCrisisBitmap->render(); + coffeeBitmap->setPosX(a + v[n / 3]); + crisisBitmap->setPosX(b + v[n / 3]); + coffeeBitmap->render(); + crisisBitmap->render(); - mDustBitmapR->update(); - mDustBitmapL->update(); - mDustBitmapR->render(); - mDustBitmapL->render(); + dustBitmapR->update(); + dustBitmapL->update(); + dustBitmapR->render(); + dustBitmapL->render(); // Vuelca el contenido del renderizador en pantalla - mScreen->blit(); + screen->blit(); } - mSection.subsection = TITLE_SECTION_3; + section.subsection = TITLE_SECTION_3; } break; @@ -510,47 +475,47 @@ void Title::render() // Sección 3 - La pantalla de titulo con el menú y la música case TITLE_SECTION_3: { // Prepara para empezar a dibujar en la textura de juego - mScreen->start(); + screen->start(); // Limpia la pantalla - mScreen->clean(bgColor); + screen->clean(bgColor); // Dibuja el tileado de fondo - SDL_RenderCopy(mRenderer, mBackground, &mBackgroundWindow, nullptr); + SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr); // Dibuja el degradado - mGradient->render(); + gradient->render(); // Dibuja los objetos - if (mMenu.active->getName() != "OPTIONS") + if (menu.active->getName() != "OPTIONS") { // Bitmaps con el logo/titulo del juego - mCoffeeBitmap->render(); - mCrisisBitmap->render(); + coffeeBitmap->render(); + crisisBitmap->render(); // Texto con el copyright y versión - mText2->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor); + text2->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, GAME_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor); } - if (mMenuVisible == true) + if (menuVisible == true) { - mMenu.active->render(); + menu.active->render(); } - mDustBitmapR->render(); - mDustBitmapL->render(); + dustBitmapR->render(); + dustBitmapL->render(); // PRESS ANY KEY! - if ((mCounter % 50 > 14) && (mMenuVisible == false)) + if ((counter % 50 > 14) && (menuVisible == false)) { - mText->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, PLAY_AREA_THIRD_QUARTER_Y + BLOCK, mLang->getText(23), 1, noColor, 1, shdwTxtColor); + text1->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, PLAY_AREA_THIRD_QUARTER_Y + BLOCK, lang->getText(23), 1, noColor, 1, shdwTxtColor); } // Fade - mFade->render(); + fade->render(); // Vuelca el contenido del renderizador en pantalla - mScreen->blit(); + screen->blit(); } break; @@ -563,24 +528,24 @@ void Title::render() void Title::checkEventHandler() { // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(mEventHandler) != 0) + while (SDL_PollEvent(eventHandler) != 0) { // Evento de salida de la aplicación - if (mEventHandler->type == SDL_QUIT) + if (eventHandler->type == SDL_QUIT) { - mSection.name = PROG_SECTION_QUIT; + section.name = PROG_SECTION_QUIT; break; } - if (mSection.subsection == TITLE_SECTION_3) + if (section.subsection == TITLE_SECTION_3) { // Si se pulsa alguna tecla durante la tercera sección del titulo - if ((mEventHandler->type == SDL_KEYUP) || (mEventHandler->type == SDL_JOYBUTTONUP)) + if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP)) { // Muestra el menu - mMenuVisible = true; + menuVisible = true; // Reinicia el contador - mCounter = TITLE_COUNTER; + counter = TITLE_COUNTER; } } } @@ -589,36 +554,36 @@ void Title::checkEventHandler() // Actualiza el tileado de fondo void Title::updateBG() { - if (mBackgroundMode == 0) + if (backgroundMode == 0) { // El tileado de fondo se desplaza en diagonal - ++mBackgroundWindow.x %= 64; - ++mBackgroundWindow.y %= 64; + ++backgroundWindow.x %= 64; + ++backgroundWindow.y %= 64; } else { // El tileado de fondo se desplaza en circulo - ++mBackgroundCounter %= 360; - mBackgroundWindow.x = 128 + (int(mSin[(mBackgroundCounter + 270) % 360] * 128)); - mBackgroundWindow.y = 96 + (int(mSin[(360 - mBackgroundCounter) % 360] * 96)); + ++backgroundCounter %= 360; + backgroundWindow.x = 128 + (int(sin[(backgroundCounter + 270) % 360] * 128)); + backgroundWindow.y = 96 + (int(sin[(360 - backgroundCounter) % 360] * 96)); } } // Cambia el valor de la variable de modo de pantalla completa void Title::switchFullScreenModeVar() { - switch (mOptions->fullScreenMode) + switch (options->fullScreenMode) { case 0: - mOptions->fullScreenMode = SDL_WINDOW_FULLSCREEN; + options->fullScreenMode = SDL_WINDOW_FULLSCREEN; break; case SDL_WINDOW_FULLSCREEN: - mOptions->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP; + options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP; break; case SDL_WINDOW_FULLSCREEN_DESKTOP: - mOptions->fullScreenMode = 0; + options->fullScreenMode = 0; break; default: - mOptions->fullScreenMode = 0; + options->fullScreenMode = 0; break; } } @@ -628,181 +593,181 @@ void Title::updateMenuLabels() { int i = 0; // DIFFICULTY - switch (mOptions->difficulty) + switch (options->difficulty) { case DIFFICULTY_EASY: - mMenu.options->setItemCaption(i, mLang->getText(59) + ": " + mLang->getText(66)); // EASY + menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(66)); // EASY break; case DIFFICULTY_NORMAL: - mMenu.options->setItemCaption(i, mLang->getText(59) + ": " + mLang->getText(67)); // NORMAL + menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(67)); // NORMAL break; case DIFFICULTY_HARD: - mMenu.options->setItemCaption(i, mLang->getText(59) + ": " + mLang->getText(68)); // HARD + menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(68)); // HARD break; default: - mMenu.options->setItemCaption(i, mLang->getText(59) + ": " + mLang->getText(67)); // NORMAL + menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(67)); // NORMAL break; } i++; // PLAYER 1 CONTROLS - mMenu.options->setItemCaption(i, mLang->getText(62)); + menu.options->setItemCaption(i, lang->getText(62)); i++; // PLAYER 1 CONTROLS - OPTIONS - switch (mOptions->input[0].deviceType) + switch (options->input[0].deviceType) { case INPUT_USE_KEYBOARD: - mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD - mMenu.options->setGreyed(i, false); + menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD + menu.options->setGreyed(i, false); break; case INPUT_USE_GAMECONTROLLER: - mMenu.options->setItemCaption(i, mLang->getText(70)); // GAME CONTROLLER - if (!mInput->gameControllerFound()) - mMenu.options->setGreyed(i, true); + menu.options->setItemCaption(i, lang->getText(70)); // GAME CONTROLLER + if (!input->gameControllerFound()) + menu.options->setGreyed(i, true); else { - mMenu.options->setGreyed(i, false); - mMenu.options->setItemCaption(i, mOptions->input[0].name); + menu.options->setGreyed(i, false); + menu.options->setItemCaption(i, options->input[0].name); } break; default: - mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD + menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD break; } i++; // PLAYER 2 CONTROLS - mMenu.options->setItemCaption(i, mLang->getText(63)); + menu.options->setItemCaption(i, lang->getText(63)); i++; // PLAYER 2 CONTROLS - OPTIONS - switch (mOptions->input[1].deviceType) + switch (options->input[1].deviceType) { case INPUT_USE_KEYBOARD: - mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD - mMenu.options->setGreyed(i, false); + menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD + menu.options->setGreyed(i, false); break; case INPUT_USE_GAMECONTROLLER: - mMenu.options->setItemCaption(i, mLang->getText(70)); // GAME CONTROLLER - if (!mInput->gameControllerFound()) - mMenu.options->setGreyed(i, true); + menu.options->setItemCaption(i, lang->getText(70)); // GAME CONTROLLER + if (!input->gameControllerFound()) + menu.options->setGreyed(i, true); else { - mMenu.options->setGreyed(i, false); - mMenu.options->setItemCaption(i, mOptions->input[1].name); + menu.options->setGreyed(i, false); + menu.options->setItemCaption(i, options->input[1].name); } break; default: - mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD + menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD break; } i++; // LANGUAGE - switch (mOptions->language) + switch (options->language) { case es_ES: - mMenu.options->setItemCaption(i, mLang->getText(8) + ": " + mLang->getText(24)); // SPANISH + menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(24)); // SPANISH break; case ba_BA: - mMenu.options->setItemCaption(i, mLang->getText(8) + ": " + mLang->getText(25)); // VALENCIAN + menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(25)); // VALENCIAN break; case en_UK: - mMenu.options->setItemCaption(i, mLang->getText(8) + ": " + mLang->getText(26)); // ENGLISH + menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(26)); // ENGLISH break; default: - mMenu.options->setItemCaption(i, mLang->getText(8) + ": " + mLang->getText(26)); // ENGLISH + menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(26)); // ENGLISH break; } i++; // DISPLAY MODE - mMenu.options->setItemCaption(i, mLang->getText(58)); + menu.options->setItemCaption(i, lang->getText(58)); i++; // DISPLAY MODE - OPTIONS - switch (mOptions->fullScreenMode) + switch (options->fullScreenMode) { case 0: - mMenu.options->setItemCaption(i, mLang->getText(4)); // WINDOW + menu.options->setItemCaption(i, lang->getText(4)); // WINDOW break; case SDL_WINDOW_FULLSCREEN: - mMenu.options->setItemCaption(i, mLang->getText(5)); // FULLSCREEN + menu.options->setItemCaption(i, lang->getText(5)); // FULLSCREEN break; case SDL_WINDOW_FULLSCREEN_DESKTOP: - mMenu.options->setItemCaption(i, mLang->getText(6)); // FAKE FULLSCREEN + menu.options->setItemCaption(i, lang->getText(6)); // FAKE FULLSCREEN break; default: - mMenu.options->setItemCaption(i, mLang->getText(4)); // WINDOW + menu.options->setItemCaption(i, lang->getText(4)); // WINDOW break; } i++; // WINDOW SIZE - mMenu.options->setItemCaption(i, mLang->getText(7) + " x" + std::to_string(mOptions->windowSize)); // WINDOW SIZE + menu.options->setItemCaption(i, lang->getText(7) + " x" + std::to_string(options->windowSize)); // WINDOW SIZE i++; // FILTER - if (mOptions->filter == FILTER_LINEAL) - mMenu.options->setItemCaption(i, mLang->getText(60) + ": " + mLang->getText(71)); // BILINEAL + if (options->filter == FILTER_LINEAL) + menu.options->setItemCaption(i, lang->getText(60) + ": " + lang->getText(71)); // BILINEAL else - mMenu.options->setItemCaption(i, mLang->getText(60) + ": " + mLang->getText(72)); // LINEAL + menu.options->setItemCaption(i, lang->getText(60) + ": " + lang->getText(72)); // LINEAL i++; // VSYNC - if (mOptions->vSync) - mMenu.options->setItemCaption(i, mLang->getText(61) + ": " + mLang->getText(73)); // ON + if (options->vSync) + menu.options->setItemCaption(i, lang->getText(61) + ": " + lang->getText(73)); // ON else - mMenu.options->setItemCaption(i, mLang->getText(61) + ": " + mLang->getText(74)); // OFF + menu.options->setItemCaption(i, lang->getText(61) + ": " + lang->getText(74)); // OFF i++; // HOW TO PLAY - mMenu.options->setItemCaption(i, mLang->getText(2)); + menu.options->setItemCaption(i, lang->getText(2)); i++; // ACCEPT - mMenu.options->setItemCaption(i, mLang->getText(9)); // ACCEPT + menu.options->setItemCaption(i, lang->getText(9)); // ACCEPT i++; // CANCEL - mMenu.options->setItemCaption(i, mLang->getText(10)); // CANCEL + menu.options->setItemCaption(i, lang->getText(10)); // CANCEL // Recoloca el menu de opciones - mMenu.options->centerMenuOnX(SCREEN_CENTER_X); - mMenu.options->centerMenuOnY(SCREEN_CENTER_Y); - mMenu.options->centerMenuElementsOnX(); + menu.options->centerMenuOnX(SCREEN_CENTER_X); + menu.options->centerMenuOnY(SCREEN_CENTER_Y); + menu.options->centerMenuElementsOnX(); // Establece las etiquetas del menu de titulo - mMenu.title->setItemCaption(0, mLang->getText(51)); // 1 PLAYER - mMenu.title->setItemCaption(1, mLang->getText(52)); // 2 PLAYERS - mMenu.title->setItemCaption(2, mLang->getText(1)); // OPTIONS - mMenu.title->setItemCaption(3, mLang->getText(3)); // QUIT + menu.title->setItemCaption(0, lang->getText(51)); // 1 PLAYER + menu.title->setItemCaption(1, lang->getText(52)); // 2 PLAYERS + menu.title->setItemCaption(2, lang->getText(1)); // OPTIONS + menu.title->setItemCaption(3, lang->getText(3)); // QUIT // Recoloca el menu de titulo - mMenu.title->centerMenuOnX(SCREEN_CENTER_X); - mMenu.title->centerMenuElementsOnX(); + menu.title->centerMenuOnX(SCREEN_CENTER_X); + menu.title->centerMenuElementsOnX(); } // Aplica las opciones de menu seleccionadas void Title::applyOptions() { - mScreen->setVideoMode(mOptions->fullScreenMode); + screen->setVideoMode(options->fullScreenMode); - mLang->setLang(mOptions->language); + lang->setLang(options->language); updateMenuLabels(); createTiledBackground(); @@ -811,89 +776,88 @@ void Title::applyOptions() // Bucle para el titulo del juego section_t Title::run() { - while (mSection.name == PROG_SECTION_TITLE) + while (section.name == PROG_SECTION_TITLE) { update(); render(); // Sección 3 - La pantalla de titulo con el menú y la música // Sección Instrucciones - // if (mSection.subsection == TITLE_SECTION_INSTRUCTIONS) + // if (section.subsection == TITLE_SECTION_INSTRUCTIONS) //{ // runInstructions(INSTRUCTIONS_MODE_AUTO); //} } - return mSection; + return section; } // Ejecuta la parte donde se muestran las instrucciones void Title::runInstructions(Uint8 mode) { - mInstructions = new Instructions(mRenderer, mScreen, mAsset, mLang); - mInstructions->run(mode); - delete mInstructions; + instructions = new Instructions(renderer, screen, asset, lang); + instructions->run(mode); + delete instructions; } // Ejecuta el juego en modo demo void Title::runDemoGame() { - mDemoGame = new Game(1, 0, mRenderer, mScreen, mAsset, mLang, mInput, true, mOptions); - mDemoGame->run(); - delete mDemoGame; + demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options); + demoGame->run(); + delete demoGame; } // Modifica las opciones para los controles de los jugadores bool Title::updatePlayerInputs(int numPlayer) { - const int numDevices = mAvailableInputDevices.size(); + const int numDevices = availableInputDevices.size(); - // Si no hay mandos se deja todo de manera prefijada - if (!mInput->gameControllerFound()) - { - mDeviceIndex[0] = 0; - mDeviceIndex[1] = 0; + if (!input->gameControllerFound()) + { // Si no hay mandos se deja todo de manera prefijada + deviceIndex.at(0) = 0; + deviceIndex.at(1) = 0; - mOptions->input[0].id = -1; - mOptions->input[0].name = "KEYBOARD"; - mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; + options->input.at(0).id = -1; + options->input.at(0).name = "KEYBOARD"; + options->input.at(0).deviceType = INPUT_USE_KEYBOARD; - mOptions->input[1].id = 0; - mOptions->input[1].name = "GAME CONTROLLER"; - mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; + options->input.at(1).id = 0; + options->input.at(1).name = "GAME CONTROLLER"; + options->input.at(1).deviceType = INPUT_USE_GAMECONTROLLER; return true; } - else // Si hay mas de un dispositivo, se recorre el vector - { + else + { // Si hay mas de un dispositivo, se recorre el vector printf("numplayer:%i\n", numPlayer); - printf("deviceindex:%i\n", mDeviceIndex[numPlayer]); + printf("deviceindex:%i\n", deviceIndex.at(numPlayer)); // Incrementa el indice - if (mDeviceIndex[numPlayer] < numDevices - 1) + if (deviceIndex.at(numPlayer) < numDevices - 1) { - mDeviceIndex[numPlayer]++; + deviceIndex.at(numPlayer)++; } else { - mDeviceIndex[numPlayer] = 0; + deviceIndex.at(numPlayer) = 0; } - printf("deviceindex:%i\n", mDeviceIndex[numPlayer]); + printf("deviceindex:%i\n", deviceIndex.at(numPlayer)); // Si coincide con el del otro jugador, se lo intercambian - if (mDeviceIndex[0] == mDeviceIndex[1]) + if (deviceIndex.at(0) == deviceIndex.at(1)) { const int theOtherPlayer = (numPlayer + 1) % 2; - mDeviceIndex[theOtherPlayer]--; - if (mDeviceIndex[theOtherPlayer] < 0) + deviceIndex.at(theOtherPlayer)--; + if (deviceIndex.at(theOtherPlayer) < 0) { - mDeviceIndex[theOtherPlayer] = numDevices - 1; + deviceIndex.at(theOtherPlayer) = numDevices - 1; } } // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador - mOptions->input[0] = mAvailableInputDevices[mDeviceIndex[0]]; - mOptions->input[1] = mAvailableInputDevices[mDeviceIndex[1]]; + options->input[0] = availableInputDevices.at(deviceIndex.at(0)); + options->input[1] = availableInputDevices.at(deviceIndex.at(1)); return true; } @@ -903,20 +867,20 @@ bool Title::updatePlayerInputs(int numPlayer) void Title::createTiledBackground() { // Crea la textura para el mosaico de fondo - mBackground = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH * 2, GAME_HEIGHT * 2); - if (mBackground == nullptr) + background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAME_WIDTH * 2, GAME_HEIGHT * 2); + if (background == nullptr) { printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError()); } // Crea los objetos para pintar en la textura de fondo - LTexture *bgTileTexture = new LTexture(mRenderer, mAsset->get("title_bg_tile.png")); - Sprite *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, mRenderer); + LTexture *bgTileTexture = new LTexture(renderer, asset->get("title_bg_tile.png")); + Sprite *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, renderer); // Prepara para dibujar sobre la textura - SDL_SetRenderTarget(mRenderer, mBackground); - SDL_SetRenderDrawColor(mRenderer, 0x43, 0x43, 0x4F, 0xFF); - SDL_RenderClear(mRenderer); + SDL_SetRenderTarget(renderer, background); + SDL_SetRenderDrawColor(renderer, 0x43, 0x43, 0x4F, 0xFF); + SDL_RenderClear(renderer); // Rellena la textura con el tile tile->setSpriteClip(0, 0, 64, 64); @@ -931,7 +895,7 @@ void Title::createTiledBackground() } // Vuelve a colocar el renderizador apuntando a la pantalla - SDL_SetRenderTarget(mRenderer, nullptr); + SDL_SetRenderTarget(renderer, nullptr); // Libera la memoria utilizada por los objetos bgTileTexture->unload(); @@ -943,25 +907,25 @@ void Title::createTiledBackground() void Title::checkInputDevices() { printf("Filling devices for options menu...\n"); - int numControllers = mInput->getNumControllers(); - mAvailableInputDevices.clear(); + const int numControllers = input->getNumControllers(); + availableInputDevices.clear(); input_t temp; // Añade todos los mandos if (numControllers > 0) - for (int i = 0; i < numControllers; i++) + for (int i = 0; i < numControllers; ++i) { temp.id = i; - temp.name = mInput->getControllerName(i); + temp.name = input->getControllerName(i); temp.deviceType = INPUT_USE_GAMECONTROLLER; - mAvailableInputDevices.push_back(temp); - printf("Device %i:\t%s\n", (int)mAvailableInputDevices.size(), temp.name.c_str()); + availableInputDevices.push_back(temp); + printf("Device %i:\t%s\n", (int)availableInputDevices.size(), temp.name.c_str()); } // Añade el teclado al final temp.id = -1; temp.name = "KEYBOARD"; temp.deviceType = INPUT_USE_KEYBOARD; - mAvailableInputDevices.push_back(temp); - printf("Device %i:\t%s\n\n", (int)mAvailableInputDevices.size(), temp.name.c_str()); + availableInputDevices.push_back(temp); + printf("Device %i:\t%s\n\n", (int)availableInputDevices.size(), temp.name.c_str()); } \ No newline at end of file diff --git a/source/title.h b/source/title.h index 17c660f..1db9a83 100644 --- a/source/title.h +++ b/source/title.h @@ -42,54 +42,54 @@ private: }; // Objetos - SDL_Renderer *mRenderer; // El renderizador de la ventana - Screen *mScreen; // Objeto encargado de dibujar en pantalla - Asset *mAsset; // Objeto que gestiona todos los ficheros de recursos - Input *mInput; // Objeto para leer las entradas de teclado o mando - Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas - Instructions *mInstructions; // Objeto para la sección de las instrucciones - Game *mDemoGame; // Objeto para lanzar la demo del juego - SDL_Event *mEventHandler; // Manejador de eventos + SDL_Renderer *renderer; // El renderizador de la ventana + Screen *screen; // Objeto encargado de dibujar en pantalla + Asset *asset; // Objeto que gestiona todos los ficheros de recursos + Input *input; // Objeto para leer las entradas de teclado o mando + Lang *lang; // Objeto para gestionar los textos en diferentes idiomas + Instructions *instructions; // Objeto para la sección de las instrucciones + Game *demoGame; // Objeto para lanzar la demo del juego + SDL_Event *eventHandler; // Manejador de eventos LTexture *dustTexture; // Textura con los graficos del polvo LTexture *coffeeTexture; // Textura con los graficos de la palabra coffee LTexture *crisisTexture; // Textura con los graficos de la plabra crisis LTexture *gradientTexture; // Textura con los graficos para el degradado del fondo del titulo - SDL_Rect mBackgroundWindow; // Ventana visible para la textura de fondo del titulo - SDL_Texture *mBackground; // Textura dibujar el fondo del titulo + SDL_Rect backgroundWindow; // Ventana visible para la textura de fondo del titulo + SDL_Texture *background; // Textura dibujar el fondo del titulo - AnimatedSprite *mDustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo - AnimatedSprite *mDustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo + AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo + AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo - SmartSprite *mCoffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo - SmartSprite *mCrisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo + SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo + SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo - Sprite *mGradient; // Sprite para dibujar el degradado del titulo + Sprite *gradient; // Sprite para dibujar el degradado del titulo - Text *mText; // Objeto de texto para poder escribir textos en pantalla - Text *mText2; // Objeto de texto para poder escribir textos en pantalla - Fade *mFade; // Objeto para realizar fundidos en pantalla + Text *text1; // Objeto de texto para poder escribir textos en pantalla + Text *text2; // Objeto de texto para poder escribir textos en pantalla + Fade *fade; // Objeto para realizar fundidos en pantalla // Variable - JA_Music mMusic; // Musica para el titulo - JA_Sound mSound; // Sonido con el impacto del título - int mBackgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo - int mCounter; // Temporizador para la pantalla de titulo - Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa - Uint8 mBackgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo - float mSin[360]; // Vector con los valores del seno precalculados - bool mMenuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente - bool mDemo; // Indica si el modo demo estará activo - section_t mSection; // Indicador para el bucle del titulo - section_t mNextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo - Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa - Uint8 mPostFade; // Opción a realizar cuando termina el fundido - menu_t mMenu; // Variable con todos los objetos menus y sus variables - struct options_t *mOptions; // Variable con todas las variables de las opciones del programa - options_t mOptionsPrevious; // Variable de respaldo para las opciones - std::vector mAvailableInputDevices; // Vector con todos los metodos de control disponibles - int mDeviceIndex[2]; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles + JA_Music titleMusic; // Musica para el titulo + JA_Sound crashSound; // Sonido con el impacto del título + int backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo + int counter; // Temporizador para la pantalla de titulo + Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa + Uint8 backgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo + float sin[360]; // Vector con los valores del seno precalculados + bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente + bool demo; // Indica si el modo demo estará activo + section_t section; // Indicador para el bucle del titulo + section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo + Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa + Uint8 postFade; // Opción a realizar cuando termina el fundido + menu_t menu; // Variable con todos los objetos menus y sus variables + struct options_t *options; // Variable con todas las variables de las opciones del programa + options_t optionsPrevious; // Variable de respaldo para las opciones + std::vector availableInputDevices; // Vector con todos los metodos de control disponibles + std::vector deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles // Actualiza las variables del objeto void update(); @@ -100,7 +100,7 @@ private: // Comprueba los eventos void checkEventHandler(); - //Actualiza el tileado de fondo + // Actualiza el tileado de fondo void updateBG(); // Cambia el valor de la variable de modo de pantalla completa diff --git a/source/utils.h b/source/utils.h index 4d65080..7a93f73 100644 --- a/source/utils.h +++ b/source/utils.h @@ -3,6 +3,7 @@ #include #include "ltexture.h" #include +#include #ifndef UTILS_H #define UTILS_H @@ -85,19 +86,19 @@ struct input_t // Estructura con todas las opciones de configuración del programa struct options_t { - Uint8 difficulty; // Dificultad del juego - input_t input[2]; // Modo de control (teclado o mando) - Uint8 language; // Idioma usado en el juego - Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa - Uint8 windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana - Uint32 filter; // Filtro usado para el escalado de la imagen - bool vSync; // Indica si se quiere usar vsync o no - int screenWidth; // Ancho de la pantalla/ventana - int screenHeight; // Alto de la pantalla/ventana - bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa - bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa - bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana - float borderSize; // Porcentaje de borde que se añade a lo ventana + Uint8 difficulty; // Dificultad del juego + std::vector input; // Modo de control (teclado o mando) + Uint8 language; // Idioma usado en el juego + Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa + Uint8 windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana + Uint32 filter; // Filtro usado para el escalado de la imagen + bool vSync; // Indica si se quiere usar vsync o no + int screenWidth; // Ancho de la pantalla/ventana + int screenHeight; // Alto de la pantalla/ventana + bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa + bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa + bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana + float borderSize; // Porcentaje de borde que se añade a lo ventana }; // Calcula el cuadrado de la distancia entre dos puntos