|
1 | | -use crate::components::{Asteroid, EnemyShip, Engine, Explosion, LootItem, LootType, Ship}; |
| 1 | +use crate::components::{Asteroid, Boss, EnemyShip, Engine, Explosion, LootItem, LootType, Ship}; |
2 | 2 | use crate::resources::Resources; |
3 | 3 | use macroquad::prelude::*; |
4 | 4 | use macroquad::rand::gen_range; |
@@ -206,6 +206,46 @@ pub fn draw_enemy(enemy: &EnemyShip, res: &Resources) { |
206 | 206 | ); |
207 | 207 | } |
208 | 208 |
|
| 209 | +const BOSS_SIZE: f32 = 120.0; |
| 210 | +const BOSS_HP_BAR_HEIGHT: f32 = 8.0; |
| 211 | +const BOSS_HP_BAR_GAP: f32 = 8.0; |
| 212 | + |
| 213 | +pub fn draw_boss(boss: &Boss, res: &Resources) { |
| 214 | + let size = vec2(BOSS_SIZE, BOSS_SIZE); |
| 215 | + let texture = &res.boss_1; |
| 216 | + |
| 217 | + let bar_width = size.x * 1.2; |
| 218 | + let bar_left = boss.pos.x - bar_width / 2.0; |
| 219 | + let bar_top = boss.pos.y - size.y / 2.0 - BOSS_HP_BAR_GAP - BOSS_HP_BAR_HEIGHT; |
| 220 | + |
| 221 | + draw_rectangle( |
| 222 | + bar_left, |
| 223 | + bar_top, |
| 224 | + bar_width, |
| 225 | + BOSS_HP_BAR_HEIGHT, |
| 226 | + ENEMY_HP_BAR_BG_COLOR, |
| 227 | + ); |
| 228 | + |
| 229 | + let ratio = (boss.health / boss.max_health).clamp(0.0, 1.0); |
| 230 | + let fill_width = bar_width * ratio; |
| 231 | + if fill_width > 0.0 { |
| 232 | + let hp_color = Color::new(1.0 - ratio, ratio, 0.0, 1.0); |
| 233 | + draw_rectangle(bar_left, bar_top, fill_width, BOSS_HP_BAR_HEIGHT, hp_color); |
| 234 | + } |
| 235 | + |
| 236 | + draw_texture_ex( |
| 237 | + texture, |
| 238 | + boss.pos.x - size.x / 2.0, |
| 239 | + boss.pos.y - size.y / 2.0, |
| 240 | + WHITE, |
| 241 | + DrawTextureParams { |
| 242 | + dest_size: Some(size), |
| 243 | + rotation: boss.rotation, |
| 244 | + ..Default::default() |
| 245 | + }, |
| 246 | + ); |
| 247 | +} |
| 248 | + |
209 | 249 | pub fn draw_loot(item: &LootItem, res: &Resources) { |
210 | 250 | let texture = match item.item_type { |
211 | 251 | LootType::Scrap(_) => &res.loot_scrap, |
|
0 commit comments