02-19-2021, 08:25 AM
(This post was last modified: 02-20-2021, 04:16 AM by DerVVulfman.
Edit Reason: Added IMG code for Metal's image attachments
)
Today's challenge! GUI!
So I have set up the GUI visuals in the editor. You can see the attached file for what it looks like.
GUI.png (Size: 53.91 KB / Downloads: 16)
Now I have to make it update when the player does stuff.
I have variables for current HP (Hull Points), SP (Shield Points) and fuel for the booster.
First, I set up the bars and their labels to match the player's current stat levels. This part happens inside my 'interface' node which is a 'control' node.
I'm not a fan of using absolute paths (I've read it's very easy to break, for example if you change something in one of the folders) so in the future I'm going to look for a way to make it more flexible. For now though, it works. You can see in the picture, it writes how many HP/SP the player has (6 and 6 for now), and the bars are full.
So, this part checks the player's CURRENT HP and SP, then sets the VALUE of the bars and their labels. It also updates the player's money display. Sorry, it's not very well aligned right now but it will be in the final version.
I haven't set this up for the fuel yet, but it works for the HP and SP! Check the 2nd attached image for the visuals.
GUI2.png (Size: 51.65 KB / Downloads: 17)
Oh and I made it check to see if the player has shield and if so, to take away from that before their HP.
Having so much fun doing this!
So I have set up the GUI visuals in the editor. You can see the attached file for what it looks like.
GUI.png (Size: 53.91 KB / Downloads: 16)
Now I have to make it update when the player does stuff.
I have variables for current HP (Hull Points), SP (Shield Points) and fuel for the booster.
First, I set up the bars and their labels to match the player's current stat levels. This part happens inside my 'interface' node which is a 'control' node.
Code:
extends Control
var hp
var sp
var fuel
# get and set stats from GlobalPlayer and bar ranges, reset player
func _ready():
hp = GlobalPlayer.stats.hull[GlobalPlayer.hp_lvl]
GlobalPlayer.cur_hp = hp
sp = GlobalPlayer.stats.shield[GlobalPlayer.shield_lvl]
GlobalPlayer.cur_sp = sp
fuel = GlobalPlayer.stats.fuel[GlobalPlayer.fuel_lvl]
GlobalPlayer.cur_fuel = fuel
$MCon/VBCon/HBoxContainer/HBar/HBarCon/HullBar.max_value = hp
$MCon/VBCon/SBar/SBarCon/ShieldBar.max_value = sp
$MCon/VBCon/BBar/BBarContainer/BoostBar.max_value = fuel
I'm not a fan of using absolute paths (I've read it's very easy to break, for example if you change something in one of the folders) so in the future I'm going to look for a way to make it more flexible. For now though, it works. You can see in the picture, it writes how many HP/SP the player has (6 and 6 for now), and the bars are full.
Code:
# Change value of the bars and labels based on current stats
func _process(delta):
# label changes
$MCon/VBCon/HBoxContainer/HBar/Counter/MCon/Label.text = str(GlobalPlayer.cur_hp)
$MCon/VBCon/SBar/Counter/MCon/Label.text = str(GlobalPlayer.cur_sp)
$MCon/VBCon/HBoxContainer/MoneyUI/Counter/Split/MoneyLabel.text = str(GlobalPlayer.money)
# bar progression
$MCon/VBCon/SBar/SBarCon/ShieldBar.value = GlobalPlayer.cur_sp
$MCon/VBCon/HBoxContainer/HBar/HBarCon/HullBar.value = GlobalPlayer.cur_hp
So, this part checks the player's CURRENT HP and SP, then sets the VALUE of the bars and their labels. It also updates the player's money display. Sorry, it's not very well aligned right now but it will be in the final version.
I haven't set this up for the fuel yet, but it works for the HP and SP! Check the 2nd attached image for the visuals.
GUI2.png (Size: 51.65 KB / Downloads: 17)
Oh and I made it check to see if the player has shield and if so, to take away from that before their HP.
Having so much fun doing this!