Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
1.2 kB
1
Indexable
Never
import pygame
import sys

# Initialize Pygame
pygame.init()

# Set up display
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Animated Dog")

# Colors
white = (255, 255, 255)

# Dog properties
dog_width, dog_height = 50, 50
dog_x, dog_y = width // 2 - dog_width // 2, height // 2 - dog_height // 2
dog_speed = 5

# Main game loop
clock = pygame.time.Clock()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Move the dog (for simplicity, moves in a square pattern)
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT] and dog_x > 0:
        dog_x -= dog_speed
    if keys[pygame.K_RIGHT] and dog_x < width - dog_width:
        dog_x += dog_speed
    if keys[pygame.K_UP] and dog_y > 0:
        dog_y -= dog_speed
    if keys[pygame.K_DOWN] and dog_y < height - dog_height:
        dog_y += dog_speed

    # Draw background
    screen.fill(white)

    # Draw the dog (for simplicity, just a rectangle)
    pygame.draw.rect(screen, (150, 75, 0), (dog_x, dog_y, dog_width, dog_height))

    # Update display
    pygame.display.flip()

    # Set frames per second
    clock.tick(30)