Aplicar formato automático con clang-format a todo el código fuente
- Reformatear archivos .cpp y .h según configuración Google personalizada - Mejorar consistencia en indentación y espaciado - Reorganizar includes y declaraciones de clases - Mantener funcionalidad existente sin cambios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+24
-37
@@ -1,14 +1,16 @@
|
||||
#include "ball.h"
|
||||
|
||||
#include <stdlib.h> // for rand
|
||||
#include <cmath> // for fabs
|
||||
#include "defines.h" // for BALL_SIZE, Color, SCREEN_HEIGHT, GRAVITY_FORCE
|
||||
|
||||
#include <cmath> // for fabs
|
||||
|
||||
#include "defines.h" // for BALL_SIZE, Color, SCREEN_HEIGHT, GRAVITY_FORCE
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> texture)
|
||||
: sprite_(std::make_unique<Sprite>(texture)),
|
||||
pos_({x, 0.0f, BALL_SIZE, BALL_SIZE})
|
||||
{
|
||||
pos_({x, 0.0f, BALL_SIZE, BALL_SIZE}) {
|
||||
// Convertir velocidades de píxeles/frame a píxeles/segundo (multiplicar por 60)
|
||||
vx_ = vx * 60.0f;
|
||||
vy_ = vy * 60.0f;
|
||||
@@ -24,58 +26,48 @@ Ball::Ball(float x, float vx, float vy, Color color, std::shared_ptr<Texture> te
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void Ball::update(float deltaTime)
|
||||
{
|
||||
if (stopped_)
|
||||
{
|
||||
void Ball::update(float deltaTime) {
|
||||
if (stopped_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Aplica la gravedad a la velocidad (píxeles/segundo²)
|
||||
if (!on_floor_)
|
||||
{
|
||||
if (!on_floor_) {
|
||||
vy_ += gravity_force_ * deltaTime;
|
||||
}
|
||||
|
||||
// Actualiza la posición en función de la velocidad (píxeles/segundo)
|
||||
pos_.x += vx_ * deltaTime;
|
||||
if (!on_floor_)
|
||||
{
|
||||
if (!on_floor_) {
|
||||
pos_.y += vy_ * deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Si está en el suelo, mantenerla ahí
|
||||
pos_.y = SCREEN_HEIGHT - pos_.h;
|
||||
}
|
||||
|
||||
// Comprueba las colisiones con el lateral izquierdo
|
||||
if (pos_.x < 0)
|
||||
{
|
||||
if (pos_.x < 0) {
|
||||
pos_.x = 0;
|
||||
vx_ = -vx_;
|
||||
}
|
||||
|
||||
// Comprueba las colisiones con el lateral derecho
|
||||
if (pos_.x + pos_.w > SCREEN_WIDTH)
|
||||
{
|
||||
if (pos_.x + pos_.w > SCREEN_WIDTH) {
|
||||
pos_.x = SCREEN_WIDTH - pos_.w;
|
||||
vx_ = -vx_;
|
||||
}
|
||||
|
||||
// Comprueba las colisiones con la parte superior
|
||||
if (pos_.y < 0)
|
||||
{
|
||||
if (pos_.y < 0) {
|
||||
pos_.y = 0;
|
||||
vy_ = -vy_;
|
||||
}
|
||||
|
||||
// Comprueba las colisiones con la parte inferior
|
||||
if (pos_.y + pos_.h > SCREEN_HEIGHT)
|
||||
{
|
||||
if (pos_.y + pos_.h > SCREEN_HEIGHT) {
|
||||
pos_.y = SCREEN_HEIGHT - pos_.h;
|
||||
vy_ = -vy_ * loss_;
|
||||
if (std::fabs(vy_) < 6.0f) // Convertir 0.1f frame-based a 6.0f time-based
|
||||
if (std::fabs(vy_) < 6.0f) // Convertir 0.1f frame-based a 6.0f time-based
|
||||
{
|
||||
vy_ = 0.0f;
|
||||
on_floor_ = true;
|
||||
@@ -83,15 +75,14 @@ void Ball::update(float deltaTime)
|
||||
}
|
||||
|
||||
// Aplica rozamiento al rodar por el suelo
|
||||
if (on_floor_)
|
||||
{
|
||||
if (on_floor_) {
|
||||
// Convertir rozamiento de frame-based a time-based
|
||||
// 0.97f por frame equivale a pow(0.97f, 60 * deltaTime)
|
||||
float friction_factor = pow(0.97f, 60.0f * deltaTime);
|
||||
vx_ = vx_ * friction_factor;
|
||||
|
||||
// Umbral de parada ajustado para velocidades en píxeles/segundo
|
||||
if (std::fabs(vx_) < 6.0f) // ~0.1f * 60 para time-based
|
||||
if (std::fabs(vx_) < 6.0f) // ~0.1f * 60 para time-based
|
||||
{
|
||||
vx_ = 0.0f;
|
||||
stopped_ = true;
|
||||
@@ -103,26 +94,22 @@ void Ball::update(float deltaTime)
|
||||
}
|
||||
|
||||
// Pinta la clase
|
||||
void Ball::render()
|
||||
{
|
||||
void Ball::render() {
|
||||
sprite_->setColor(color_.r, color_.g, color_.b);
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Modifica la velocidad (convierte de frame-based a time-based)
|
||||
void Ball::modVel(float vx, float vy)
|
||||
{
|
||||
if (stopped_)
|
||||
{
|
||||
vx_ = vx_ + (vx * 60.0f); // Convertir a píxeles/segundo
|
||||
void Ball::modVel(float vx, float vy) {
|
||||
if (stopped_) {
|
||||
vx_ = vx_ + (vx * 60.0f); // Convertir a píxeles/segundo
|
||||
}
|
||||
vy_ = vy_ + (vy * 60.0f); // Convertir a píxeles/segundo
|
||||
vy_ = vy_ + (vy * 60.0f); // Convertir a píxeles/segundo
|
||||
on_floor_ = false;
|
||||
stopped_ = false;
|
||||
}
|
||||
|
||||
// Cambia la gravedad (usa la versión convertida)
|
||||
void Ball::switchGravity()
|
||||
{
|
||||
void Ball::switchGravity() {
|
||||
gravity_force_ = gravity_force_ == 0.0f ? (GRAVITY_FORCE * 60.0f * 60.0f) : 0.0f;
|
||||
}
|
||||
Reference in New Issue
Block a user