Paddle-Ball/scenes/Player.gd
HomeMadeGames Studio facc1dac5a Paddle-Ball 1.01
2024-07-16 23:00:08 -04:00

20 lines
730 B
GDScript

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)