Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- var screen_size
- var pad_size
- var ball_speed = 80
- var direction = Vector2(-1,0)
- const 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+=direction*ball_speed*delta
- if ( (ball_pos.y<0 and direction.y <0) or (ball_pos.y>screen_size.y and direction.y>0)):
- direction.y = -direction.y
- if ( (left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
- direction.x=-direction.x
- ball_speed*=1.1
- direction.y=randf()*2.0-1
- direction = direction.normalized()
- if (ball_pos.x<0 or ball_pos.x>screen_size.x):
- ball_pos=screen_size*0.5
- ball_speed=80
- direction=Vector2(-1,0)
- get_node("ball").set_pos(ball_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement