diff --git a/data/room/06.tmx b/data/room/06.tmx index 7daec5d..334cfe7 100644 --- a/data/room/06.tmx +++ b/data/room/06.tmx @@ -9,14 +9,14 @@ 26,0,0,0,0,0,86,0,0,0,0,0,0,0,0,0,0,183,0,0,0,0,0,0,0,0,0,0,0,0,0,26, 26,0,0,0,86,86,86,0,0,0,0,0,0,0,0,0,0,0,183,0,0,0,0,0,0,0,0,0,0,0,0,26, 26,0,0,0,86,0,86,0,0,0,0,0,0,0,0,167,66,66,66,66,187,0,0,0,0,164,65,65,0,0,0,26, -26,0,0,0,86,0,86,0,0,0,0,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26, -26,0,0,0,0,0,0,0,0,0,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26, -26,0,0,0,0,0,0,0,0,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,62,62,0,0,0,0,26, -26,0,0,0,0,0,0,0,0,161,212,212,212,212,212,212,212,0,212,212,0,0,0,0,0,62,62,0,0,0,0,26, -26,0,0,0,0,0,0,0,161,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26, -26,0,0,0,0,0,0,161,0,0,0,0,0,0,0,0,0,269,0,0,0,0,0,0,0,0,22,22,0,0,0,26, -26,0,0,0,0,0,161,0,0,0,0,0,0,0,0,0,0,269,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -26,0,0,0,0,161,0,0,0,0,0,0,0,0,0,0,81,289,81,0,0,0,0,0,0,0,0,0,0,0,0,0, +26,0,0,0,86,0,86,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26, +26,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26, +26,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,62,62,0,0,0,0,26, +26,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,62,62,0,0,0,0,26, +26,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26, +26,0,0,0,0,0,0,0,0,0,163,26,26,26,26,26,26,26,26,183,0,0,0,0,0,0,22,22,0,0,0,26, +26,0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,183,0,0,0,0,0,0,0,0,0,0,0, +26,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,183,0,0,0,0,0,0,0,0,0,0, 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26, 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26 diff --git a/data/room/11.room b/data/room/11.room index 6049df6..4d1f6cf 100644 --- a/data/room/11.room +++ b/data/room/11.room @@ -34,7 +34,7 @@ width=16 height=16 x=19 y=7 -vx=0.6 +vx=0 vy=0.3 x1=19 y1=3 diff --git a/data/room/11.tmx b/data/room/11.tmx index 02d80b5..99f501c 100644 --- a/data/room/11.tmx +++ b/data/room/11.tmx @@ -10,13 +10,13 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,113,113,113,183,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, -113,113,113,113,113,0,183,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, -113,113,113,113,113,0,0,183,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, -113,0,0,0,0,0,163,113,113,113,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, -113,0,0,0,0,163,0,113,113,113,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, -113,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -113,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,113,113,113,182,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, +113,113,113,113,113,0,182,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, +113,113,0,0,0,0,0,182,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, +113,0,0,0,0,0,162,113,113,113,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, +113,0,0,0,0,162,0,113,113,113,113,113,0,0,0,0,113,113,0,0,0,0,113,113,0,0,0,0,113,113,113,113, +113,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +113,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 113,113,113,113,101,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,103,113,113,113,113,113, 113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113 diff --git a/source/debug.cpp b/source/debug.cpp index 6abc71e..c0090a6 100644 --- a/source/debug.cpp +++ b/source/debug.cpp @@ -45,6 +45,13 @@ void Debug::render() x += w * text->getCharacterSize() + 2; } } + + y = 0; + for (auto l : log) + { + text->writeColored(x, y, l, {255, 255, 255}); + y += text->getCharacterSize() + 1; + } } // Establece la posición donde se colocará la información de debug @@ -66,6 +73,18 @@ void Debug::clear() slot.clear(); } +// Añade un texto para mostrar en el apartado log +void Debug::addToLog(std::string text) +{ + log.push_back(text); +} + +// Borra la información de debug del apartado log +void Debug::clearLog() +{ + log.clear(); +} + // Establece el valor de la variable void Debug::setEnabled(bool value) { diff --git a/source/debug.h b/source/debug.h index 1f3fbb9..c17e623 100644 --- a/source/debug.h +++ b/source/debug.h @@ -21,6 +21,7 @@ private: Asset *asset; // Objeto con los ficheros de recursos Text *text; // Objeto encargado de escribir texto en pantalla std::vector slot; // Vector con los textos a escribir + std::vector log; // Vector con los textos a escribir int x; // Posicion donde escribir el texto de debug int y; // Posición donde escribir el texto de debug bool enabled; // Indica si esta activo el modo debug @@ -47,6 +48,12 @@ public: // Borra la información de debug void clear(); + // Añade un texto para mostrar en el apartado log + void addToLog(std::string text); + + // Borra la información de debug del apartado log + void clearLog(); + // Establece el valor de la variable void setEnabled(bool value); diff --git a/source/director.cpp b/source/director.cpp index 4c2eb4c..4b7a485 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -17,7 +17,7 @@ Director::Director(std::string path) } else { - section.name = SECTION_PROG_CREDITS; + section.name = SECTION_PROG_GAME; section.subsection = 0; } diff --git a/source/game.cpp b/source/game.cpp index f301458..d88d8fe 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -15,9 +15,15 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D this->input = input; this->debug = debug; - // this->debug->setEnabled(true); + // **** + this->debug->setEnabled(true); + + currentRoom = "11.room"; + spawnPoint = {2 * 8, 5 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; + // currentRoom = "06.room"; - // spawnPoint = {240, 96, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; + // spawnPoint = {14 * 8, 9 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; + // **** // Crea los objetos scoreboard = new ScoreBoard(renderer, asset, &board); diff --git a/source/player.cpp b/source/player.cpp index 2b0c602..27791f0 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -126,7 +126,6 @@ void Player::render() // Pinta el rectangulo de movimiento SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); SDL_RenderFillRect(renderer, &r); - debug->add("RECT: " + std::to_string(r.x) + "," + std::to_string(r.y) + "," + std::to_string(r.w) + "," + std::to_string(r.h)); } } @@ -454,6 +453,8 @@ void Player::move() // Actualiza la posición del sprite sprite->setPosX(x); sprite->setPosY(y); + + debug->add("RECT: " + std::to_string(r.x) + "," + std::to_string(r.y) + "," + std::to_string(r.w) + "," + std::to_string(r.h)); } // Establece la animación del jugador @@ -506,6 +507,8 @@ void Player::playFallSound() bool Player::isOnFloor() { bool onFloor = false; + bool onSlopeL = false; + bool onSlopeR = false; updateFeet(); @@ -516,15 +519,25 @@ bool Player::isOnFloor() } // Comprueba las rampas - onFloor |= room->checkLeftSlopes(&underFeet[0]); - onFloor |= room->checkRightSlopes(&underFeet[1]); + onSlopeL = room->checkLeftSlopes(&underFeet[0]); + onSlopeR = room->checkRightSlopes(&underFeet[1]); if (onFloor) { - debug->add("ONFLOOR"); + debug->add("ON_FLOOR"); } - return onFloor; + if (onSlopeL) + { + debug->add("ON_SLOPE_L: " + std::to_string(underFeet[0].x) + "," + std::to_string(underFeet[0].y)); + } + + if (onSlopeR) + { + debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y)); + } + + return onFloor || onSlopeL || onSlopeR; } // Comprueba si el jugador está sobre una rampa hacia abajo @@ -545,7 +558,7 @@ bool Player::isOnDownSlope() if (onSlope) { - debug->add("ONSLOPE"); + debug->add("ON_DOWN_SLOPE"); } return onSlope; diff --git a/source/room.cpp b/source/room.cpp index bb93c4a..b064812 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -25,6 +25,8 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset texture = new LTexture(renderer, asset->get(tileset)); itemSound = JA_LoadSound(asset->get("item.wav").c_str()); + debug->clearLog(); + debug->addToLog(tileset); // Calcula las superficies setBottomSurfaces(); setTopSurfaces(); @@ -43,6 +45,7 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset // Establece el color del borde screen->setBorderColor(borderColor); + } // Destructor @@ -937,6 +940,7 @@ void Room::setLeftSlopes() line.x2 = ((lastOneFound % mapWidth) * tileSize) + tileSize - 1; line.y2 = ((lastOneFound / mapWidth) * tileSize) + tileSize - 1; leftSlopes.push_back(line); + debug->addToLog("LS: " + std::to_string(line.x1) + "," + std::to_string(line.y1) + "," + std::to_string(line.x2) + "," + std::to_string(line.y2)); } } @@ -978,6 +982,7 @@ void Room::setRightSlopes() line.x2 = (lastOneFound % mapWidth) * tileSize; line.y2 = ((lastOneFound / mapWidth) * tileSize) + tileSize - 1; rightSlopes.push_back(line); + debug->addToLog("RS: " + std::to_string(line.x1) + "," + std::to_string(line.y1) + "," + std::to_string(line.x2) + "," + std::to_string(line.y2)); } } diff --git a/source/utils.cpp b/source/utils.cpp index 1a6d53b..bc0117d 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -353,8 +353,30 @@ bool checkCollision(SDL_Point &p, d_line_t &l) return false; } + // Comprueba si está por encima de la linea + if (p.y > l.y1 && p.y > l.y2) + { + return false; + } + + // Comprueba si está por debajo de la linea + if (p.y < l.y1 && p.y < l.y2) + { + return false; + } + // En caso contrario, el punto está en la linea return true; + + + /*const int m = (l.y2 - l.y1) / (l.x2 - l.x1); + const int c = 0; + + // Comprueba si p cumple la ecuación de la linea + if (p.y == ((m * p.x) + c)) + return true; + + return false;*/ } // Devuelve un color_t a partir de un string