afegit friendly fire
This commit is contained in:
@@ -19,6 +19,7 @@ Bala::Bala(SDL_Renderer* renderer)
|
||||
angle_(0.0f),
|
||||
velocitat_(0.0f),
|
||||
esta_(false),
|
||||
grace_timer_(0.0f),
|
||||
brightness_(Defaults::Brightness::BALA) {
|
||||
// [NUEVO] Carregar forma compartida des de fitxer
|
||||
forma_ = Graphics::ShapeLoader::load("bullet.shp");
|
||||
@@ -34,6 +35,7 @@ void Bala::inicialitzar() {
|
||||
centre_ = {0.0f, 0.0f};
|
||||
angle_ = 0.0f;
|
||||
velocitat_ = 0.0f;
|
||||
grace_timer_ = 0.0f;
|
||||
}
|
||||
|
||||
void Bala::disparar(const Punt& posicio, float angle, uint8_t owner_id) {
|
||||
@@ -57,12 +59,23 @@ void Bala::disparar(const Punt& posicio, float angle, uint8_t owner_id) {
|
||||
// 7 px/frame × 20 FPS = 140 px/s
|
||||
velocitat_ = 140.0f;
|
||||
|
||||
// Activar grace period (prevents instant self-collision)
|
||||
grace_timer_ = Defaults::Game::BULLET_GRACE_PERIOD;
|
||||
|
||||
// Reproducir sonido de disparo láser
|
||||
Audio::get()->playSound(Defaults::Sound::LASER, Audio::Group::GAME);
|
||||
}
|
||||
|
||||
void Bala::actualitzar(float delta_time) {
|
||||
if (esta_) {
|
||||
// Decrementar grace timer
|
||||
if (grace_timer_ > 0.0f) {
|
||||
grace_timer_ -= delta_time;
|
||||
if (grace_timer_ < 0.0f) {
|
||||
grace_timer_ = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
mou(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ class Bala {
|
||||
bool esta_activa() const { return esta_; }
|
||||
const Punt& get_centre() const { return centre_; }
|
||||
uint8_t get_owner_id() const { return owner_id_; }
|
||||
float get_grace_timer() const { return grace_timer_; }
|
||||
void desactivar() { esta_ = false; }
|
||||
|
||||
private:
|
||||
@@ -38,8 +39,9 @@ class Bala {
|
||||
float angle_;
|
||||
float velocitat_;
|
||||
bool esta_;
|
||||
uint8_t owner_id_; // 0=P1, 1=P2
|
||||
float brightness_; // Factor de brillantor (0.0-1.0)
|
||||
uint8_t owner_id_; // 0=P1, 1=P2
|
||||
float grace_timer_; // Grace period timer (0.0 = vulnerable)
|
||||
float brightness_; // Factor de brillantor (0.0-1.0)
|
||||
|
||||
void mou(float delta_time);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user