novetat: canvi de color de les bales quan queda poc powerUp
This commit is contained in:
@@ -4,28 +4,29 @@
|
||||
#include <string> // Para char_traits, basic_string, operator+, string
|
||||
|
||||
#include "param.h" // Para Param, ParamGame, param
|
||||
#include "player.h" // Para Player::Id
|
||||
#include "resource.h" // Para Resource
|
||||
|
||||
// Constructor
|
||||
Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, Player::Id owner)
|
||||
Bullet::Bullet(float x, float y, Type type, Color color, int owner)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("bullet.png"), Resource::get()->getAnimation("bullet.ani"))),
|
||||
bullet_type_(bullet_type),
|
||||
type_(type),
|
||||
owner_(owner),
|
||||
pos_x_(x),
|
||||
pos_y_(y) {
|
||||
vel_x_ = calculateVelocity(bullet_type_);
|
||||
sprite_->setCurrentAnimation(buildAnimationString(bullet_type_, powered));
|
||||
vel_x_ = calculateVelocity(type_);
|
||||
sprite_->setCurrentAnimation(buildAnimationString(type_, color));
|
||||
|
||||
collider_.r = WIDTH / 2;
|
||||
shiftColliders();
|
||||
}
|
||||
|
||||
// Calcula la velocidad horizontal de la bala basada en su tipo
|
||||
auto Bullet::calculateVelocity(BulletType bullet_type) -> float {
|
||||
switch (bullet_type) {
|
||||
case BulletType::LEFT:
|
||||
auto Bullet::calculateVelocity(Type type) -> float {
|
||||
switch (type) {
|
||||
case Type::LEFT:
|
||||
return VEL_X_LEFT;
|
||||
case BulletType::RIGHT:
|
||||
case Type::RIGHT:
|
||||
return VEL_X_RIGHT;
|
||||
default:
|
||||
return VEL_X_CENTER;
|
||||
@@ -33,17 +34,17 @@ auto Bullet::calculateVelocity(BulletType bullet_type) -> float {
|
||||
}
|
||||
|
||||
// Construye el string de animación basado en el tipo de bala y si está potenciada
|
||||
auto Bullet::buildAnimationString(BulletType bullet_type, bool powered) -> std::string {
|
||||
std::string animation_string = powered ? "powered_" : "normal_";
|
||||
auto Bullet::buildAnimationString(Type type, Color color) -> std::string {
|
||||
std::string animation_string = color == Color::GREEN ? "powered_" : "normal_";
|
||||
|
||||
switch (bullet_type) {
|
||||
case BulletType::UP:
|
||||
switch (type) {
|
||||
case Type::UP:
|
||||
animation_string += "up";
|
||||
break;
|
||||
case BulletType::LEFT:
|
||||
case Type::LEFT:
|
||||
animation_string += "left";
|
||||
break;
|
||||
case BulletType::RIGHT:
|
||||
case Type::RIGHT:
|
||||
animation_string += "right";
|
||||
break;
|
||||
default:
|
||||
@@ -53,49 +54,48 @@ auto Bullet::buildAnimationString(BulletType bullet_type, bool powered) -> std::
|
||||
return animation_string;
|
||||
}
|
||||
|
||||
// Implementación de render (llama al render del sprite_)
|
||||
// Implementación de render
|
||||
void Bullet::render() {
|
||||
if (bullet_type_ != BulletType::NONE) {
|
||||
if (type_ != Type::NONE) {
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el estado del objeto (time-based)
|
||||
auto Bullet::update(float deltaTime) -> BulletMoveStatus {
|
||||
// Actualiza el estado del objeto
|
||||
auto Bullet::update(float deltaTime) -> MoveStatus {
|
||||
sprite_->update(deltaTime);
|
||||
return move(deltaTime);
|
||||
}
|
||||
|
||||
// Implementación del movimiento usando BulletMoveStatus (time-based)
|
||||
auto Bullet::move(float deltaTime) -> BulletMoveStatus {
|
||||
// DeltaTime puro: velocidad (pixels/segundo) * tiempo (segundos)
|
||||
// Implementación del movimiento usando MoveStatus
|
||||
auto Bullet::move(float deltaTime) -> MoveStatus {
|
||||
pos_x_ += vel_x_ * deltaTime;
|
||||
if (pos_x_ < param.game.play_area.rect.x - WIDTH || pos_x_ > param.game.play_area.rect.w) {
|
||||
disable();
|
||||
return BulletMoveStatus::OUT;
|
||||
return MoveStatus::OUT;
|
||||
}
|
||||
|
||||
pos_y_ += VEL_Y * deltaTime;
|
||||
if (pos_y_ < param.game.play_area.rect.y - HEIGHT) {
|
||||
disable();
|
||||
return BulletMoveStatus::OUT;
|
||||
return MoveStatus::OUT;
|
||||
}
|
||||
|
||||
shiftSprite();
|
||||
shiftColliders();
|
||||
|
||||
return BulletMoveStatus::OK;
|
||||
return MoveStatus::OK;
|
||||
}
|
||||
|
||||
auto Bullet::isEnabled() const -> bool {
|
||||
return bullet_type_ != BulletType::NONE;
|
||||
return type_ != Type::NONE;
|
||||
}
|
||||
|
||||
void Bullet::disable() {
|
||||
bullet_type_ = BulletType::NONE;
|
||||
type_ = Type::NONE;
|
||||
}
|
||||
|
||||
auto Bullet::getOwner() const -> Player::Id {
|
||||
auto Bullet::getOwner() const -> int {
|
||||
return owner_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user