June 2018
Beginner to intermediate
298 pages
7h 38m
English
Next, add a script to Main and start with these variables:
extends Nodevar shots = 0var statevar power = 0var power_change = 1var power_speed = 100var angle_change = 1var angle_speed = 1.1enum {SET_ANGLE, SET_POWER, SHOOT, WIN}
The enum lists the states the game can be in, while the power* and angle* variables will be used to set their respective values and change them over time. Take a look at the following code snippet:
func _ready(): $Arrow.hide() $Ball.transform.origin = $Tee.transform.origin change_state(SET_ANGLE)
At the beginning, the ball is placed at the location of the Tee using both bodies' transform.origin properties. Then, the game is put into the SET_ANGLE state:
func change_state(new_state): state = new_state match state: ...
Read now
Unlock full access