godot-demo-projects/2d/pong/paddle.gd

21 lines
534 B
GDScript3
Raw Normal View History

extends Area2D
export var ball_dir=1
const MOVE_SPEED=100
func _process(delta):
var which = get_name()
# move up and down based on input
if (Input.is_action_pressed(which+"_move_up") and position.y > 0):
position.y -= MOVE_SPEED * delta
2017-07-01 12:29:03 +02:00
if (Input.is_action_pressed(which+"_move_down") and position.y < get_viewport_rect().size.y):
position.y += MOVE_SPEED * delta
func _on_area_entered( area ):
if area.get_name() == "ball":
# assign new direction
area.direction = Vector2(ball_dir,randf() * 2 - 1).normalized()