diff --git a/bullet-chatGPT.cpp b/bullet-chatGPT.cpp deleted file mode 100644 index 5693401..0000000 --- a/bullet-chatGPT.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "bullet.h" -#include "param.h" // for param -#include "sprite.h" // for Sprite -#include // for std::unique_ptr - -// Constantes evaluables en tiempo de compilación -constexpr int BULLET_WIDTH = 12; -constexpr int BULLET_HEIGHT = 12; -constexpr int BULLET_VELY = -3; -constexpr int BULLET_VELX_LEFT = -2; -constexpr int BULLET_VELX_RIGHT = 2; - -// Constructor -Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, Texture *texture) - : posX(x), posY(y), kind(kind), owner(owner), playArea(playArea), - width(BULLET_WIDTH), height(BULLET_HEIGHT), velY(BULLET_VELY), - sprite(std::make_unique(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture)) -{ - velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT - : 0; - - auto spriteOffset = poweredUp ? 3 : 0; - auto kindIndex = static_cast(kind); - sprite->setSpriteClip((kindIndex + spriteOffset) * width, 0, sprite->getWidth(), sprite->getHeight()); - - collider.r = width / 2; - shiftColliders(); -} - -// Implementación de render (llama al render del sprite) -void Bullet::render() -{ - sprite->render(); -} - -// Implementación del movimiento usando BulletMoveStatus -BulletMoveStatus Bullet::move() -{ - posX += velX; - if (posX < param.game.playArea.rect.x - width || posX > playArea->w) - { - disable(); - return BulletMoveStatus::OUT; - } - - posY += velY; - if (posY < param.game.playArea.rect.y - height) - { - disable(); - return BulletMoveStatus::OUT; - } - - sprite->setPosX(posX); - sprite->setPosY(posY); - shiftColliders(); - - return BulletMoveStatus::OK; -} - -bool Bullet::isEnabled() const -{ - return kind != BulletType::NULL_TYPE; -} - -void Bullet::disable() -{ - kind = BulletType::NULL_TYPE; -} - -int Bullet::getPosX() const -{ - return posX; -} - -int Bullet::getPosY() const -{ - return posY; -} - -void Bullet::setPosX(int x) -{ - posX = x; -} - -void Bullet::setPosY(int y) -{ - posY = y; -} - -int Bullet::getVelY() const -{ - return velY; -} - -BulletType Bullet::getKind() const -{ - return kind; -} - -int Bullet::getOwner() const -{ - return owner; -} - -circle_t &Bullet::getCollider() -{ - return collider; -} - -void Bullet::shiftColliders() -{ - collider.x = posX + collider.r; - collider.y = posY + collider.r; -} diff --git a/bullet-chatGPT.h b/bullet-chatGPT.h deleted file mode 100644 index be23b96..0000000 --- a/bullet-chatGPT.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include // for SDL_Rect -#include // for Uint8 -#include "utils.h" // for circle_t -#include // for std::unique_ptr - -class Sprite; -class Texture; - -// Enumeración para los diferentes tipos de balas -enum class BulletType { - UP, - LEFT, - RIGHT, - NULL_TYPE -}; - -// Enumeración para los resultados del movimiento de la bala -enum class BulletMoveStatus : Uint8 { - OK = 0, - OUT = 1 -}; - -// Clase Bullet -class Bullet -{ -private: - std::unique_ptr sprite; // Sprite con los gráficos y métodos de pintado - - int posX; // Posición en el eje X - int posY; // Posición en el eje Y - Uint8 width; // Ancho del objeto - Uint8 height; // Alto del objeto - int velX; // Velocidad en el eje X - int velY; // Velocidad en el eje Y - BulletType kind; // Tipo de objeto - int owner; // Identificador del dueño del objeto - circle_t collider; // Círculo de colisión del objeto - SDL_Rect *playArea; // Rectángulo con la zona de juego - - void shiftColliders(); // Alinea el círculo de colisión con el objeto - -public: - Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, Texture *texture); - ~Bullet() = default; - - void render(); // Pinta el objeto en pantalla - BulletMoveStatus move(); // Actualiza la posición y estado del objeto - - bool isEnabled() const; // Comprueba si el objeto está habilitado - void disable(); // Deshabilita el objeto - - int getPosX() const; - int getPosY() const; - void setPosX(int x); - void setPosY(int y); - int getVelY() const; - BulletType getKind() const; - int getOwner() const; - circle_t& getCollider(); -}; diff --git a/linux-utils/check-includes.sh b/linux-utils/check-includes.sh new file mode 100755 index 0000000..62f5eb9 --- /dev/null +++ b/linux-utils/check-includes.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SOURCEPATH=../source/ + +for i in "$SOURCEPATH"/*.cpp +do + include-what-you-use -D DEBUG -D VERBOSE -std=c++11 -Wall "$i" +done diff --git a/go.sh b/linux-utils/go.sh similarity index 100% rename from go.sh rename to linux-utils/go.sh diff --git a/linux-utils/include-what-you-use b/linux-utils/include-what-you-use new file mode 100755 index 0000000..1d9e285 Binary files /dev/null and b/linux-utils/include-what-you-use differ diff --git a/source/balloon.cpp b/source/balloon.cpp index 6031391..5696097 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -1,10 +1,10 @@ #include "balloon.h" -#include // for abs -#include "animated_sprite.h" // for AnimatedSprite -#include "moving_sprite.h" // for MovingSprite -#include "param.h" // for param -#include "sprite.h" // for Sprite -#include "texture.h" // for Texture +#include // for abs +#include "animated_sprite.h" // for AnimatedSprite +#include "moving_sprite.h" // for MovingSprite +#include "param.h" // for param +#include "sprite.h" // for Sprite +#include "texture.h" // for Texture // Constructor Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector *animation) diff --git a/source/bullet.h b/source/bullet.h index 5bcf444..7698524 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -2,11 +2,10 @@ #include // for SDL_Rect #include // for Uint8 +#include // for unique_ptr +#include "sprite.h" // for Sprite #include "utils.h" // for circle_t -#include // for std::unique_ptr - -class Sprite; -class Texture; +class Texture; // lines 9-9 // Enumeración para los diferentes tipos de balas enum class BulletType diff --git a/source/game.h b/source/game.h index eb059ee..889ed32 100644 --- a/source/game.h +++ b/source/game.h @@ -7,24 +7,24 @@ #include // for vector #include "section.h" // for options_e #include "utils.h" // for demoKeys_t, color_t, hiScoreEntry_t -#include "bullet.h" -class Asset; -class Background; -class Balloon; -class Bullet; -class EnemyFormations; -class Explosions; -class Fade; -class Input; -class Item; -class Player; -class Scoreboard; -class Screen; -class SmartSprite; -class Text; -class Texture; -struct JA_Music_t; -struct JA_Sound_t; +class Asset; // lines 11-11 +class Background; // lines 12-12 +class Balloon; // lines 13-13 +class Bullet; // lines 14-14 +class EnemyFormations; // lines 15-15 +class Explosions; // lines 16-16 +class Fade; // lines 17-17 +class Input; // lines 18-18 +class Item; // lines 19-19 +class Player; // lines 20-20 +class Scoreboard; // lines 21-21 +class Screen; // lines 22-22 +class SmartSprite; // lines 23-23 +class Text; // lines 24-24 +class Texture; // lines 25-25 +enum class BulletType; +struct JA_Music_t; // lines 26-26 +struct JA_Sound_t; // lines 27-27 #define GAME_MODE_DEMO_OFF false #define GAME_MODE_DEMO_ON true diff --git a/source/utils.cpp b/source/utils.cpp index 38db88f..50b85d3 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,7 +1,10 @@ #include "utils.h" -#include // for free, malloc -struct JA_Music_t; -struct JA_Sound_t; +#include // for free, malloc +#include // for max, min +#include // for isspace +#include // for distance +struct JA_Music_t; // lines 3-3 +struct JA_Sound_t; // lines 4-4 // Colores const color_t bgColor = {0x27, 0x27, 0x36};