ball serve and reset

master
Sascha 2025-01-16 13:29:15 +07:00
parent 110c7b333e
commit 3c0ff4e31c
2 changed files with 20 additions and 1 deletions

@ -1,4 +1,20 @@
extends RigidBody2D
const SPEED = 444
var direction: Vector2
func _ready() -> void:
reset()
func reset() -> void:
print("Reset ball")
position = Vector2(578, 326)
direction = Vector2.ZERO
func serve() -> void:
print("Serve!")
print("Serve")
direction = Vector2(randf_range(-1, 1), randf_range(-1, 1)).normalized()
print(direction)
func _physics_process(delta: float) -> void:
position += direction * SPEED * delta

@ -11,5 +11,8 @@ func _input(event: InputEvent) -> void:
if game_mode == "idle":
game_mode = "play"
ball.serve()
elif game_mode == "play":
game_mode = "idle"
ball.reset()
elif event.is_action_pressed("esc"):
get_tree().quit()