80 lines
1.8 KiB
C++
80 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
|
#include <SDL2/SDL_stdinc.h> // for Uint8
|
|
#include <memory> // for shared_ptr, unique_ptr
|
|
#include "sprite.h" // for Sprite
|
|
#include "utils.h" // for Circle
|
|
class Texture;
|
|
|
|
// Enumeración para los diferentes tipos de balas
|
|
enum class BulletType
|
|
{
|
|
UP,
|
|
LEFT,
|
|
RIGHT,
|
|
NONE
|
|
};
|
|
|
|
// 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_; // Sprite con los gráficos y métodos de pintado
|
|
|
|
int pos_x_; // Posición en el eje X
|
|
int pos_y_; // Posición en el eje Y
|
|
Uint8 width_; // Ancho del objeto
|
|
Uint8 height_; // Alto del objeto
|
|
|
|
int vel_x_; // Velocidad en el eje X
|
|
int vel_y_; // Velocidad en el eje Y
|
|
|
|
BulletType kind_; // Tipo de objeto
|
|
int owner_; // Identificador del dueño del objeto
|
|
Circle collider_; // Círculo de colisión del objeto
|
|
SDL_Rect *play_area_; // Rectángulo con la zona de juego
|
|
|
|
void shiftColliders(); // Alinea el círculo de colisión con el objeto
|
|
|
|
public:
|
|
// Constructor
|
|
Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr<Texture> texture);
|
|
|
|
// Destructor
|
|
~Bullet() = default;
|
|
|
|
// Pinta el objeto en pantalla
|
|
void render();
|
|
|
|
// Actualiza la posición y estado del objeto
|
|
BulletMoveStatus move();
|
|
|
|
// Comprueba si el objeto está habilitado
|
|
bool isEnabled() const;
|
|
|
|
// Deshabilita el objeto
|
|
void disable();
|
|
|
|
// Obtiene la posición
|
|
int getPosX() const;
|
|
int getPosY() const;
|
|
|
|
// Establece la posición
|
|
void setPosX(int x);
|
|
void setPosY(int y);
|
|
|
|
// Obtiene parámetros
|
|
int getVelY() const;
|
|
BulletType getKind() const;
|
|
int getOwner() const;
|
|
Circle &getCollider();
|
|
};
|