Implementar sistema de gravedad direccional con controles de cursor
- Añadir enum GravityDirection (UP/DOWN/LEFT/RIGHT) en defines.h - Modificar Ball class para soportar gravedad multi-direccional - Reescribir Ball::update() con lógica direccional completa - Cambiar on_floor_ por on_surface_ (más genérico) - Implementar detección de superficie según dirección de gravedad - Añadir controles de teclado con teclas de cursor - Actualizar debug display para mostrar dirección actual - Aplicar fricción correctamente según superficie activa Controles nuevos: - ↑/↓/←/→: Cambiar dirección de gravedad - H: Toggle debug display (incluye nueva info de gravedad) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
55
source/ball.h
Normal file
55
source/ball.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#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
|
||||
GravityDirection gravity_direction_; // Direcci\u00f3n de la gravedad
|
||||
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
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture, GravityDirection gravity_dir = GravityDirection::DOWN);
|
||||
|
||||
// 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();
|
||||
|
||||
// Cambia la direcci\u00f3n de gravedad
|
||||
void setGravityDirection(GravityDirection direction);
|
||||
|
||||
// Getters para debug
|
||||
float getVelocityY() const { return vy_; }
|
||||
float getVelocityX() const { return vx_; }
|
||||
float getGravityForce() const { return gravity_force_; }
|
||||
GravityDirection getGravityDirection() const { return gravity_direction_; }
|
||||
bool isOnSurface() const { return on_surface_; }
|
||||
|
||||
// Getters para batch rendering
|
||||
SDL_FRect getPosition() const { return pos_; }
|
||||
Color getColor() const { return color_; }
|
||||
};
|
||||
Reference in New Issue
Block a user