Scripts
In this section, you'll create the scripts needed to make everything work together. The flow of the game will be as follows:
- Place the ball at the start (
Tee
) - Angle mode: Aim the ball
- Power mode: Set the hit power
- Launch the ball
- Repeat from step 2 until the ball is in the hole
UI
Add the following script to the UI
to update the UI elements:
extends CanvasLayer
var bar_red = preload("res://assets/bar_red.png")
var bar_green = preload("res://assets/bar_green.png")
var bar_yellow = preload("res://assets/bar_yellow.png")
func update_shots(value):
$Margin/Container/Shots.text = 'Shots: %s' % value
func update_powerbar(value):
$Margin/Container/PowerBar.texture_progress = bar_green
if value > 70:
$Margin/Container/PowerBar.texture_progress = bar_red
elif value > 40:
$Margin/Container/PowerBar.texture_progress = bar_yellow
$Margin/Container/PowerBar.value = value
The two functions provide a way to update the UI elements when they need to display a new value...