neteja tidy a source/game (fixes d'arrel: BulletKind enum class, signatures, branches)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "game/entities/bullet.h"
|
||||
|
||||
#include "core/rendering/sprite.h" // for Sprite
|
||||
#include "game/defaults.hpp" // for NO_KIND, PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
#include "game/defaults.hpp" // for BulletKind::NONE, PLAY_AREA_LEFT, PLAY_AREA_RIGHT, PLAY_A...
|
||||
class Texture;
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *texture, SDL_Renderer *renderer) {
|
||||
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);
|
||||
|
||||
// Posición inicial del objeto
|
||||
@@ -27,7 +27,7 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *textu
|
||||
|
||||
// Valores especificos según el tipo
|
||||
switch (kind) {
|
||||
case BULLET_UP:
|
||||
case BulletKind::UP:
|
||||
// Establece la velocidad inicial
|
||||
velX = 0;
|
||||
|
||||
@@ -39,7 +39,7 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *textu
|
||||
}
|
||||
break;
|
||||
|
||||
case BULLET_LEFT:
|
||||
case BulletKind::LEFT:
|
||||
// Establece la velocidad inicial
|
||||
velX = -2;
|
||||
|
||||
@@ -51,7 +51,7 @@ Bullet::Bullet(int x, int y, int kind, bool poweredUp, int owner, Texture *textu
|
||||
}
|
||||
break;
|
||||
|
||||
case BULLET_RIGHT:
|
||||
case BulletKind::RIGHT:
|
||||
// Establece la velocidad inicial
|
||||
velX = 2;
|
||||
|
||||
@@ -85,7 +85,7 @@ void Bullet::render() {
|
||||
}
|
||||
|
||||
// Actualiza la posición y estado del objeto en horizontal
|
||||
Uint8 Bullet::move() {
|
||||
auto Bullet::move() -> Uint8 {
|
||||
// Variable con el valor de retorno
|
||||
Uint8 msg = BULLET_MOVE_OK;
|
||||
|
||||
@@ -95,19 +95,19 @@ Uint8 Bullet::move() {
|
||||
// Si el objeto se sale del area de juego por los laterales
|
||||
if ((posX < PLAY_AREA_LEFT - width) || (posX > PLAY_AREA_RIGHT)) {
|
||||
// Se deshabilita
|
||||
kind = NO_KIND;
|
||||
kind = BulletKind::NONE;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = BULLET_MOVE_OUT;
|
||||
}
|
||||
|
||||
// Mueve el objeto a su nueva posición en vertical
|
||||
posY += int(velY);
|
||||
posY += velY;
|
||||
|
||||
// Si el objeto se sale del area de juego por la parte superior
|
||||
if (posY < PLAY_AREA_TOP - height) {
|
||||
// Se deshabilita
|
||||
kind = NO_KIND;
|
||||
kind = BulletKind::NONE;
|
||||
|
||||
// Mensaje de salida
|
||||
msg = BULLET_MOVE_OUT;
|
||||
@@ -124,26 +124,22 @@ Uint8 Bullet::move() {
|
||||
}
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool Bullet::isEnabled() {
|
||||
if (kind == NO_KIND) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
auto Bullet::isEnabled() const -> bool {
|
||||
return kind != BulletKind::NONE;
|
||||
}
|
||||
|
||||
// Deshabilita el objeto
|
||||
void Bullet::disable() {
|
||||
kind = NO_KIND;
|
||||
kind = BulletKind::NONE;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Bullet::getPosX() {
|
||||
auto Bullet::getPosX() const -> int {
|
||||
return posX;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Bullet::getPosY() {
|
||||
auto Bullet::getPosY() const -> int {
|
||||
return posY;
|
||||
}
|
||||
|
||||
@@ -158,22 +154,22 @@ void Bullet::setPosY(int y) {
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Bullet::getVelY() {
|
||||
auto Bullet::getVelY() const -> int {
|
||||
return velY;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Bullet::getKind() {
|
||||
auto Bullet::getKind() const -> BulletKind {
|
||||
return kind;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Bullet::getOwner() {
|
||||
auto Bullet::getOwner() const -> int {
|
||||
return owner;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
circle_t &Bullet::getCollider() {
|
||||
auto Bullet::getCollider() -> circle_t & {
|
||||
return collider;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user