Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys, random, math
- WIDTH, HEIGHT = 700, 980
- FPS = 120
- BG_COLOR = (10, 10, 12)
- BALL_RADIUS = 10
- BALL_COLOR = (255, 128, 0)
- BALL_SPEED = 6.0
- BUBBLE_R = 14
- BLUE = (0, 0, 255)
- PINK = (255, 0, 255)
- WHITE = (255, 255, 255)
- UI_BLUE = (20, 80, 165)
- pygame.init()
- pygame.display.set_caption("Bubble labyrinth ")
- screen = pygame.display.set_mode((WIDTH, HEIGHT))
- clock = pygame.time.Clock()
- font_big = pygame.font.SysFont('Arial', 48, bold=True)
- font_ui = pygame.font.SysFont('Arial', 24, bold=False)
- def reflect_velocity(vx,vy,nx,ny):
- dot = vx * nx + vy * ny
- rx = vx - 2 * dot * nx
- ry = vy - 2 * dot * ny
- return rx, ry
- def clamp(minv, v, maxv):
- return max(minv, min(v, maxv))
- class Ball:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- self.vx = 0
- self.vy = 0
- def launch(self):
- angle = random.uniform(-0.9, -2.3)
- self.vx = BALL_SPEED * math.cos(angle)
- self.vy = BALL_SPEED * math.sin(angle)
- def reset(self,x,y):
- self.x,self.y = float(x), float(y)
- self.vx, self.vy = 0.0
- def move(self):
- self.x += self.vx
- self.y += self.vy
- if self.x < BALL_RADIUS:
- self.x = BALL_RADIUS
- self.vx *= -1
- if self.x > WIDTH - BALL_RADIUS:
- self.x = WIDTH - BALL_RADIUS
- self.vx *= -1
- if self.y < BALL_RADIUS:
- self.y = BALL_RADIUS
- self.vy *= -1
- if self.y > HEIGHT - BALL_RADIUS:
- self.y = HEIGHT - BALL_RADIUS
- self.vy *= -1
- def draw(self, screen):
- pygame.draw.circle(screen, BALL_COLOR, (int(self.x), int(self.y)), BALL_RADIUS)
Advertisement
Add Comment
Please, Sign In to add comment