NUEVAS CARACTERÍSTICAS: - Zoom por profundidad Z: Escala sprites según distancia (0.5x-1.5x) - Toggle con Numpad / (KP_DIVIDE) para activar/desactivar perspectiva - Fix transición figura→física: Reset automático de depth_scale a 1.0 - Texto informativo: "DEPTH ZOOM ON/OFF" IMPLEMENTACIÓN TÉCNICA: - Ball class: Nueva variable depth_scale_ (0.5-1.5) - Ball class: Getters/setters getDepthScale() / setDepthScale() - Engine::addSpriteToBatch(): Parámetro scale con valor defecto 1.0 - Engine::addSpriteToBatch(): Cálculo de vértices escalados centrados - Engine::updateShape(): Cálculo depth_scale = 0.5 + z_normalized * 1.0 - Engine::render(): Pasa depth_scale al batch en modo SHAPE - Engine::toggleShapeMode(): Reset depth_scale en salida de figura - Engine: Variable depth_zoom_enabled_ (true por defecto) - Batch rendering: Mantiene performance (sin llamadas individuales) EFECTO VISUAL: - Pelotas lejanas (Z-): Pequeñas (50%) y oscuras - Pelotas medias (Z=0): Normales (100%) y brillo medio - Pelotas cercanas (Z+): Grandes (150%) y brillantes - Perspectiva 3D realista combinada con Z-sorting CONTROLES: - Numpad /: Toggle zoom por profundidad (solo en modo SHAPE) - Por defecto: ACTIVADO para máximo realismo 3D README ACTUALIZADO: - Añadida tecla KP_/ a tabla de controles - Actualizada sección "Características Técnicas" - Añadida línea "Zoom por profundidad" en características - Actualizada sección "Uso" con control de perspectiva 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
3.9 KiB
C++
92 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL_rect.h> // for SDL_FRect
|
|
|
|
#include <memory> // for shared_ptr, unique_ptr
|
|
|
|
#include "defines.h" // for Color
|
|
#include "external/sprite.h" // for Sprite
|
|
class Texture;
|
|
|
|
class Ball {
|
|
private:
|
|
std::unique_ptr<Sprite> sprite_; // Sprite para pintar la clase
|
|
SDL_FRect pos_; // Posición y tamaño de la pelota
|
|
float vx_, vy_; // Velocidad
|
|
float gravity_force_; // Gravedad base
|
|
float gravity_mass_factor_; // Factor de masa individual (0.7-1.3, afecta gravedad)
|
|
GravityDirection gravity_direction_; // Direcci\u00f3n de la gravedad
|
|
int screen_width_; // Ancho del terreno de juego
|
|
int screen_height_; // Alto del terreno de juego
|
|
Color color_; // Color de la pelota
|
|
bool on_surface_; // Indica si la pelota est\u00e1 en la superficie (suelo/techo/pared)
|
|
bool stopped_; // Indica si la pelota ha terminado de moverse;
|
|
float loss_; // Coeficiente de rebote. Pérdida de energía en cada rebote
|
|
|
|
// Datos para modo RotoBall (esfera 3D)
|
|
float pos_3d_x_, pos_3d_y_, pos_3d_z_; // Posición 3D en la esfera
|
|
float target_x_, target_y_; // Posición destino 2D (proyección)
|
|
float depth_brightness_; // Brillo según profundidad Z (0.0-1.0)
|
|
float depth_scale_; // Escala según profundidad Z (0.5-1.5)
|
|
bool rotoball_attraction_active_; // ¿Está siendo atraída hacia la esfera?
|
|
|
|
public:
|
|
// Constructor
|
|
Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture, int screen_width, int screen_height, GravityDirection gravity_dir = GravityDirection::DOWN, float mass_factor = 1.0f);
|
|
|
|
// Destructor
|
|
~Ball() = default;
|
|
|
|
// Actualiza la lógica de la clase
|
|
void update(float deltaTime);
|
|
|
|
// Pinta la clase
|
|
void render();
|
|
|
|
// Modifica la velocidad
|
|
void modVel(float vx, float vy);
|
|
|
|
// Cambia la gravedad
|
|
void switchGravity();
|
|
|
|
// Reactiva la gravedad si está desactivada
|
|
void enableGravityIfDisabled();
|
|
|
|
// Fuerza gravedad ON (siempre activa)
|
|
void forceGravityOn();
|
|
|
|
// Fuerza gravedad OFF (siempre desactiva)
|
|
void forceGravityOff();
|
|
|
|
// Cambia la direcci\u00f3n de gravedad
|
|
void setGravityDirection(GravityDirection direction);
|
|
|
|
// Aplica un peque\u00f1o empuje lateral aleatorio
|
|
void applyRandomLateralPush();
|
|
|
|
// Getters para debug
|
|
float getVelocityY() const { return vy_; }
|
|
float getVelocityX() const { return vx_; }
|
|
float getGravityForce() const { return gravity_force_; }
|
|
float getLossCoefficient() const { return loss_; }
|
|
GravityDirection getGravityDirection() const { return gravity_direction_; }
|
|
bool isOnSurface() const { return on_surface_; }
|
|
bool isStopped() const { return stopped_; }
|
|
|
|
// Getters para batch rendering
|
|
SDL_FRect getPosition() const { return pos_; }
|
|
Color getColor() const { return color_; }
|
|
|
|
// Funciones para modo RotoBall
|
|
void setRotoBallPosition3D(float x, float y, float z);
|
|
void setRotoBallTarget2D(float x, float y);
|
|
void setRotoBallScreenPosition(float x, float y); // Establecer posición directa en pantalla
|
|
void setDepthBrightness(float brightness);
|
|
float getDepthBrightness() const { return depth_brightness_; }
|
|
void setDepthScale(float scale);
|
|
float getDepthScale() const { return depth_scale_; }
|
|
|
|
// Sistema de atracción física hacia esfera RotoBall
|
|
void enableRotoBallAttraction(bool enable);
|
|
void applyRotoBallForce(float target_x, float target_y, float sphere_radius, float deltaTime);
|
|
}; |