Guest User

Untitled

a guest
Aug 20th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. extends Node2D
  2.  
  3. var screen_size
  4. var pad_size
  5. var direction = Vector2(1.0 , 0.0)
  6.  
  7. const INITIAL_BALL_SPEED = 80
  8. var ball_speed = INITIAL_BALL_SPEED
  9. const PAD_SPEED = 150
  10.  
  11. func _ready():
  12. screen_size = get_viewport_rect().size
  13. pad_size = get_node('LPallete').get_texture().get_size()
  14.  
  15. func _process(delta):
  16. var ball_pos = get_node("Ball").position
  17. var left_rect = Rect2( get_node("LPallete").position - pad_size*0.5, pad_size )
  18. var right_rect = Rect2( get_node("RPallete").position - pad_size*0.5, pad_size )
  19. ball_pos += direction * ball_speed * delta
  20. if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)): direction.y = -direction.y
  21.  
  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. direction.y = randf()*2.0 - 1
  25. direction = direction.normalized()
  26. ball_speed *= 1.1
  27. if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
  28. ball_pos = screen_size*0.5
  29. ball_speed = INITIAL_BALL_SPEED
  30. direction = Vector2(-1, 0)
  31. get_node("Ball").position = ball_pos
  32.  
  33.  
  34. #PAD Movement
  35. var left_pos = get_node("LPallete").position
  36.  
  37. if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
  38. left_pos.y += -PAD_SPEED * delta
  39. if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
  40. left_pos.y += PAD_SPEED * delta
  41.  
  42. get_node("LPallete").position = left_pos
  43.  
  44. var right_pos = get_node("RPallete").position
  45.  
  46. if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
  47. right_pos.y += -PAD_SPEED * delta
  48. if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
  49. right_pos.y += PAD_SPEED * delta
  50.  
  51. get_node("RPallete").position = right_pos
  52.  
Advertisement
Add Comment
Please, Sign In to add comment