Untitled

mail@pastecode.io avatar
unknown
html
a month ago
1.2 kB
0
Indexable
Never
import pygame
import sys

# Initialize Pygame
pygame.init()

# Screen dimensions
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Cat Game")

# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)

# Load cat image
cat_image = pygame.image.load('cat.png')
cat_rect = cat_image.get_rect()
cat_rect.topleft = (WIDTH // 2, HEIGHT // 2)

# Movement speed
SPEED = 5

# Main game loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Get the set of keys pressed and check for user input
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        cat_rect.x -= SPEED
    if keys[pygame.K_RIGHT]:
        cat_rect.x += SPEED
    if keys[pygame.K_UP]:
        cat_rect.y -= SPEED
    if keys[pygame.K_DOWN]:
        cat_rect.y += SPEED

    # Fill the screen with white color
    screen.fill(WHITE)

    # Draw the cat image on the screen
    screen.blit(cat_image, cat_rect)

    # Update the display
    pygame.display.flip()

    # Cap the frame rate
    pygame.time.Clock().tick(60)

# Quit Pygame
pygame.quit()
sys.exit()
Leave a Comment