treball en curs: correccions de tidy
This commit is contained in:
@@ -1,65 +1,65 @@
|
||||
#include "game/entities/bullet.h"
|
||||
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "game/defaults.hpp" // for BulletKind::NONE, PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
#include "game/defaults.hpp" // for PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer) {
|
||||
sprite = new Sprite({x, y, 10, 10}, texture, renderer);
|
||||
Bullet::Bullet(int x, int y, Bullet::Kind kind, bool powered_up, int owner, Texture *texture, SDL_Renderer *renderer) {
|
||||
sprite_ = new Sprite({x, y, 10, 10}, texture, renderer);
|
||||
|
||||
// Posición inicial del objeto
|
||||
posX = x;
|
||||
posY = y;
|
||||
pos_x_ = x;
|
||||
pos_y_ = y;
|
||||
|
||||
// Alto y ancho del objeto
|
||||
width = 10;
|
||||
height = 10;
|
||||
width_ = 10;
|
||||
height_ = 10;
|
||||
|
||||
// Velocidad inicial en el eje Y
|
||||
velY = -3;
|
||||
vel_y_ = -3;
|
||||
|
||||
// Tipo de bala
|
||||
this->kind = kind;
|
||||
this->kind_ = kind;
|
||||
|
||||
// Identificador del dueño del objeto
|
||||
this->owner = owner;
|
||||
this->owner_ = owner;
|
||||
|
||||
// Valores especificos según el tipo
|
||||
switch (kind) {
|
||||
case BulletKind::UP:
|
||||
case Bullet::Kind::UP:
|
||||
// Establece la velocidad inicial
|
||||
velX = 0;
|
||||
vel_x_ = 0;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
if (!poweredUp) {
|
||||
sprite->setSpriteClip(0 * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
if (!powered_up) {
|
||||
sprite_->setSpriteClip(0 * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
} else {
|
||||
sprite->setSpriteClip((0 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
sprite_->setSpriteClip((0 + 3) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
}
|
||||
break;
|
||||
|
||||
case BulletKind::LEFT:
|
||||
case Bullet::Kind::LEFT:
|
||||
// Establece la velocidad inicial
|
||||
velX = -2;
|
||||
vel_x_ = -2;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
if (!poweredUp) {
|
||||
sprite->setSpriteClip(1 * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
if (!powered_up) {
|
||||
sprite_->setSpriteClip(1 * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
} else {
|
||||
sprite->setSpriteClip((1 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
sprite_->setSpriteClip((1 + 3) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
}
|
||||
break;
|
||||
|
||||
case BulletKind::RIGHT:
|
||||
case Bullet::Kind::RIGHT:
|
||||
// Establece la velocidad inicial
|
||||
velX = 2;
|
||||
vel_x_ = 2;
|
||||
|
||||
// Rectangulo con los gráficos del objeto
|
||||
if (!poweredUp) {
|
||||
sprite->setSpriteClip(2 * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
if (!powered_up) {
|
||||
sprite_->setSpriteClip(2 * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
} else {
|
||||
sprite->setSpriteClip((2 + 3) * width, 0, sprite->getWidth(), sprite->getHeight());
|
||||
sprite_->setSpriteClip((2 + 3) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -68,7 +68,7 @@ Bullet::Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture
|
||||
}
|
||||
|
||||
// Establece el tamaño del circulo de colisión
|
||||
collider.r = width / 2;
|
||||
collider_.r = width_ / 2;
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
@@ -76,46 +76,46 @@ Bullet::Bullet(int x, int y, BulletKind kind, bool poweredUp, int owner, Texture
|
||||
|
||||
// Destructor
|
||||
Bullet::~Bullet() {
|
||||
delete sprite;
|
||||
delete sprite_;
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void Bullet::render() {
|
||||
sprite->render();
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Actualiza la posición y estado del objeto en horizontal
|
||||
auto Bullet::move() -> Uint8 {
|
||||
auto Bullet::move() -> MoveResult {
|
||||
// Variable con el valor de retorno
|
||||
Uint8 msg = BULLET_MOVE_OK;
|
||||
MoveResult msg = MoveResult::OK;
|
||||
|
||||
// Mueve el objeto a su nueva posición
|
||||
posX += velX;
|
||||
pos_x_ += vel_x_;
|
||||
|
||||
// Si el objeto se sale del area de juego por los laterales
|
||||
if ((posX < PLAY_AREA_LEFT - width) || (posX > PLAY_AREA_RIGHT)) {
|
||||
if ((pos_x_ < PLAY_AREA_LEFT - width_) || (pos_x_ > PLAY_AREA_RIGHT)) {
|
||||
// Se deshabilita
|
||||
kind = BulletKind::NONE;
|
||||
kind_ = Bullet::Kind::NONE;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = BULLET_MOVE_OUT;
|
||||
msg = MoveResult::OUT;
|
||||
}
|
||||
|
||||
// Mueve el objeto a su nueva posición en vertical
|
||||
posY += velY;
|
||||
pos_y_ += vel_y_;
|
||||
|
||||
// Si el objeto se sale del area de juego por la parte superior
|
||||
if (posY < PLAY_AREA_TOP - height) {
|
||||
if (pos_y_ < PLAY_AREA_TOP - height_) {
|
||||
// Se deshabilita
|
||||
kind = BulletKind::NONE;
|
||||
kind_ = Bullet::Kind::NONE;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = BULLET_MOVE_OUT;
|
||||
msg = MoveResult::OUT;
|
||||
}
|
||||
|
||||
// Actualiza la posición del sprite
|
||||
sprite->setPosX(posX);
|
||||
sprite->setPosY(posY);
|
||||
sprite_->setPosX(pos_x_);
|
||||
sprite_->setPosY(pos_y_);
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
shiftColliders();
|
||||
@@ -125,56 +125,56 @@ auto Bullet::move() -> Uint8 {
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
auto Bullet::isEnabled() const -> bool {
|
||||
return kind != BulletKind::NONE;
|
||||
return kind_ != Bullet::Kind::NONE;
|
||||
}
|
||||
|
||||
// Deshabilita el objeto
|
||||
void Bullet::disable() {
|
||||
kind = BulletKind::NONE;
|
||||
kind_ = Bullet::Kind::NONE;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getPosX() const -> int {
|
||||
return posX;
|
||||
return pos_x_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getPosY() const -> int {
|
||||
return posY;
|
||||
return pos_y_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Bullet::setPosX(int x) {
|
||||
posX = x;
|
||||
pos_x_ = x;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Bullet::setPosY(int y) {
|
||||
posY = y;
|
||||
pos_y_ = y;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getVelY() const -> int {
|
||||
return velY;
|
||||
return vel_y_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getKind() const -> BulletKind {
|
||||
return kind;
|
||||
auto Bullet::getKind() const -> Bullet::Kind {
|
||||
return kind_;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto Bullet::getOwner() const -> int {
|
||||
return owner;
|
||||
return owner_;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
auto Bullet::getCollider() -> Circle & {
|
||||
return collider;
|
||||
return collider_;
|
||||
}
|
||||
|
||||
// Alinea el circulo de colisión con el objeto
|
||||
void Bullet::shiftColliders() {
|
||||
collider.x = posX + collider.r;
|
||||
collider.y = posY + collider.r;
|
||||
collider_.x = pos_x_ + collider_.r;
|
||||
collider_.y = pos_y_ + collider_.r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user