Paddle-Ball/scenes/Player.gd

20 lines
730 B
GDScript3
Raw Normal View History

2024-07-17 03:00:08 +00:00
extends StaticBody2D
var win_height : int
var p_height : int
# Called when the node enters the scene tree for the first time.
func _ready():
win_height = get_viewport_rect().size.y
p_height = $ColorRect.get_size().y
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_pressed("ui_up"):
position.y -= get_parent().PADDLE_SPEED * delta # get_parent() allows calls from variables from parent scripts. In this case Player is the child to Main the parent.
elif Input.is_action_pressed("ui_down"):
position.y += get_parent().PADDLE_SPEED * delta
# Limit paddle movement to the window
position.y = clamp(position.y, p_height / 2, win_height - p_height / 2)