diff --git a/source/enemy.cpp b/source/enemy.cpp index 865b728..2fdc7df 100644 --- a/source/enemy.cpp +++ b/source/enemy.cpp @@ -48,7 +48,7 @@ void Enemy::render() void Enemy::update() { sprite->update(); - //sprite->animate(); + // sprite->animate(); checkPath(); collider = getRect(); } @@ -77,4 +77,10 @@ SDL_Rect Enemy::getRect() SDL_Rect &Enemy::getCollider() { return collider; +} + +// Recarga la textura +void Enemy::reLoadTexture() +{ + texture->reLoad(); } \ No newline at end of file diff --git a/source/enemy.h b/source/enemy.h index 9d53ac7..73d45b1 100644 --- a/source/enemy.h +++ b/source/enemy.h @@ -80,6 +80,9 @@ public: // Obtiene el rectangulo de colision del enemigo SDL_Rect &getCollider(); + + // Recarga la textura + void reLoadTexture(); }; #endif diff --git a/source/game.cpp b/source/game.cpp index dae9265..625892a 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -18,7 +18,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) // Crea los objetos scoreboard = new ScoreBoard(renderer, asset, &playerLives, &itemsPicked, &clock); itemTracker = new ItemTracker(); - room = new Room(asset->get(currentRoom), renderer, asset, itemTracker,&itemsPicked); + room = new Room(asset->get(currentRoom), renderer, asset, itemTracker, &itemsPicked); player = new Player(spawnPoint, asset->get("player01.png"), asset->get("player01.ani"), renderer, asset, input, room); eventHandler = new SDL_Event(); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); @@ -65,6 +65,62 @@ Game::~Game() debugText = nullptr; } +// Comprueba los eventos de la cola +void Game::checkEventHandler() +{ + // Comprueba los eventos que hay en la cola + while (SDL_PollEvent(eventHandler) != 0) + { + // Evento de salida de la aplicación + if (eventHandler->type == SDL_QUIT) + { + section.name = SECTION_PROG_QUIT; + break; + } + else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) + { + switch (eventHandler->key.keysym.scancode) + { + case SDL_SCANCODE_D: + debug = !debug; + break; + + case SDL_SCANCODE_M: + (JA_GetMusicState() == JA_MUSIC_PLAYING) ? JA_PauseMusic() : JA_ResumeMusic(); + break; + + case SDL_SCANCODE_F: + screen->switchVideoMode(); + reLoadTextures(); + break; + + case SDL_SCANCODE_F1: + screen->setWindowSize(1); + reLoadTextures(); + break; + + case SDL_SCANCODE_F2: + screen->setWindowSize(2); + reLoadTextures(); + break; + + case SDL_SCANCODE_F3: + screen->setWindowSize(3); + reLoadTextures(); + break; + + case SDL_SCANCODE_F4: + screen->setWindowSize(4); + reLoadTextures(); + break; + + default: + break; + } + } + } +} + // Bucle para el juego section_t Game::run() { @@ -94,58 +150,15 @@ void Game::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); - // Comprueba los eventos que hay en la cola - while (SDL_PollEvent(eventHandler) != 0) - { - // Evento de salida de la aplicación - if (eventHandler->type == SDL_QUIT) - { - section.name = SECTION_PROG_QUIT; - break; - } - else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) - { - switch (eventHandler->key.keysym.scancode) - { - case SDL_SCANCODE_D: - debug = !debug; - break; - - case SDL_SCANCODE_M: - (JA_GetMusicState() == JA_MUSIC_PLAYING) ? JA_PauseMusic() : JA_ResumeMusic(); - break; - - case SDL_SCANCODE_F: - screen->switchVideoMode(); - break; - - case SDL_SCANCODE_F1: - screen->setWindowSize(1); - break; - - case SDL_SCANCODE_F2: - screen->setWindowSize(2); - break; - - case SDL_SCANCODE_F3: - screen->setWindowSize(3); - break; - - case SDL_SCANCODE_F4: - screen->setWindowSize(4); - break; - - default: - break; - } - } - } + // Comprueba los eventos de la cola + checkEventHandler(); + // Actualiza los objetos room->update(); { player->update(); - checkPlayerAndWalls(); - } // Debe ir detras del player update, por si se ha metido en algun muro + checkPlayerAndWalls(); // Debe ir detras del player update, por si se ha metido en algun muro + } checkPlayerOnBorder(); checkPlayerOnFloor(); checkPlayerAndItems(); @@ -393,4 +406,13 @@ void Game::killPlayer() // Crea la nueva habitación y el nuevo jugador room = new Room(asset->get(currentRoom), renderer, asset, itemTracker, &itemsPicked); player = new Player(spawnPoint, asset->get("player01.png"), asset->get("player01.ani"), renderer, asset, input, room); +} + +// Recarga todas las texturas +void Game::reLoadTextures() +{ + player->reLoadTexture(); + room->reLoadTexture(); + scoreboard->reLoadTexture(); + text->reLoadTexture(); } \ No newline at end of file diff --git a/source/game.h b/source/game.h index bfa0f76..e6b3036 100644 --- a/source/game.h +++ b/source/game.h @@ -50,6 +50,9 @@ private: // Pinta los objetos en pantalla void render(); + // Comprueba los eventos de la cola + void checkEventHandler(); + // Pone la información de debug en pantalla void renderDebugInfo(); @@ -77,6 +80,9 @@ private: // Mata al jugador void killPlayer(); + // Recarga todas las texturas + void reLoadTextures(); + public: // Constructor Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input); diff --git a/source/item.cpp b/source/item.cpp index 01a31f0..e97f6c1 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -78,4 +78,10 @@ SDL_Point Item::getPos() { const SDL_Point p = {sprite->getPosX(), sprite->getPosY()}; return p; +} + +// Recarga la textura +void Item::reLoadTexture() +{ + texture->reLoad(); } \ No newline at end of file diff --git a/source/item.h b/source/item.h index eb87ce1..6bff79f 100644 --- a/source/item.h +++ b/source/item.h @@ -59,6 +59,9 @@ public: // Obtiene su ubicación SDL_Point getPos(); + + // Recarga la textura + void reLoadTexture(); }; #endif diff --git a/source/menu.cpp b/source/menu.cpp index ddd7ef8..aa64abe 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -887,4 +887,10 @@ int Menu::getSelectorHeight(int value) { return item[value].rect.h; } +} + +// Recarga la textura +void Menu::reLoadTexture() +{ + text->reLoadTexture(); } \ No newline at end of file diff --git a/source/menu.h b/source/menu.h index 09a001c..bcbf130 100644 --- a/source/menu.h +++ b/source/menu.h @@ -143,7 +143,7 @@ private: public: // Constructor - Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file=""); + Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file = ""); // Destructor ~Menu(); @@ -208,6 +208,9 @@ public: // Establece el estado de enlace de un item void setLinkedDown(int index, bool value); + // Recarga la textura + void reLoadTexture(); + // hacer procedimientos para establecer el titulo, la x, la y, la tipografia y el tipo de fondo }; diff --git a/source/player.cpp b/source/player.cpp index 54dc473..aafda59 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -289,5 +289,5 @@ player_t Player::getSpawnParams() // Recarga la textura void Player::reLoadTexture() { - //texture->loadFromFile(asset->get(tileset), renderer); + texture->reLoad(); } \ No newline at end of file diff --git a/source/player.h b/source/player.h index d17468d..93fc491 100644 --- a/source/player.h +++ b/source/player.h @@ -115,14 +115,14 @@ public: // Obtiene el rectangulo de colision del jugador SDL_Rect &getCollider(); - // Recarga la textura - void reLoadTexture(); - // Deshace el ultimo movimiento void undoLastMove(); // Obtiene algunos parametros del jugador player_t getSpawnParams(); + + // Recarga la textura + void reLoadTexture(); }; #endif diff --git a/source/room.cpp b/source/room.cpp index 5d2432c..7a830fb 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -14,7 +14,7 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTrac // Crea los objetos load(file_path); - texture = new LTexture(renderer,asset->get(tileset)); + texture = new LTexture(renderer, asset->get(tileset)); itemSound = JA_LoadSound(asset->get("item.wav").c_str()); // Crea la textura para el mapa de tiles de la habitación @@ -207,37 +207,37 @@ bool Room::setVars(std::string var, std::string value) { name = value; } - + else if (var == "bgColor") { bgColor = stringToColor(value); } - + else if (var == "tileset") { tileset = value; } - + else if (var == "roomUp") { roomUp = value; } - + else if (var == "roomDown") { roomDown = value; } - + else if (var == "roomLeft") { roomLeft = value; } - + else if (var == "roomRight") { roomRight = value; } - + else if (var == "tilemap") { // Se introducen los valores separados por comas en un vector @@ -248,11 +248,11 @@ bool Room::setVars(std::string var, std::string value) tilemap.push_back(std::stoi(tmp)); } } - + else if (var == "") { } - + else { success = false; @@ -536,13 +536,13 @@ bool Room::enemyCollision(SDL_Rect &rect) bool Room::itemCollision(SDL_Rect &rect) { bool collision = false; - for (int i =0;igetCollider())) { itemTracker->addItem(name, items[i]->getPos()); delete items[i]; - items.erase(items.begin()+i); + items.erase(items.begin() + i); JA_PlaySound(itemSound); *itemsPicked = *itemsPicked + 1; collision = true; @@ -550,4 +550,20 @@ bool Room::itemCollision(SDL_Rect &rect) } return collision; +} + +// Recarga la textura +void Room::reLoadTexture() +{ + texture->reLoad(); + fillMapTexture(); + for (auto enemy : enemies) + { + enemy->reLoadTexture(); + } + + for (auto item : items) + { + item->reLoadTexture(); + } } \ No newline at end of file diff --git a/source/room.h b/source/room.h index c4dceb1..d874226 100644 --- a/source/room.h +++ b/source/room.h @@ -53,7 +53,7 @@ private: SDL_Renderer *renderer; // El renderizador de la ventana SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación JA_Sound itemSound; // Sonido producido al coger un objeto - int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego + int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego // Carga las variables desde un fichero bool load(std::string file_path); @@ -106,6 +106,9 @@ public: // Indica si hay colision con un objeto a partir de un rectangulo bool itemCollision(SDL_Rect &rect); + + // Recarga la textura + void reLoadTexture(); }; #endif diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index e8f0176..f19e2d3 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -13,7 +13,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it this->clock = clock; // Reserva memoria para los objetos - texture = new LTexture(renderer,asset->get("player01.png")); + texture = new LTexture(renderer, asset->get("player01.png")); sprite = new AnimatedSprite(texture, renderer, asset->get("player01.ani")); sprite->setCurrentAnimation("walk_menu"); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); @@ -131,4 +131,11 @@ ScoreBoard::clock_t ScoreBoard::getTime() time.seconds = timeElapsed / 1000; time.separator = (timeElapsed % 1000 <= 500); return time; +} + +// Recarga la textura +void ScoreBoard::reLoadTexture() +{ + texture->reLoad(); + text->reLoadTexture(); } \ No newline at end of file diff --git a/source/scoreboard.h b/source/scoreboard.h index 83b3952..9c121c4 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -50,6 +50,9 @@ public: // Actualiza las variables del objeto void update(); + + // Recarga la textura + void reLoadTexture(); }; #endif diff --git a/source/text.cpp b/source/text.cpp index df62e43..e3b8598 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -49,10 +49,6 @@ void Text::init() offset[i].x = ((i - 32) % 15) * boxWidth; offset[i].y = ((i - 32) / 15) * boxHeight; } - - // printf("Cargando %s\n", file.c_str()); - // const std::string texto = "w = "+ std::to_string(boxWidth) + ", h = " + std::to_string(boxHeight); - // printf("%s\n",texto.c_str()); } // Escribe texto en pantalla @@ -179,4 +175,10 @@ void Text::initOffsetFromFile() int Text::getCharacterWidth() { return boxWidth; +} + +// Recarga la textura +void Text::reLoadTexture() +{ + texture->reLoad(); } \ No newline at end of file diff --git a/source/text.h b/source/text.h index 9e38dda..818d8d0 100644 --- a/source/text.h +++ b/source/text.h @@ -25,9 +25,9 @@ private: }; Offset offset[128]; // Vector con las posiciones y ancho de cada letra - int boxWidth; // Anchura de la caja de cada caracter en el png - int boxHeight; // Altura de la caja de cada caracter en el png - std::string file; // Fichero con los descriptores de la fuente + int boxWidth; // Anchura de la caja de cada caracter en el png + int boxHeight; // Altura de la caja de cada caracter en el png + std::string file; // Fichero con los descriptores de la fuente LTexture *texture; // Textura con los bitmaps del texto // Inicializador @@ -63,6 +63,9 @@ public: // Devuelve el valor de la variable int getCharacterWidth(); + + // Recarga la textura + void reLoadTexture(); }; #endif