Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
0
Indexable
Never


```python
import pygame
import sys

# Initialize Pygame
pygame.init()

# Constants
WIDTH, HEIGHT = 800, 600
PLAYER_SIZE = 50

# Colors
WHITE = (255, 255, 255)

# Create the screen
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Multiplayer Game")

# Player variables
player1 = pygame.Rect(WIDTH // 4, HEIGHT // 2, PLAYER_SIZE, PLAYER_SIZE)
player2 = pygame.Rect(3 * WIDTH // 4, HEIGHT // 2, PLAYER_SIZE, PLAYER_SIZE)

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

    # Player movement
    keys = pygame.key.get_pressed()
    if keys[pygame.K_w]:
        player1.y -= 5
    if keys[pygame.K_s]:
        player1.y += 5
    if keys[pygame.K_UP]:
        player2.y -= 5
    if keys[pygame.K_DOWN]:
        player2.y += 5

    # Draw players
    screen.fill(WHITE)
    pygame.draw.rect(screen, (0, 0, 255), player1)
    pygame.draw.rect(screen, (255, 0, 0), player2)
    pygame.display.update()

pygame.quit()
sys.exit()
```