|
|
|
|
@ -7,39 +7,39 @@ extends Node2D
|
|
|
|
|
@onready var player_2_score: Label = %Player2Score
|
|
|
|
|
@onready var game_text: Label = %GameText
|
|
|
|
|
|
|
|
|
|
var points: Vector2i = Vector2i(0, 0)
|
|
|
|
|
var game_mode = "idle"
|
|
|
|
|
var points := Vector2i(0, 0)
|
|
|
|
|
var game_mode := "idle"
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
ball.connect("game_over", Callable(self, "_on_game_over"))
|
|
|
|
|
ball.connect("game_over", Callable(self, "_on_game_over"))
|
|
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
|
|
|
if event.is_action_pressed("space"):
|
|
|
|
|
if game_mode == "idle":
|
|
|
|
|
game_mode = "play"
|
|
|
|
|
game_text.visible = false
|
|
|
|
|
ball.serve()
|
|
|
|
|
elif game_mode == "play":
|
|
|
|
|
game_mode = "idle"
|
|
|
|
|
ball.reset()
|
|
|
|
|
elif event.is_action_pressed("esc"):
|
|
|
|
|
get_tree().quit()
|
|
|
|
|
if event.is_action_pressed("space"):
|
|
|
|
|
if game_mode == "idle":
|
|
|
|
|
game_mode = "play"
|
|
|
|
|
game_text.visible = false
|
|
|
|
|
ball.serve()
|
|
|
|
|
elif game_mode == "play":
|
|
|
|
|
game_mode = "idle"
|
|
|
|
|
ball.reset()
|
|
|
|
|
elif event.is_action_pressed("esc"):
|
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
func _on_game_over(winning_player: int) -> void:
|
|
|
|
|
if winning_player == 1:
|
|
|
|
|
points.x += 1
|
|
|
|
|
else:
|
|
|
|
|
points.y += 1
|
|
|
|
|
player_1_score.text = str(points.x)
|
|
|
|
|
player_2_score.text = str(points.y)
|
|
|
|
|
game_mode = "idle"
|
|
|
|
|
if winning_player == 1:
|
|
|
|
|
points.x += 1
|
|
|
|
|
else:
|
|
|
|
|
points.y += 1
|
|
|
|
|
player_1_score.text = str(points.x)
|
|
|
|
|
player_2_score.text = str(points.y)
|
|
|
|
|
game_mode = "idle"
|
|
|
|
|
|
|
|
|
|
if points.x >= 10:
|
|
|
|
|
_game_over(1)
|
|
|
|
|
elif points.y >= 10:
|
|
|
|
|
_game_over(2)
|
|
|
|
|
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
|
|
|
|
|
game_mode = "game_over"
|
|
|
|
|
game_text.text = "Game Over! Winning Player: " + str(player_wins)
|
|
|
|
|
game_text.visible = true
|
|
|
|
|
|