diff --git a/Paddle.gd b/Paddle.gd index 0b8ae66..36278d7 100644 --- a/Paddle.gd +++ b/Paddle.gd @@ -5,13 +5,13 @@ const SPEED: float = 350.0 @export var player_id: int func _input(event: InputEvent) -> void: - if event.is_action_pressed('up-%d' % player_id): - velocity = Vector2(0, -SPEED) - if event.is_action_pressed( 'down-%d' % player_id): - velocity = Vector2(0, SPEED) - if event.is_action_released('up-%d' % player_id) or \ - event.is_action_released('down-%d' % player_id): - velocity = Vector2.ZERO + if event.is_action_pressed('up-%d' % player_id): + velocity = Vector2(0, -SPEED) + if event.is_action_pressed( 'down-%d' % player_id): + velocity = Vector2(0, SPEED) + if event.is_action_released('up-%d' % player_id) or \ + event.is_action_released('down-%d' % player_id): + velocity = Vector2.ZERO func _physics_process(_delta: float) -> void: - move_and_slide() + move_and_slide() diff --git a/ball.gd b/ball.gd index 82214d1..b55b7c9 100644 --- a/ball.gd +++ b/ball.gd @@ -3,19 +3,19 @@ extends CharacterBody2D const SPEED : float = 300.0 func _ready() -> void: - initialize() + initialize() - func _physics_process(delta: float) -> void: - var collision = move_and_collide(velocity * _delta) - if collision: - velocity = velocity.bounce(collision.get_normal()) + func _physics_process(delta: float) -> void: + var collision = move_and_collide(velocity * _delta) + if collision: + velocity = velocity.bounce(collision.get_normal()) 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() * SPEED - position = get_viewport_rect().size / 2.0 + 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() * SPEED + position = get_viewport_rect().size / 2.0 func _on_screen_exited() -> void: - await get_tree().create_timer(1.0).timeout - initialize() + await get_tree().create_timer(1.0).timeout + initialize()