|
|
|
@ -5,6 +5,7 @@ extends Node2D
|
|
|
|
@onready var ball: RigidBody2D = $Ball
|
|
|
|
@onready var ball: RigidBody2D = $Ball
|
|
|
|
@onready var player_1_score: Label = %Player1Score
|
|
|
|
@onready var player_1_score: Label = %Player1Score
|
|
|
|
@onready var player_2_score: Label = %Player2Score
|
|
|
|
@onready var player_2_score: Label = %Player2Score
|
|
|
|
|
|
|
|
@onready var game_text: Label = %GameText
|
|
|
|
|
|
|
|
|
|
|
|
var points: Vector2i
|
|
|
|
var points: Vector2i
|
|
|
|
|
|
|
|
|
|
|
|
@ -17,6 +18,7 @@ func _input(event: InputEvent) -> void:
|
|
|
|
if event.is_action_pressed("space"):
|
|
|
|
if event.is_action_pressed("space"):
|
|
|
|
if game_mode == "idle":
|
|
|
|
if game_mode == "idle":
|
|
|
|
game_mode = "play"
|
|
|
|
game_mode = "play"
|
|
|
|
|
|
|
|
game_text.visible = false
|
|
|
|
ball.serve()
|
|
|
|
ball.serve()
|
|
|
|
elif game_mode == "play":
|
|
|
|
elif game_mode == "play":
|
|
|
|
game_mode = "idle"
|
|
|
|
game_mode = "idle"
|
|
|
|
@ -28,7 +30,6 @@ func _on_ball_body_entered(body: Node) -> void:
|
|
|
|
print("ball hits " + str(body.name))
|
|
|
|
print("ball hits " + str(body.name))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_game_over(winning_player: int) -> void:
|
|
|
|
func _on_game_over(winning_player: int) -> void:
|
|
|
|
print("Game Over! Winning Player: " + str(winning_player))
|
|
|
|
|
|
|
|
if winning_player == 1:
|
|
|
|
if winning_player == 1:
|
|
|
|
points.x += 1
|
|
|
|
points.x += 1
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
@ -36,3 +37,13 @@ func _on_game_over(winning_player: int) -> void:
|
|
|
|
player_1_score.text = str(points.x)
|
|
|
|
player_1_score.text = str(points.x)
|
|
|
|
player_2_score.text = str(points.y)
|
|
|
|
player_2_score.text = str(points.y)
|
|
|
|
game_mode = "idle"
|
|
|
|
game_mode = "idle"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if points.x >= 10:
|
|
|
|
|
|
|
|
game_over(1)
|
|
|
|
|
|
|
|
elif points.y >= 10:
|
|
|
|
|
|
|
|
game_over(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func game_over(player_wins: int) -> void:
|
|
|
|
|
|
|
|
game_mode = "game_over"
|
|
|
|
|
|
|
|
game_text.text = "Game Over! Winning Player: " + str(player_wins)
|
|
|
|
|
|
|
|
game_text.visible = true
|
|
|
|
|