Szczepan86

[Godot] Soccer 3D - Main

Mar 23rd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. extends Spatial
  2.  
  3. var score1
  4. var score2
  5. export (PackedScene) var Ball
  6. var ball
  7.  
  8. func _ready():
  9. start_game()
  10.  
  11. func start_game():
  12. score1 = 0
  13. score2 = 0
  14. $Score1_1.hide()
  15. $Score1_2.hide()
  16. $Score1_3.hide()
  17. $Score2_1.hide()
  18. $Score2_2.hide()
  19. $Score2_3.hide()
  20. start_round()
  21.  
  22. func start_round():
  23. $Player1.translation = $Player1Position.translation
  24. $Player2.translation = $Player2Position.translation
  25. ball = Ball.instance()
  26. ball.translation = $BallPosition.translation
  27. add_child(ball)
  28. $GoalSprite.hide()
  29.  
  30.  
  31. func player1_score():
  32. score1 += 1
  33. print(str(score1) + " : " + str(score2))
  34. $Scores.text = str(score1) + " : " + str(score2)
  35. if score1 == 1:
  36. $Score1_1.show()
  37. if score1 == 2:
  38. $Score1_2.show()
  39. if score1 == 3:
  40. $Score1_3.show()
  41. ball.queue_free()
  42. $GoalTimer.start()
  43. $GoalSprite.show()
  44.  
  45. func player2_score():
  46. score2 += 1
  47. print(str(score1) + " : " + str(score2))
  48. $Scores.text = str(score1) + " : " + str(score2)
  49. if score2 == 1:
  50. $Score2_1.show()
  51. if score2 == 2:
  52. $Score2_2.show()
  53. if score2 == 3:
  54. $Score2_3.show()
  55. ball.queue_free()
  56. $GoalSprite.show()
  57. $GoalTimer.start()
  58.  
  59. func _on_GoalZone1_body_entered(body):
  60. if body is RigidBody:
  61. print("GOAL1!")
  62. player1_score()
  63.  
  64.  
  65. func _on_GoalZone2_body_entered(body):
  66. if body is RigidBody:
  67. print("GOAL2!")
  68. player2_score()
  69.  
  70.  
  71. func _on_GoalTimer_timeout():
  72. start_round()
Advertisement
Add Comment
Please, Sign In to add comment