ara pots recolocar al jugador en debug amb el ratoli
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cmath> // Para std::sqrt, std::min
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
@@ -166,7 +167,17 @@ void Game::updatePlaying(float delta_time) {
|
||||
room_->update(delta_time);
|
||||
switch (mode_) {
|
||||
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);
|
||||
#endif
|
||||
checkPlayerIsOnBorder();
|
||||
checkPlayerAndItems();
|
||||
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
|
||||
|
||||
// Escribe el nombre de la pantalla
|
||||
|
||||
Reference in New Issue
Block a user