ara pots recolocar al jugador en debug amb el ratoli
This commit is contained in:
@@ -67,6 +67,7 @@ class Screen {
|
|||||||
auto getRendererSurface() -> std::shared_ptr<Surface>;
|
auto getRendererSurface() -> std::shared_ptr<Surface>;
|
||||||
auto getBorderSurface() -> std::shared_ptr<Surface>;
|
auto getBorderSurface() -> std::shared_ptr<Surface>;
|
||||||
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; }
|
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; }
|
||||||
|
[[nodiscard]] auto getGameSurfaceDstRect() const -> SDL_FRect { return game_surface_dstrect_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Estructuras
|
// Estructuras
|
||||||
|
|||||||
@@ -887,4 +887,22 @@ auto Player::getProjection(Direction direction, float displacement) -> SDL_FRect
|
|||||||
.w = 0.0F,
|
.w = 0.0F,
|
||||||
.h = 0.0F};
|
.h = 0.0F};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// Establece la posición del jugador directamente (debug)
|
||||||
|
void Player::setDebugPosition(float x, float y) {
|
||||||
|
x_ = x;
|
||||||
|
y_ = y;
|
||||||
|
syncSpriteAndCollider();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fija estado ON_GROUND, velocidades a 0, actualiza last_grounded_position_ (debug)
|
||||||
|
void Player::finalizeDebugTeleport() {
|
||||||
|
vx_ = 0.0F;
|
||||||
|
vy_ = 0.0F;
|
||||||
|
state_ = State::ON_GROUND;
|
||||||
|
last_grounded_position_ = static_cast<int>(y_);
|
||||||
|
syncSpriteAndCollider();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -103,6 +103,12 @@ class Player {
|
|||||||
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo
|
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo
|
||||||
void setPaused(bool value) { is_paused_ = value; } // Pone el jugador en modo pausa
|
void setPaused(bool value) { is_paused_ = value; } // Pone el jugador en modo pausa
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// --- Funciones de debug ---
|
||||||
|
void setDebugPosition(float x, float y); // Establece la posición del jugador directamente (debug)
|
||||||
|
void finalizeDebugTeleport(); // Fija estado ON_GROUND, velocidades a 0, actualiza last_grounded_position_ (debug)
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
static constexpr int WIDTH = 8; // Ancho del jugador
|
static constexpr int WIDTH = 8; // Ancho del jugador
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include <cmath> // Para std::sqrt, std::min
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
@@ -166,7 +167,17 @@ void Game::updatePlaying(float delta_time) {
|
|||||||
room_->update(delta_time);
|
room_->update(delta_time);
|
||||||
switch (mode_) {
|
switch (mode_) {
|
||||||
case Mode::GAME:
|
case Mode::GAME:
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// Maneja el arrastre del jugador con el ratón (debug)
|
||||||
|
handleDebugMouseDrag(delta_time);
|
||||||
|
|
||||||
|
// Si estamos arrastrando, no ejecutar la física normal del jugador
|
||||||
|
if (!debug_dragging_player_) {
|
||||||
|
player_->update(delta_time);
|
||||||
|
}
|
||||||
|
#else
|
||||||
player_->update(delta_time);
|
player_->update(delta_time);
|
||||||
|
#endif
|
||||||
checkPlayerIsOnBorder();
|
checkPlayerIsOnBorder();
|
||||||
checkPlayerAndItems();
|
checkPlayerAndItems();
|
||||||
checkPlayerAndEnemies();
|
checkPlayerAndEnemies();
|
||||||
@@ -439,6 +450,60 @@ void Game::handleDebugEvents(const SDL_Event& event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maneja el arrastre del jugador con el ratón (debug)
|
||||||
|
void Game::handleDebugMouseDrag(float delta_time) {
|
||||||
|
// Solo funciona si Debug está habilitado
|
||||||
|
if (!Debug::get()->isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtener estado del ratón
|
||||||
|
float mouse_x = 0.0F;
|
||||||
|
float mouse_y = 0.0F;
|
||||||
|
SDL_MouseButtonFlags buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||||
|
|
||||||
|
// Convertir coordenadas de ventana a coordenadas de juego
|
||||||
|
SDL_FRect dst_rect = Screen::get()->getGameSurfaceDstRect();
|
||||||
|
|
||||||
|
// Calcular posición en coordenadas de juego (256x192)
|
||||||
|
float game_x = (mouse_x - dst_rect.x) * (static_cast<float>(PlayArea::WIDTH) / dst_rect.w);
|
||||||
|
float game_y = (mouse_y - dst_rect.y) * (static_cast<float>(PlayArea::HEIGHT) / dst_rect.h);
|
||||||
|
|
||||||
|
// Verificar si el botón izquierdo está presionado
|
||||||
|
bool left_button_pressed = (buttons & SDL_BUTTON_LMASK) != 0;
|
||||||
|
|
||||||
|
if (left_button_pressed) {
|
||||||
|
// Obtener posición actual del jugador
|
||||||
|
SDL_FRect player_rect = player_->getRect();
|
||||||
|
float player_x = player_rect.x;
|
||||||
|
float player_y = player_rect.y;
|
||||||
|
|
||||||
|
// Calcular distancia al objetivo
|
||||||
|
float dx = game_x - player_x;
|
||||||
|
float dy = game_y - player_y;
|
||||||
|
float distance = std::sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
|
// Velocidad de movimiento hacia el cursor (pixels/segundo)
|
||||||
|
constexpr float DRAG_SPEED = 300.0F;
|
||||||
|
|
||||||
|
if (distance > 1.0F) {
|
||||||
|
// Calcular el movimiento con aceleración (interpolación suave)
|
||||||
|
float move_factor = std::min(1.0F, DRAG_SPEED * delta_time / distance);
|
||||||
|
float new_x = player_x + dx * move_factor;
|
||||||
|
float new_y = player_y + dy * move_factor;
|
||||||
|
|
||||||
|
// Mover el jugador hacia la posición del cursor
|
||||||
|
player_->setDebugPosition(new_x, new_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_dragging_player_ = true;
|
||||||
|
} else if (debug_dragging_player_) {
|
||||||
|
// Botón soltado después de arrastrar: finalizar teleport
|
||||||
|
player_->finalizeDebugTeleport();
|
||||||
|
debug_dragging_player_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ class Game {
|
|||||||
void updateDebugInfo(); // Pone la información de debug en pantalla
|
void updateDebugInfo(); // Pone la información de debug en pantalla
|
||||||
static void renderDebugInfo(); // Pone la información de debug en pantalla
|
static void renderDebugInfo(); // Pone la información de debug en pantalla
|
||||||
void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos
|
void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos
|
||||||
|
void handleDebugMouseDrag(float delta_time); // Maneja el arrastre del jugador con el ratón (debug)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --- Variables miembro ---
|
// --- Variables miembro ---
|
||||||
@@ -125,4 +126,9 @@ class Game {
|
|||||||
// Variables de efectos visuales
|
// Variables de efectos visuales
|
||||||
SDL_FRect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
|
SDL_FRect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
|
||||||
float jail_restore_time_{0.0F}; // Tiempo acumulado para restauración de vidas en la Jail
|
float jail_restore_time_{0.0F}; // Tiempo acumulado para restauración de vidas en la Jail
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// Variables de debug para arrastre con ratón
|
||||||
|
bool debug_dragging_player_{false}; // Indica si estamos arrastrando al jugador con el ratón
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user