✨ Reload & HUD
This commit is contained in:
		
							
								
								
									
										40
									
								
								Scripts/UI/HUD.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Scripts/UI/HUD.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
using AceField.Scripts.Logic;
 | 
			
		||||
using Godot;
 | 
			
		||||
 | 
			
		||||
namespace AceField.Scripts.UI;
 | 
			
		||||
 | 
			
		||||
public partial class HUD : Control
 | 
			
		||||
{
 | 
			
		||||
	[Export] public World World;
 | 
			
		||||
 | 
			
		||||
	private void ApplySize()
 | 
			
		||||
	{
 | 
			
		||||
		var screenSize = GetViewportRect().Size;
 | 
			
		||||
 | 
			
		||||
		Position = new Vector2(0, 0);
 | 
			
		||||
		Size = screenSize;
 | 
			
		||||
		GetNode<HBoxContainer>("TopBox").Size = new Vector2(screenSize.X-16*2, 16);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override void _Process(double delta)
 | 
			
		||||
	{
 | 
			
		||||
		var player = World.GetCurrentPlayer();
 | 
			
		||||
		if (player == null) return;
 | 
			
		||||
		
 | 
			
		||||
		var healthBar = GetNode<ProgressBar>("TopBox/HealthBox/Bar");
 | 
			
		||||
		var healthLabel = GetNode<Label>("TopBox/HealthBox/Label");
 | 
			
		||||
		healthBar.Value = player.Health / player.MaxHealth * 100;
 | 
			
		||||
		healthLabel.Text = $"Health {player.Health}/{player.MaxHealth}";
 | 
			
		||||
		
 | 
			
		||||
		var actionBar = GetNode<ProgressBar>("TopBox/ActionPointBox/Bar");
 | 
			
		||||
		var actionLabel = GetNode<Label>("TopBox/ActionPointBox/Label");
 | 
			
		||||
		actionBar.Value = player.ActionPoints / player.MaxActionPoints * 100;
 | 
			
		||||
		actionLabel.Text = $"AP {player.ActionPoints}/{player.MaxActionPoints}";
 | 
			
		||||
		
 | 
			
		||||
		var ammoBar = GetNode<ProgressBar>("TopBox/AmmoBox/Bar");
 | 
			
		||||
		var ammoLabel = GetNode<Label>("TopBox/AmmoBox/Label");
 | 
			
		||||
		ammoBar.Value = player.AmmoAmount / player.MaxAmmoAmount * 100;
 | 
			
		||||
		if (player.IsReloading) ammoLabel.Text = $"Reloading... {player.TimeRemainingOfReload:F2}";
 | 
			
		||||
		else ammoLabel.Text = $"Ammo {player.AmmoAmount}/{player.MaxAmmoAmount}";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user