Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- var screen_size
- var pad_size
- var ballspeed = 80
- var ball_direction = Vector2(-1,0)
- var PAD_SPEED = 150
- func _ready():
- screen_size = get_viewport_rect().size
- pad_size = get_node("left").get_texture().get_size()
- set_process(true)
- func _process(delta):
- var ball_pos = get_node("ball").get_pos()
- var left_rect = Rect2( get_node("left").get_pos() - pad_size/2, pad_size )
- var right_rect = Rect2( get_node("right").get_pos() - pad_size/2, pad_size )
- ball_pos += ball_direction*ballspeed*delta
- if ( (ball_pos.y < 0 and ball_direction.y < 0) or (ball_pos.y > screen_size.y and ball_direction.y > 0) ):
- ball_direction.y = - ball_direction.y
- if ( (left_rect.has_point(ball_pos) and ball_direction.x < 0) or (right_rect.has_point(ball_pos) and ball_direction.x > 0)):
- ball_direction.x=-ball_direction.x
- ballspeed*=1.1
- ball_direction.y=randf()*2.0-1
- ball_direction = ball_direction.normalized()
- if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
- ball_pos = screen_size/2
- ballspeed = 80
- ball_direction=Vector2(-1,0)
- get_node("ball").set_pos(ball_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement