Advertisement
rodrigofbm

Error

Sep 10th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. extends Node2D
  2.  
  3. var screen_size
  4. var pad_size
  5.  
  6. var ball_speed = 80
  7. var direction = Vector2(-1,0)
  8. const PAD_SPEED = 150
  9.  
  10. func _ready():
  11.     screen_size = get_viewport_rect().size
  12.     pad_size = get_node("left").get_texture().get_size()
  13.     set_process(true)
  14. func _process(delta):
  15.     var ball_pos = get_node("ball").get_pos()
  16.     var left_rect = Rect2( get_node("left").get_pos() - pad_size/2, pad_size )
  17.     var right_rect = Rect2( get_node("right").get_pos() - pad_size/2, pad_size )
  18.     ball_pos+=direction*ball_speed*delta
  19.    
  20.     if ( (ball_pos.y<0 and direction.y <0) or (ball_pos.y>screen_size.y and direction.y>0)):
  21.         direction.y = -direction.y
  22.     if ( (left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
  23.         direction.x=-direction.x
  24.         ball_speed*=1.1
  25.         direction.y=randf()*2.0-1
  26.         direction = direction.normalized()
  27.     if (ball_pos.x<0 or ball_pos.x>screen_size.x):
  28.         ball_pos=screen_size*0.5
  29.         ball_speed=80
  30.         direction=Vector2(-1,0)
  31.     get_node("ball").set_pos(ball_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement