Skip to content

Commit

Permalink
fix: healthbar size/dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeder committed May 24, 2023
1 parent a4881d7 commit ad7493e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "turtle_time"
version = "0.7.2"
version = "0.7.3"
publish = false
authors = ["Mike Eder <[email protected]>"] # ToDo: you are the author
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
.build(&mut app);

app.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4)))
.insert_resource(ClearColor(Color::rgb(0.0, 0.3, 0.0)))
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
Expand Down
8 changes: 7 additions & 1 deletion src/player/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ pub fn add_player_health_bars(

commands.entity(health_entity).with_children(|cb| {
cb.spawn(SpriteBundle {
// black background
sprite: Sprite {
color: Color::BLACK,
custom_size: Some(Vec2::new(PLAYER_HEALTH_MAX as f32, TILE_SIZE / 4.)),
Expand All @@ -915,9 +916,10 @@ pub fn add_player_health_bars(
.with_children(|parent| {
parent
.spawn(SpriteBundle {
// red overlay
sprite: Sprite {
color: Color::RED,
custom_size: Some(Vec2::new(PLAYER_HEALTH_MAX as f32, TILE_SIZE / 4.)),
custom_size: Some(Vec2::new(PLAYER_HEALTH_MAX as f32, TILE_SIZE / 8.)),
..default()
},
transform: Transform::from_xyz(0., 0., 0.2),
Expand All @@ -940,6 +942,10 @@ pub fn update_health_bars(
for (_, health_bar, mut transform) in bars {
let player_health = health_entities.get(health_bar.health_entity).unwrap();
let health_percent = player_health.decimal();
let h = PLAYER_HEALTH_MAX as f32 * 0.5;
let x_offset = h - h * health_percent;

transform.scale = vec3(health_percent as f32, 1.0, 1.0);
transform.translation = vec3(-x_offset, 0., 0.2)
}
}

0 comments on commit ad7493e

Please sign in to comment.