Advertisement
jaldpsd
Apr 26th, 2024
47
0
Never
This is comment for paste GPT-4 vs Llama-3 vs Claude
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Code created by Reka Core:
  2.  
  3.  
  4. import pygame
  5. import random
  6. import time
  7.  
  8. # Initialize Pygame
  9. pygame.init()
  10.  
  11. # Game window dimensions
  12. WINDOW_WIDTH = 800
  13. WINDOW_HEIGHT = 400
  14.  
  15. # Create the game window
  16. screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
  17.  
  18. # Set the window title
  19. pygame.display.set_caption("Letter Game")
  20.  
  21. # Line movement speed
  22. LINE_SPEED = 5
  23.  
  24. # Player colors
  25. PLAYER_A_COLOR = (255, 0, 0)
  26. PLAYER_L_COLOR = (0, 0, 255)
  27.  
  28. # Game field dimensions
  29. FIELD_WIDTH = WINDOW_WIDTH
  30. FIELD_HEIGHT = WINDOW_HEIGHT // 2
  31.  
  32. # Player-controlled areas
  33. player_a_area = FIELD_WIDTH // 2
  34. player_l_area = FIELD_WIDTH // 2
  35.  
  36. # Line position
  37. line_x = WINDOW_WIDTH // 2
  38. line_y = FIELD_HEIGHT
  39.  
  40. # Line direction
  41. line_direction = random.choice([-1, 1])
  42.  
  43. # Game loop
  44. running = True
  45. while running:
  46. # Handle events
  47. for event in pygame.event.get():
  48. if event.type == pygame.QUIT:
  49. running = False
  50. elif event.type == pygame.KEYDOWN:
  51. if event.key == pygame.K_a and line_x <= FIELD_WIDTH * 3 // 4:
  52. line_x = FIELD_WIDTH * 3 // 4
  53. line_direction = 1
  54. time.sleep(random.uniform(0, 5))
  55. elif event.key == pygame.K_l and line_x >= FIELD_WIDTH // 4:
  56. line_x = FIELD_WIDTH // 4
  57. line_direction = -1
  58. time.sleep(random.uniform(0, 5))
  59.  
  60. # Move the line in a specific direction
  61. line_x += line_direction * LINE_SPEED
  62.  
  63. # Check if a player is losing ground
  64. if line_x <= FIELD_WIDTH // 4:
  65. player_l_area -= LINE_SPEED
  66. line_x = FIELD_WIDTH // 2 - player_a_area
  67. elif line_x >= FIELD_WIDTH * 3 // 4:
  68. player_a_area -= LINE_SPEED
  69. line_x = FIELD_WIDTH // 2 + player_l_area
  70.  
  71. # Update player-controlled areas
  72. player_a_area = FIELD_WIDTH // 2 - line_x
  73. player_l_area = line_x - FIELD_WIDTH // 2
  74.  
  75. # Draw the game field
  76. screen.fill((255, 255, 255))
  77. pygame.draw.line(screen, (0, 0, 0), (line_x, line_y), (line_x, WINDOW_HEIGHT), 2)
  78. pygame.draw.rect(screen, PLAYER_A_COLOR, (0, 0, player_a_area, FIELD_HEIGHT))
  79. pygame.draw.rect(screen, PLAYER_L_COLOR, (player_a_area, 0, player_l_area, FIELD_HEIGHT))
  80.  
  81. # Update the display
  82. pygame.display.flip()
  83.  
  84. # Wait for the next line movement
  85. time.sleep(0.1)
  86.  
  87. # Game over screen
  88. pygame.display.set_caption("Game Over")
  89. screen.fill((255, 255, 255))
  90. if player_a_area == 0:
  91. winner = "Player L"
  92. elif player_l_area == 0:
  93. winner = "Player A"
  94. text = pygame.font.Font(None, 36).render(f"Winner: {winner}", True, (0, 0, 0))
  95. text_rect = text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2))
  96. screen.blit(text, text_rect)
  97. pygame.display.flip()
  98. time.sleep(3)
  99.  
  100. # Quit Pygame
  101. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement