Pong/ball.gd
2025-08-24 13:39:07 +01:00

23 lines
522 B
GDScript

extends CharacterBody2D
const SPEED : float = 300.0
func _ready() -> void:
initialize()
func _physics_process(delta: float) -> void:
move_and_slide()
func initialize():
var extra_offset = 0.0 if randf() < 0.5 else PI
var angle = \
extra_offset + randf_range(-PI/3.0, PI/3.0)
velocity = Vector2(cos(angle), sin(angle)).normalized()
position = get_viewport_rect().size / 2.0
func _on_screen_exited() -> void:
# update score
# reinit after 1 second
await get_tree().create_timer (1.0).timeout
initialize()