Fries
f84479e03a
i added a main menu scene and a score system that is written in GDScript instead of C# for a change. the WallManager, the thing that detects collisions, calls the score method on the ScoreManager.
34 lines
941 B
GDScript
34 lines
941 B
GDScript
extends HFlowContainer
|
|
|
|
var PlayerOneScore: int
|
|
var PlayerTwoScore: int
|
|
|
|
var PlayerOneLabel: Label
|
|
var PlayerTwoLabel: Label
|
|
|
|
enum {PlayerOne, PlayerTwo}
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
PlayerOneLabel = get_node("Player1")
|
|
PlayerTwoLabel = get_node("Player2")
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(_delta):
|
|
pass
|
|
|
|
## when the ball collides with the wall, this method is called by the WallManager
|
|
func score(player_number: int):
|
|
if player_number == PlayerOne:
|
|
PlayerOneScore += 1
|
|
update_label(player_number)
|
|
elif player_number == PlayerTwo:
|
|
PlayerTwoScore += 1
|
|
update_label(player_number)
|
|
|
|
## this method takes care of updating labels
|
|
func update_label(player_number: int):
|
|
if player_number == PlayerOne:
|
|
PlayerOneLabel.text = str(PlayerOneScore)
|
|
elif player_number == PlayerTwo:
|
|
PlayerTwoLabel.text = str(PlayerTwoScore)
|