Arreglos en la estructura i format del codi

This commit is contained in:
2025-03-01 22:36:22 +01:00
parent 360ebfd2e6
commit aca2be98af
27 changed files with 371 additions and 560 deletions

View File

@@ -17,11 +17,7 @@
// Constructor
Player::Player(const PlayerData &player)
: renderer_(Screen::get()->getRenderer()),
input_(Input::get()),
asset_(Asset::get()),
debug_(Debug::get()),
room_(player.room)
: room_(player.room)
{
// Inicializa algunas variables
initSprite(player.texture_path, player.animations_path);
@@ -82,13 +78,13 @@ void Player::checkInput()
if (!auto_movement_)
{
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
if (input_->checkInput(InputAction::LEFT))
if (Input::get()->checkInput(InputAction::LEFT))
{
vx_ = -0.6f;
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
}
else if (input_->checkInput(InputAction::RIGHT))
else if (Input::get()->checkInput(InputAction::RIGHT))
{
vx_ = 0.6f;
sprite_->setFlip(SDL_FLIP_NONE);
@@ -119,7 +115,7 @@ void Player::checkInput()
}
}
if (input_->checkInput(InputAction::JUMP))
if (Input::get()->checkInput(InputAction::JUMP))
{
// Solo puede saltar si ademas de estar (state == s_standing)
// Esta sobre el suelo, rampa o suelo que se mueve
@@ -469,8 +465,8 @@ void Player::move()
collider_box_ = getRect(); // Actualiza el rectangulo de colisión
#ifdef DEBUG
debug_->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
debug_->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h));
Debug::get()->add("RECT_X: " + std::to_string(debug_rect_x_.x) + "," + std::to_string(debug_rect_x_.y) + "," + std::to_string(debug_rect_x_.w) + "," + std::to_string(debug_rect_x_.h));
Debug::get()->add("RECT_Y: " + std::to_string(debug_rect_y_.x) + "," + std::to_string(debug_rect_y_.y) + "," + std::to_string(debug_rect_y_.w) + "," + std::to_string(debug_rect_y_.h));
#endif
}
@@ -510,7 +506,7 @@ void Player::playJumpSound()
}
#ifdef DEBUG
debug_->add("JUMP: " + std::to_string(jumping_counter_ / 4));
Debug::get()->add("JUMP: " + std::to_string(jumping_counter_ / 4));
#endif
}
@@ -523,7 +519,7 @@ void Player::playFallSound()
}
#ifdef DEBUG
debug_->add("FALL: " + std::to_string(falling_counter_ / 4));
Debug::get()->add("FALL: " + std::to_string(falling_counter_ / 4));
#endif
}
@@ -550,17 +546,17 @@ bool Player::isOnFloor()
#ifdef DEBUG
if (onFloor)
{
debug_->add("ON_FLOOR");
Debug::get()->add("ON_FLOOR");
}
if (onSlopeL)
{
debug_->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y));
Debug::get()->add("ON_SLOPE_L: " + std::to_string(under_feet_[0].x) + "," + std::to_string(under_feet_[0].y));
}
if (onSlopeR)
{
debug_->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y));
Debug::get()->add("ON_SLOPE_R: " + std::to_string(under_feet_[1].x) + "," + std::to_string(under_feet_[1].y));
}
#endif
@@ -583,7 +579,7 @@ bool Player::isOnAutoSurface()
#ifdef DEBUG
if (onAutoSurface)
{
debug_->add("ON_AUTO_SURFACE");
Debug::get()->add("ON_AUTO_SURFACE");
}
#endif
@@ -609,7 +605,7 @@ bool Player::isOnDownSlope()
#ifdef DEBUG
if (onSlope)
{
debug_->add("ON_DOWN_SLOPE");
Debug::get()->add("ON_DOWN_SLOPE");
}
#endif
@@ -744,34 +740,36 @@ void Player::initSprite(const std::string &texture_path, const std::string &anim
// Pinta la información de debug del jugador
void Player::renderDebugInfo()
{
if (debug_->getEnabled())
if (Debug::get()->getEnabled())
{
auto renderer = Screen::get()->getRenderer();
// Pinta los underfeet
SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 255);
SDL_RenderDrawPoint(renderer_, under_feet_[0].x, under_feet_[0].y);
SDL_RenderDrawPoint(renderer_, under_feet_[1].x, under_feet_[1].y);
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
SDL_RenderDrawPoint(renderer, under_feet_[0].x, under_feet_[0].y);
SDL_RenderDrawPoint(renderer, under_feet_[1].x, under_feet_[1].y);
// Pinta rectangulo del jugador
SDL_SetRenderDrawColor(renderer_, debug_color_.r, debug_color_.g, debug_color_.b, 192);
SDL_SetRenderDrawColor(renderer, debug_color_.r, debug_color_.g, debug_color_.b, 192);
SDL_Rect rect = getRect();
SDL_RenderFillRect(renderer_, &rect);
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 255);
SDL_RenderDrawRect(renderer_, &rect);
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_SetRenderDrawColor(renderer, 255, 0, 0, 255);
if (vx_ != 0.0f)
{
SDL_RenderFillRect(renderer_, &debug_rect_x_);
SDL_RenderFillRect(renderer, &debug_rect_x_);
}
if (vy_ != 0.0f)
{
SDL_RenderFillRect(renderer_, &debug_rect_y_);
SDL_RenderFillRect(renderer, &debug_rect_y_);
}
// Pinta el punto de debug
SDL_SetRenderDrawColor(renderer_, rand() % 256, rand() % 256, rand() % 256, 255);
SDL_RenderDrawPoint(renderer_, debug_point_.x, debug_point_.y);
SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255);
SDL_RenderDrawPoint(renderer, debug_point_.x, debug_point_.y);
}
}
#endif