Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.4 kB
0
Indexable
Never
import pygame
import sys
from pygame.locals import *

# Initialize Pygame
pygame.init()

# Set up the screen
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("First Person Shooter")

# Set up colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)

# Player attributes
player_pos = [400, 300]
player_speed = 5

# Bullet attributes
bullet_speed = 10
bullets = []

# Main game loop
while True:
    screen.fill(WHITE)

    # Handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == KEYDOWN:
            if event.key == K_w:
                player_pos[1] -= player_speed
            elif event.key == K_s:
                player_pos[1] += player_speed
            elif event.key == K_a:
                player_pos[0] -= player_speed
            elif event.key == K_d:
                player_pos[0] += player_speed
            elif event.key == K_SPACE:
                bullets.append(player_pos.copy())

    # Draw player
    pygame.draw.circle(screen, BLACK, player_pos, 10)

    # Draw bullets and move them
    for bullet in bullets:
        pygame.draw.circle(screen, BLACK, bullet, 5)
        bullet[0] += bullet_speed

    # Update the display
    pygame.display.update()
Leave a Comment