Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.6 kB
1
Indexable

```
import pygame
import random

# Initialize Pygame
pygame.init()

# Set up display variables
screen_width = 640
screen_height = 480
screen = pygame.display.set_mode((screen_width, screen_height))

# Set up title of the window
pygame.display.set_caption("Bubble Shoot")

# Define some colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)

# Set up font for text
font = pygame.font.Font(None, 36)

# Set up clock for game speed
clock = pygame.time.Clock()

# Set up bubble variables
bubble_radius = 20
bubble_color = RED
bubbles = []

# Set up player variables
player_x = screen_width / 2
player_y = screen_height - 50
player_width = 50
player_height = 50
player_speed = 5

# Game loop
while True:
    # Event handling
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    # Move player
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        player_x -= player_speed
    if keys[pygame.K_RIGHT]:
        player_x += player_speed

    # Shoot bubble
    if keys[pygame.K_SPACE]:
        bubbles.append([player_x, player_y])

    # Move bubbles
    for bubble in bubbles:
        bubble[1] -= 5
        if bubble[1] < 0:
            bubbles.remove(bubble)

    # Draw everything
    screen.fill(WHITE)
    pygame.draw.rect(screen, RED, (player_x, player_y, player_width, player_height))
    for bubble in bubbles:
        pygame.draw.circle(screen, bubble_color, bubble, bubble_radius)

    # Update display
    pygame.display.flip()

    # Cap game speed
    clock.tick(60)
```
Leave a Comment