Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Learning GDScript
#6
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.

[Image: attachment.php?aid=1499]

.png   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.

[Image: attachment.php?aid=1500]

.png   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!
Reply }


Messages In This Thread
Learning GDScript - by MetalRenard - 02-09-2021, 08:55 AM
RE: Learning GDScript - by MetalRenard - 02-09-2021, 10:45 AM
RE: Learning GDScript - by kyonides - 02-10-2021, 05:55 AM
RE: Learning GDScript - by MetalRenard - 02-10-2021, 04:16 PM
RE: Learning GDScript - by MetalRenard - 02-14-2021, 04:24 PM
RE: Learning GDScript - by MetalRenard - 02-19-2021, 08:25 AM
RE: Learning GDScript - by MetalRenard - 02-23-2021, 10:40 AM
RE: Learning GDScript - by MetalRenard - 03-03-2021, 12:54 PM



Users browsing this thread: