Skip to content

Commit 741029e

Browse files
committed
Updated status bar
1 parent f3a7c55 commit 741029e

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

assets/shader/status_bar.wgsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const RANGE = 0.75;
44
const COLOR_VOID = vec4<f32>(0.0, 0.0, 0.0, 0.333333);
5+
const COLOR_STAMINA = vec4<f32>(0.8, 0.8, 0.8, 0.4);
56
const COLOR_HEALTH = vec4<f32>(1.0, 0.0, 0.0, 0.6);
67
const COLOR_AMMO = vec4<f32>(0.8, 0.8, 0.8, 0.4);
78

@@ -10,6 +11,7 @@ struct Uniform {
1011
health_alpha: f32,
1112
ammo: f32,
1213
ammo_alpha: f32,
14+
stamina: f32,
1315
};
1416

1517
@group(1) @binding(0)
@@ -75,8 +77,9 @@ fn bar(value: f32, center: vec2<f32>, color: vec4<f32>, radius: f32, thickness:
7577
fn fragment(
7678
#import bevy_sprite::mesh2d_vertex_output
7779
) -> @location(0) vec4<f32> {
78-
var center = uv.xy - 0.5;
79-
var health = bar(uniform.health, center, mix_alpha(COLOR_HEALTH, uniform.health_alpha), 0.85, 0.05);
80-
var ammo = bar(uniform.ammo , center, mix_alpha(COLOR_AMMO , uniform.ammo_alpha ), 1.00, 0.03);
81-
return vec4<f32>(health + ammo);
80+
var center = uv.xy - 0.5;
81+
var stamina = bar(uniform.stamina, center, mix_alpha(COLOR_STAMINA, 1.0 ), 0.62, 0.01);
82+
var health = bar(uniform.health , center, mix_alpha(COLOR_HEALTH , uniform.health_alpha), 0.91, 0.06);
83+
var ammo = bar(uniform.ammo , center, mix_alpha(COLOR_AMMO , uniform.ammo_alpha ), 1.00, 0.01);
84+
return vec4<f32>(stamina + health + ammo);
8285
}

src/command/status_bar_set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl Command for StatusBarSet {
2929
health_alpha: 0.0,
3030
ammo: 1.0,
3131
ammo_alpha: 0.0,
32+
stamina: 0.0,
3233
image,
3334
});
3435

src/material/status_bar.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct StatusBarMaterial {
1616
pub ammo: f32,
1717
#[uniform(0)]
1818
pub ammo_alpha: f32,
19+
#[uniform(0)]
20+
pub stamina: f32,
1921
#[texture(1)]
2022
#[sampler(2)]
2123
pub image: Handle<Image>,

src/system/game/status_bar.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
component::{Health, Weapon},
2+
component::{Actor, Health, Weapon},
33
StatusBarMaterial,
44
};
55
use bevy::{
@@ -13,15 +13,15 @@ const INTERPOLATION: f32 = 8.0;
1313
const PULSE: Duration = Duration::from_millis(500);
1414

1515
pub fn status_bar(
16-
targets: Query<(&Health, Option<&Weapon>, &Children)>, // TODO: try to simplify
16+
targets: Query<(&Actor, &Health, Option<&Weapon>, &Children)>, // TODO: try to simplify
1717
handles: Query<&Handle<StatusBarMaterial>>,
1818
mut assets: ResMut<Assets<StatusBarMaterial>>,
1919
time: Res<Time>,
2020
) {
2121
let pulse = (time.elapsed_seconds() * TAU / PULSE.as_secs_f32()).cos() / 2.0 + 0.5;
2222
let interpolation = f32::min(INTERPOLATION * time.delta().as_secs_f32(), 1.0);
2323

24-
for (health, weapon, children) in targets.iter() {
24+
for (actor, health, weapon, children) in targets.iter() {
2525
for child in children.iter() {
2626
if let Some(material) = handles.get(*child).ok().and_then(|h| assets.get_mut(h)) {
2727
material.health -= (material.health - health.get()) * interpolation;
@@ -43,6 +43,8 @@ pub fn status_bar(
4343
} else {
4444
material.ammo_alpha = 0.0;
4545
}
46+
47+
material.stamina = actor.stamina;
4648
}
4749
}
4850
}

0 commit comments

Comments
 (0)