mes canvis de merda
This commit is contained in:
@@ -66,7 +66,7 @@ Game::Game(Mode mode)
|
||||
// Crea objetos e inicializa variables
|
||||
ItemTracker::init();
|
||||
demoInit();
|
||||
room_ = std::make_shared<Room>(current_room_, scoreboard_data_);
|
||||
room_ = getOrCreateRoom(current_room_);
|
||||
initPlayer(spawn_data_, room_);
|
||||
game_backbuffer_surface_ = std::make_shared<Surface>(Options::game.width, Options::game.height);
|
||||
changeRoom(current_room_);
|
||||
@@ -314,6 +314,7 @@ void Game::updatePlaying(float delta_time) {
|
||||
if (transitioning_) {
|
||||
transition_old_room_->update(delta_time);
|
||||
}
|
||||
updateAdjacentRooms(delta_time);
|
||||
switch (mode_) {
|
||||
case Mode::GAME:
|
||||
#ifdef _DEBUG
|
||||
@@ -420,8 +421,10 @@ void Game::transitionToState(State new_state) {
|
||||
|
||||
// Lógica de ENTRADA según el nuevo estado
|
||||
if (new_state == State::BLACK_SCREEN) {
|
||||
// Limpiar caché de habitaciones (enemigos vuelven a sus posiciones iniciales)
|
||||
room_cache_.clear();
|
||||
// Respawn room y player
|
||||
room_ = std::make_shared<Room>(current_room_, scoreboard_data_);
|
||||
room_ = getOrCreateRoom(current_room_);
|
||||
initPlayer(spawn_data_, room_);
|
||||
// Pausar ambos
|
||||
room_->setPaused(true);
|
||||
@@ -763,8 +766,8 @@ auto Game::changeRoom(const std::string& room_path) -> bool {
|
||||
|
||||
// Verifica que exista el fichero que se va a cargar
|
||||
if (!Resource::List::get()->get(room_path).empty()) { // NOLINT(readability-static-accessed-through-instance)
|
||||
// Crea un objeto habitación nuevo a partir del fichero
|
||||
room_ = std::make_shared<Room>(room_path, scoreboard_data_);
|
||||
// Obtiene la habitación del caché o la crea
|
||||
room_ = getOrCreateRoom(room_path);
|
||||
|
||||
// Pone el color del marcador en función del color del borde de la habitación
|
||||
if (room_tracker_->addRoom(room_path)) {
|
||||
@@ -788,6 +791,32 @@ auto Game::changeRoom(const std::string& room_path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Obtiene una habitación del caché o la crea si no existe
|
||||
auto Game::getOrCreateRoom(const std::string& room_path) -> std::shared_ptr<Room> {
|
||||
auto it = room_cache_.find(room_path);
|
||||
if (it != room_cache_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
auto room = std::make_shared<Room>(room_path, scoreboard_data_);
|
||||
room_cache_[room_path] = room;
|
||||
return room;
|
||||
}
|
||||
|
||||
// Actualiza los enemigos de las habitaciones adyacentes a la actual
|
||||
void Game::updateAdjacentRooms(float delta_time) {
|
||||
for (auto border : {Room::Border::TOP, Room::Border::RIGHT, Room::Border::BOTTOM, Room::Border::LEFT}) {
|
||||
const auto ROOM_NAME = room_->getRoom(border);
|
||||
if (ROOM_NAME == "0") {
|
||||
continue;
|
||||
}
|
||||
auto adjacent = getOrCreateRoom(ROOM_NAME);
|
||||
// Evitar actualizar la habitación actual o la que ya se actualiza en la transición
|
||||
if (adjacent != room_ && adjacent != transition_old_room_) {
|
||||
adjacent->update(delta_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si el jugador esta en el borde de la pantalla
|
||||
void Game::checkPlayerIsOnBorder() {
|
||||
// No permitir transiciones encadenadas
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <initializer_list> // Para initializer_list
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include <initializer_list> // Para initializer_list
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <unordered_map> // Para unordered_map
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/entities/player.hpp" // Para PlayerSpawn
|
||||
#include "game/gameplay/room.hpp" // Para Room, Room::Border
|
||||
@@ -68,6 +69,8 @@ class Game {
|
||||
void renderFadeToEnding(); // Renderiza el juego en estado FADE_TO_ENDING (via backbuffer)
|
||||
static void renderPostFadeEnding(); // Renderiza el juego en estado POST_FADE_ENDING (pantalla negra)
|
||||
auto changeRoom(const std::string& room_path) -> bool; // Cambia de habitación
|
||||
auto getOrCreateRoom(const std::string& room_path) -> std::shared_ptr<Room>; // Obtiene una habitación del caché o la crea
|
||||
void updateAdjacentRooms(float delta_time); // Actualiza enemigos de las habitaciones adyacentes
|
||||
void handleInput(); // Comprueba el teclado
|
||||
void checkPlayerIsOnBorder(); // Comprueba si el jugador esta en el borde de la pantalla y actua
|
||||
auto checkPlayerAndEnemies() -> bool; // Comprueba las colisiones del jugador con los enemigos
|
||||
@@ -105,6 +108,9 @@ class Game {
|
||||
float state_time_{0.0F}; // Tiempo acumulado en el estado actual
|
||||
float fade_accumulator_{0.0F}; // Acumulador de tiempo para el fade
|
||||
|
||||
// Caché de habitaciones vivas (enemigos mantienen su posición)
|
||||
std::unordered_map<std::string, std::shared_ptr<Room>> room_cache_;
|
||||
|
||||
// Transición animada entre pantallas
|
||||
bool transitioning_{false}; // Indica si hay una transición en curso
|
||||
float transition_timer_{0.0F}; // Tiempo transcurrido en la transición
|
||||
|
||||
Reference in New Issue
Block a user