Advertisement
SkidScripts

Highly simplified version of an FPS game using Python with Pygame library

Nov 29th, 2023 (edited)
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import pygame
  2. from pygame.locals import *
  3.  
  4. # Initialize Pygame
  5. pygame.init()
  6.  
  7. # Game Constants
  8. SCREEN_WIDTH = 800
  9. SCREEN_HEIGHT = 600
  10. FPS = 60
  11.  
  12. # Colors
  13. WHITE = (255, 255, 255)
  14. BLACK = (0, 0, 0)
  15. RED = (255, 0, 0)
  16.  
  17. # Set up display
  18. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  19. pygame.display.set_caption('Simple FPS Game')
  20.  
  21. clock = pygame.time.Clock()
  22.  
  23. # Player properties
  24. player_x = SCREEN_WIDTH // 2
  25. player_y = SCREEN_HEIGHT // 2
  26. player_speed = 5
  27. player_width = 20
  28. player_height = 20
  29.  
  30. # Game loop
  31. running = True
  32. while running:
  33.     screen.fill(BLACK)
  34.  
  35.     for event in pygame.event.get():
  36.         if event.type == QUIT:
  37.             running = False
  38.  
  39.     keys = pygame.key.get_pressed()
  40.     if keys[K_LEFT]:
  41.         player_x -= player_speed
  42.     if keys[K_RIGHT]:
  43.         player_x += player_speed
  44.     if keys[K_UP]:
  45.         player_y -= player_speed
  46.     if keys[K_DOWN]:
  47.         player_y += player_speed
  48.  
  49.     pygame.draw.rect(screen, RED, (player_x, player_y, player_width, player_height))
  50.  
  51.     pygame.display.flip()
  52.     clock.tick(FPS)
  53.  
  54. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement