Añadidos mas ifdef DEBUG para quitar código sobrante de la versión final
This commit is contained in:
@@ -14,67 +14,6 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
rooms.push_back("31.room");
|
||||
rooms.push_back("44.room");
|
||||
|
||||
// rooms.push_back("01.room");
|
||||
// rooms.push_back("02.room");
|
||||
// rooms.push_back("03.room");
|
||||
// rooms.push_back("04.room");
|
||||
// rooms.push_back("05.room");
|
||||
// rooms.push_back("06.room");
|
||||
// rooms.push_back("07.room");
|
||||
// rooms.push_back("08.room");
|
||||
// rooms.push_back("09.room");
|
||||
// rooms.push_back("10.room");
|
||||
// rooms.push_back("11.room");
|
||||
// rooms.push_back("12.room");
|
||||
// rooms.push_back("13.room");
|
||||
// rooms.push_back("14.room");
|
||||
// rooms.push_back("15.room");
|
||||
// rooms.push_back("16.room");
|
||||
// rooms.push_back("17.room");
|
||||
// rooms.push_back("18.room");
|
||||
// rooms.push_back("19.room");
|
||||
// rooms.push_back("20.room");
|
||||
// rooms.push_back("21.room");
|
||||
// rooms.push_back("22.room");
|
||||
// rooms.push_back("23.room");
|
||||
// rooms.push_back("24.room");
|
||||
// rooms.push_back("25.room");
|
||||
// rooms.push_back("26.room");
|
||||
// rooms.push_back("27.room");
|
||||
// rooms.push_back("28.room");
|
||||
// rooms.push_back("29.room");
|
||||
// rooms.push_back("30.room");
|
||||
// rooms.push_back("31.room");
|
||||
// rooms.push_back("32.room");
|
||||
// rooms.push_back("33.room");
|
||||
// rooms.push_back("34.room");
|
||||
// rooms.push_back("35.room");
|
||||
// rooms.push_back("36.room");
|
||||
// rooms.push_back("37.room");
|
||||
// rooms.push_back("38.room");
|
||||
// rooms.push_back("39.room");
|
||||
// rooms.push_back("40.room");
|
||||
// rooms.push_back("41.room");
|
||||
// rooms.push_back("42.room");
|
||||
// rooms.push_back("43.room");
|
||||
// rooms.push_back("44.room");
|
||||
// rooms.push_back("45.room");
|
||||
// rooms.push_back("46.room");
|
||||
// rooms.push_back("47.room");
|
||||
// rooms.push_back("48.room");
|
||||
// rooms.push_back("49.room");
|
||||
// rooms.push_back("50.room");
|
||||
// rooms.push_back("51.room");
|
||||
// rooms.push_back("52.room");
|
||||
// rooms.push_back("53.room");
|
||||
// rooms.push_back("54.room");
|
||||
// rooms.push_back("55.room");
|
||||
// rooms.push_back("56.room");
|
||||
// rooms.push_back("57.room");
|
||||
// rooms.push_back("58.room");
|
||||
// rooms.push_back("59.room");
|
||||
// rooms.push_back("60.room");
|
||||
|
||||
roomIndex = 0;
|
||||
currentRoom = rooms.at(roomIndex);
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
this->options = options;
|
||||
|
||||
#ifdef DEBUG
|
||||
currentRoom = "14.room";
|
||||
const int x1 = 1;
|
||||
currentRoom = "48.room";
|
||||
const int x1 = 18;
|
||||
const int y1 = 13;
|
||||
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
#endif
|
||||
@@ -207,8 +207,11 @@ void Game::update()
|
||||
// Comprueba los eventos de la cola
|
||||
checkEventHandler();
|
||||
|
||||
// Actualiza los objetos
|
||||
#ifdef DEBUG
|
||||
debug->clear();
|
||||
#endif
|
||||
|
||||
// Actualiza los objetos
|
||||
room->update();
|
||||
player->update();
|
||||
checkPlayerOnBorder();
|
||||
@@ -220,9 +223,11 @@ void Game::update()
|
||||
scoreboard->update();
|
||||
input->update();
|
||||
|
||||
updateDebugInfo();
|
||||
updateBlackScreen();
|
||||
screen->updateFX();
|
||||
|
||||
#ifdef DEBUG
|
||||
updateDebugInfo();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,14 +246,16 @@ void Game::render()
|
||||
scoreboard->render();
|
||||
renderBlackScreen();
|
||||
|
||||
#ifdef DEBUG
|
||||
// Debug info
|
||||
renderDebugInfo();
|
||||
// screen->renderFX();
|
||||
#endif
|
||||
|
||||
// Actualiza la pantalla
|
||||
screen->blit();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo()
|
||||
{
|
||||
@@ -285,6 +292,7 @@ void Game::renderDebugInfo()
|
||||
debug->setPos({1, 18 * 8});
|
||||
debug->render();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Escribe el nombre de la pantalla
|
||||
void Game::renderRoomName()
|
||||
|
||||
@@ -63,11 +63,13 @@ private:
|
||||
// Comprueba los eventos de la cola
|
||||
void checkEventHandler();
|
||||
|
||||
#ifdef DEBUG
|
||||
// Pone la información de debug en pantalla
|
||||
void updateDebugInfo();
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void renderDebugInfo();
|
||||
#endif
|
||||
|
||||
// Escribe el nombre de la pantalla
|
||||
void renderRoomName();
|
||||
|
||||
@@ -93,9 +93,13 @@ Player::Player(player_t player)
|
||||
fallSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str()));
|
||||
fallSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str()));
|
||||
|
||||
r = {0, 0, 0, 0};
|
||||
jumpCounter = 0;
|
||||
fallCounter = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
rx = {0, 0, 0, 0};
|
||||
ry = {0, 0, 0, 0};
|
||||
#endif
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -114,6 +118,8 @@ void Player::render()
|
||||
{
|
||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||
sprite->render();
|
||||
|
||||
#ifdef DEBUG
|
||||
if (debug->getEnabled())
|
||||
{
|
||||
// Pinta los underfeet
|
||||
@@ -125,11 +131,21 @@ void Player::render()
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 192);
|
||||
SDL_Rect rect = getRect();
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
|
||||
SDL_RenderDrawRect(renderer, &rect);
|
||||
|
||||
// Pinta el rectangulo de movimiento
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &r);
|
||||
if (vx != 0.0f)
|
||||
{
|
||||
SDL_RenderFillRect(renderer, &rx);
|
||||
}
|
||||
if (vy != 0.0f)
|
||||
{
|
||||
SDL_RenderFillRect(renderer, &ry);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
@@ -231,21 +247,25 @@ void Player::checkBorders()
|
||||
border = BORDER_LEFT;
|
||||
onBorder = true;
|
||||
}
|
||||
|
||||
else if (x > PLAY_AREA_RIGHT - w)
|
||||
{
|
||||
border = BORDER_RIGHT;
|
||||
onBorder = true;
|
||||
}
|
||||
|
||||
else if (y < PLAY_AREA_TOP)
|
||||
{
|
||||
border = BORDER_TOP;
|
||||
onBorder = true;
|
||||
}
|
||||
|
||||
else if (y > PLAY_AREA_BOTTOM - h)
|
||||
{
|
||||
border = BORDER_BOTTOM;
|
||||
onBorder = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
onBorder = false;
|
||||
@@ -273,14 +293,14 @@ void Player::checkState()
|
||||
vy = 0.0f;
|
||||
jumpCounter = 0;
|
||||
fallCounter = 0;
|
||||
if (!isOnFloor() && !isOnAutoSurface())
|
||||
/*if (!isOnFloor() && !isOnAutoSurface())
|
||||
{
|
||||
setState(s_falling);
|
||||
vx = 0.0f;
|
||||
vy = maxVY;
|
||||
fallCounter++;
|
||||
playFallSound();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
else if (state == s_jumping)
|
||||
@@ -363,7 +383,9 @@ void Player::move()
|
||||
proj.h = h;
|
||||
proj.w = ceil(abs(vx)); // Para evitar que tenga un ancho de 0 pixels
|
||||
|
||||
r = proj;
|
||||
#ifdef DEBUG
|
||||
rx = proj;
|
||||
#endif
|
||||
|
||||
// Comprueba la colisión con las superficies
|
||||
const int pos = room->checkRightSurfaces(&proj);
|
||||
@@ -406,7 +428,9 @@ void Player::move()
|
||||
proj.h = h;
|
||||
proj.w = ceil(vx); // Para evitar que tenga un ancho de 0 pixels
|
||||
|
||||
r = proj;
|
||||
#ifdef DEBUG
|
||||
rx = proj;
|
||||
#endif
|
||||
|
||||
// Comprueba la colisión
|
||||
const int pos = room->checkLeftSurfaces(&proj);
|
||||
@@ -465,7 +489,9 @@ void Player::move()
|
||||
proj.h = ceil(abs(vy)); // Para evitar que tenga una altura de 0 pixels
|
||||
proj.w = w;
|
||||
|
||||
r = proj;
|
||||
#ifdef DEBUG
|
||||
ry = proj;
|
||||
#endif
|
||||
|
||||
// Comprueba la colisión
|
||||
const int pos = room->checkBottomSurfaces(&proj);
|
||||
@@ -492,7 +518,9 @@ void Player::move()
|
||||
proj.h = ceil(vy); // Para evitar que tenga una altura de 0 pixels
|
||||
proj.w = w;
|
||||
|
||||
r = proj;
|
||||
#ifdef DEBUG
|
||||
ry = proj;
|
||||
#endif
|
||||
|
||||
// Comprueba la colisión con las superficies normales y las automáticas
|
||||
const int pos = std::max(room->checkTopSurfaces(&proj), room->checkAutoSurfaces(&proj));
|
||||
@@ -535,7 +563,10 @@ void Player::move()
|
||||
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));
|
||||
#ifdef DEBUG
|
||||
debug->add("RECT_X: " + std::to_string(rx.x) + "," + std::to_string(rx.y) + "," + std::to_string(rx.w) + "," + std::to_string(rx.h));
|
||||
debug->add("RECT_Y: " + std::to_string(ry.x) + "," + std::to_string(ry.y) + "," + std::to_string(ry.w) + "," + std::to_string(ry.h));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Establece la animación del jugador
|
||||
@@ -571,7 +602,10 @@ void Player::playJumpSound()
|
||||
{
|
||||
JA_PlaySound(jumpSound[jumpCounter / 4]);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
debug->add("JUMP: " + std::to_string(jumpCounter / 4));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Calcula y reproduce el sonido de caer
|
||||
@@ -581,7 +615,10 @@ void Player::playFallSound()
|
||||
{
|
||||
JA_PlaySound(fallSound[std::min((fallCounter / 4), (int)fallSound.size() - 1)]);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
debug->add("FALL: " + std::to_string(fallCounter / 4));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||
@@ -604,6 +641,7 @@ bool Player::isOnFloor()
|
||||
onSlopeL = room->checkLeftSlopes(&underFeet[0]);
|
||||
onSlopeR = room->checkRightSlopes(&underFeet[1]);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (onFloor)
|
||||
{
|
||||
debug->add("ON_FLOOR");
|
||||
@@ -618,6 +656,7 @@ bool Player::isOnFloor()
|
||||
{
|
||||
debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
|
||||
}
|
||||
#endif
|
||||
|
||||
return onFloor || onSlopeL || onSlopeR;
|
||||
}
|
||||
@@ -635,10 +674,12 @@ bool Player::isOnAutoSurface()
|
||||
onAutoSurface |= room->checkAutoSurfaces(&f);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (onAutoSurface)
|
||||
{
|
||||
debug->add("ON_AUTO_SURFACE");
|
||||
}
|
||||
#endif
|
||||
|
||||
return onAutoSurface;
|
||||
}
|
||||
@@ -659,10 +700,12 @@ bool Player::isOnDownSlope()
|
||||
onSlope |= room->checkLeftSlopes(&underFeet[0]);
|
||||
onSlope |= room->checkRightSlopes(&underFeet[1]);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (onSlope)
|
||||
{
|
||||
debug->add("ON_DOWN_SLOPE");
|
||||
}
|
||||
#endif
|
||||
|
||||
return onSlope;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,11 @@ public:
|
||||
int fallCounter; // Cuenta el tiempo de caida
|
||||
bool alive; // Indica si el jugador esta vivo o no
|
||||
int maxFallHeight; // Altura maxima permitida de caída.
|
||||
SDL_Rect r;
|
||||
|
||||
#ifdef DEBUG
|
||||
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
|
||||
SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug
|
||||
#endif
|
||||
|
||||
// Comprueba las entradas y modifica variables
|
||||
void checkInput();
|
||||
|
||||
@@ -554,6 +554,7 @@ void Room::fillMapTexture()
|
||||
clip.y = (tileMap.at(index) / tileSetWidth) * tileSize;
|
||||
texture->render(renderer, x * tileSize, y * tileSize, &clip);
|
||||
|
||||
#ifdef DEBUG
|
||||
// ****
|
||||
if (debug->getEnabled())
|
||||
{
|
||||
@@ -566,9 +567,11 @@ void Room::fillMapTexture()
|
||||
}
|
||||
}
|
||||
// ****
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// ****
|
||||
if (debug->getEnabled())
|
||||
{
|
||||
@@ -649,6 +652,7 @@ void Room::fillMapTexture()
|
||||
}
|
||||
}
|
||||
// ****
|
||||
#endif
|
||||
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
@@ -660,10 +664,14 @@ void Room::renderMap()
|
||||
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
|
||||
|
||||
// Dibuja los tiles animados
|
||||
#ifdef DEBUG
|
||||
if (!debug->getEnabled())
|
||||
{
|
||||
renderAnimatedTiles();
|
||||
}
|
||||
#else
|
||||
renderAnimatedTiles();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Dibuja los enemigos en pantalla
|
||||
@@ -882,22 +890,30 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
||||
{
|
||||
// Calcula la base del tile
|
||||
int base = ((p.y / tileSize) * tileSize) + tileSize;
|
||||
#ifdef DEBUG
|
||||
debug->add("BASE = " + std::to_string(base));
|
||||
#endif
|
||||
|
||||
// Calcula cuanto se ha entrado en el tile horizontalmente
|
||||
const int pos = (p.x % tileSize); // Esto da un valor entre 0 y 7
|
||||
#ifdef DEBUG
|
||||
debug->add("POS = " + std::to_string(pos));
|
||||
#endif
|
||||
|
||||
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
||||
if (slope == t_slope_r)
|
||||
{
|
||||
base -= pos + 1;
|
||||
#ifdef DEBUG
|
||||
debug->add("BASE_R = " + std::to_string(base));
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
base -= (tileSize - pos);
|
||||
#ifdef DEBUG
|
||||
debug->add("BASE_L = " + std::to_string(base));
|
||||
#endif
|
||||
}
|
||||
|
||||
return base;
|
||||
|
||||
Reference in New Issue
Block a user