Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Spatial
- var score1
- var score2
- export (PackedScene) var Ball
- var ball
- func _ready():
- start_game()
- func start_game():
- score1 = 0
- score2 = 0
- $Score1_1.hide()
- $Score1_2.hide()
- $Score1_3.hide()
- $Score2_1.hide()
- $Score2_2.hide()
- $Score2_3.hide()
- start_round()
- func start_round():
- $Player1.translation = $Player1Position.translation
- $Player2.translation = $Player2Position.translation
- ball = Ball.instance()
- ball.translation = $BallPosition.translation
- add_child(ball)
- $GoalSprite.hide()
- func player1_score():
- score1 += 1
- print(str(score1) + " : " + str(score2))
- $Scores.text = str(score1) + " : " + str(score2)
- if score1 == 1:
- $Score1_1.show()
- if score1 == 2:
- $Score1_2.show()
- if score1 == 3:
- $Score1_3.show()
- ball.queue_free()
- $GoalTimer.start()
- $GoalSprite.show()
- func player2_score():
- score2 += 1
- print(str(score1) + " : " + str(score2))
- $Scores.text = str(score1) + " : " + str(score2)
- if score2 == 1:
- $Score2_1.show()
- if score2 == 2:
- $Score2_2.show()
- if score2 == 3:
- $Score2_3.show()
- ball.queue_free()
- $GoalSprite.show()
- $GoalTimer.start()
- func _on_GoalZone1_body_entered(body):
- if body is RigidBody:
- print("GOAL1!")
- player1_score()
- func _on_GoalZone2_body_entered(body):
- if body is RigidBody:
- print("GOAL2!")
- player2_score()
- func _on_GoalTimer_timeout():
- start_round()
Advertisement
Add Comment
Please, Sign In to add comment