#include "game.h" // Constructor Game::Game(SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input) { // Copia los punteros mRenderer = renderer; mFileList = filelist; mLang = lang; mInput = input; mScreen = new Screen(renderer); mEventHandler = new SDL_Event(); mTextureText = new LTexture(); mText = new Text(mFileList[5], mTextureText, renderer); mFade = new Fade(renderer); } Game::~Game() { mRenderer = nullptr; mFileList = nullptr; mLang = nullptr; mInput = nullptr; delete mEventHandler; mEventHandler = nullptr; mTextureText->unload(); delete mTextureText; mTextureText = nullptr; delete mScreen; mScreen = nullptr; delete mText; mText = nullptr; delete mFade; mFade = nullptr; } // Inicializa las variables necesarias para la sección 'Game' void Game::init() { // Carga los recursos loadMedia(); mTicks = 0; mTicksSpeed = 15; mSection.name = PROG_SECTION_GAME; mSection.subsection = GAME_SECTION_PLAY_1P; } // Carga los recursos necesarios para la sección 'Game' bool Game::loadMedia() { bool success = true; // Texturas success &= loadTextureFromFile(mTextureText, mFileList[4], mRenderer); return success; } // Bucle para el juego section_t Game::run() { init(); while (mSection.name == PROG_SECTION_GAME) { // Sección juego jugando if ((mSection.subsection == GAME_SECTION_PLAY_1P) || (mSection.subsection == GAME_SECTION_PLAY_2P)) { // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego if (SDL_GetTicks() - mTicks > mTicksSpeed) { // Actualiza el contador de ticks mTicks = SDL_GetTicks(); // Comprueba los eventos que hay en la cola while (SDL_PollEvent(mEventHandler) != 0) { // Evento de salida de la aplicación if (mEventHandler->type == SDL_QUIT) { mSection.name = PROG_SECTION_QUIT; break; } } } // Limpia la pantalla mScreen->clean(); mText->writeCentered(SCREEN_CENTER_X, SCREEN_CENTER_Y, "Pepe el Cazavampiros", 0); // Actualiza la pantalla mScreen->blit(); } } return mSection; }