Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame.locals import *
- # Initialize Pygame
- pygame.init()
- # Game Constants
- SCREEN_WIDTH = 800
- SCREEN_HEIGHT = 600
- FPS = 60
- # Colors
- WHITE = (255, 255, 255)
- BLACK = (0, 0, 0)
- RED = (255, 0, 0)
- # Set up display
- screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
- pygame.display.set_caption('Simple FPS Game')
- clock = pygame.time.Clock()
- # Player properties
- player_x = SCREEN_WIDTH // 2
- player_y = SCREEN_HEIGHT // 2
- player_speed = 5
- player_width = 20
- player_height = 20
- # Game loop
- running = True
- while running:
- screen.fill(BLACK)
- for event in pygame.event.get():
- if event.type == QUIT:
- running = False
- keys = pygame.key.get_pressed()
- if keys[K_LEFT]:
- player_x -= player_speed
- if keys[K_RIGHT]:
- player_x += player_speed
- if keys[K_UP]:
- player_y -= player_speed
- if keys[K_DOWN]:
- player_y += player_speed
- pygame.draw.rect(screen, RED, (player_x, player_y, player_width, player_height))
- pygame.display.flip()
- clock.tick(FPS)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement