Advertisement
rodrigofbm

Error2

Sep 10th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 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 _draw():
  11.     left_rect = draw_rect( Rect2( get_node("left").get_pos() - pad_size/2, pad_size ) )
  12.     right_rect = draw_rect( Rect2( get_node("right").get_pos() - pad_size/2, pad_size ) )
  13.     pass
  14.  
  15. func _ready():
  16.     update()
  17.    
  18.     screen_size = get_viewport_rect().size
  19.     pad_size = get_node("left").get_texture().get_size()
  20.     set_process(true)
  21.    
  22. func _process(delta):
  23.    
  24.     var ball_pos = get_node("ball").get_pos()
  25.     var left_rect = Rect2( get_node("left").get_pos() - pad_size/2, pad_size )
  26.     var right_rect = Rect2( get_node("right").get_pos() - pad_size/2, pad_size )
  27.    
  28.     ball_pos+=direction*ball_speed*delta
  29.    
  30.     if ( (ball_pos.y<0 and direction.y <0) or (ball_pos.y>screen_size.y and direction.y>0)):
  31.         direction.y = -direction.y
  32.     if ( (left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
  33.         direction.x=-direction.x
  34.         ball_speed*=1.1
  35.         direction.y=randf()*2.0-1
  36.         direction = direction.normalized()
  37.     if (ball_pos.x<0 or ball_pos.x>screen_size.x):
  38.         ball_pos=screen_size*0.5
  39.         ball_speed=80
  40.         direction=Vector2(-1,0)
  41.     get_node("ball").set_pos(ball_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement