feat(enemy): sistema d'HP declaratiu i nou enemic big_pentagon
This commit is contained in:
@@ -133,6 +133,9 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
invulnerability_timer_ = cfg.spawn.invulnerability_duration;
|
||||
brightness_ = cfg.spawn.invulnerability_brightness_start;
|
||||
|
||||
health_ = cfg.health;
|
||||
flash_timer_ = 0.0F;
|
||||
|
||||
is_active_ = true;
|
||||
}
|
||||
|
||||
@@ -150,6 +153,11 @@ void Enemy::update(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
if (flash_timer_ > 0.0F) {
|
||||
flash_timer_ -= delta_time;
|
||||
flash_timer_ = std::max(flash_timer_, 0.0F);
|
||||
}
|
||||
|
||||
if (invulnerability_timer_ > 0.0F) {
|
||||
invulnerability_timer_ -= delta_time;
|
||||
invulnerability_timer_ = std::max(invulnerability_timer_, 0.0F);
|
||||
@@ -192,7 +200,15 @@ void Enemy::draw() const {
|
||||
}
|
||||
}
|
||||
|
||||
Rendering::renderShape(renderer_, shape_, center_, rotation_, SCALE, 1.0F, brightness_, color);
|
||||
// Flash d'impacte parcial (HP>1): força el color a blanc i el brillo a
|
||||
// 1.0 durant la finestra de flash. Té prioritat sobre el blink wounded.
|
||||
float effective_brightness = brightness_;
|
||||
if (flash_timer_ > 0.0F) {
|
||||
color = SDL_Color{.r = 255, .g = 255, .b = 255, .a = 255};
|
||||
effective_brightness = 1.0F;
|
||||
}
|
||||
|
||||
Rendering::renderShape(renderer_, shape_, center_, rotation_, SCALE, 1.0F, effective_brightness, color);
|
||||
}
|
||||
|
||||
void Enemy::destroy() {
|
||||
@@ -203,6 +219,7 @@ void Enemy::destroy() {
|
||||
wounded_timer_ = 0.0F;
|
||||
wound_expired_this_frame_ = false;
|
||||
last_hit_by_ = 0xFF;
|
||||
flash_timer_ = 0.0F;
|
||||
}
|
||||
|
||||
void Enemy::hurt(uint8_t shooter_id) {
|
||||
|
||||
Reference in New Issue
Block a user