ateyevtm

Untitled

Oct 1st, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import pygame, sys, random, math
  2.  
  3. WIDTH, HEIGHT = 700, 980
  4. FPS = 120
  5. BG_COLOR = (10, 10, 12)
  6.  
  7. BALL_RADIUS = 10
  8. BALL_COLOR = (255, 128, 0)
  9. BALL_SPEED = 6.0
  10.  
  11. BUBBLE_R = 14
  12. BLUE = (0, 0, 255)
  13. PINK = (255, 0, 255)
  14.  
  15. WHITE = (255, 255, 255)
  16. UI_BLUE = (20, 80, 165)
  17.  
  18. pygame.init()
  19. pygame.display.set_caption("Bubble labyrinth ")
  20. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  21. clock = pygame.time.Clock()
  22. font_big = pygame.font.SysFont('Arial', 48, bold=True)
  23. font_ui = pygame.font.SysFont('Arial', 24, bold=False)
  24.  
  25. def reflect_velocity(vx,vy,nx,ny):
  26. dot = vx * nx + vy * ny
  27. rx = vx - 2 * dot * nx
  28. ry = vy - 2 * dot * ny
  29. return rx, ry
  30. def clamp(minv, v, maxv):
  31. return max(minv, min(v, maxv))
  32. class Ball:
  33. def __init__(self, x, y):
  34. self.x = x
  35. self.y = y
  36. self.vx = 0
  37. self.vy = 0
  38. def launch(self):
  39. angle = random.uniform(-0.9, -2.3)
  40. self.vx = BALL_SPEED * math.cos(angle)
  41. self.vy = BALL_SPEED * math.sin(angle)
  42. def reset(self,x,y):
  43. self.x,self.y = float(x), float(y)
  44. self.vx, self.vy = 0.0
  45. def move(self):
  46. self.x += self.vx
  47. self.y += self.vy
  48.  
  49. if self.x < BALL_RADIUS:
  50. self.x = BALL_RADIUS
  51. self.vx *= -1
  52. if self.x > WIDTH - BALL_RADIUS:
  53. self.x = WIDTH - BALL_RADIUS
  54. self.vx *= -1
  55. if self.y < BALL_RADIUS:
  56. self.y = BALL_RADIUS
  57. self.vy *= -1
  58. if self.y > HEIGHT - BALL_RADIUS:
  59. self.y = HEIGHT - BALL_RADIUS
  60. self.vy *= -1
  61. def draw(self, screen):
  62. pygame.draw.circle(screen, BALL_COLOR, (int(self.x), int(self.y)), BALL_RADIUS)
  63.  
Advertisement
Add Comment
Please, Sign In to add comment