Advertisement
jaldpsd
Aug 15th, 2024
39
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. Grok 2 Mini:
  2. import pygame
  3. import random
  4.  
  5. # Initialize Pygame
  6. pygame.init()
  7.  
  8. # Constants
  9. SCREEN_WIDTH = 800
  10. SCREEN_HEIGHT = 600
  11. LINE_WIDTH = 10
  12. FPS = 60
  13.  
  14. # Colors
  15. WHITE = (255, 255, 255)
  16. BLACK = (0, 0, 0)
  17. RED = (255, 0, 0)
  18. GREEN = (0, 255, 0)
  19.  
  20. # Setup
  21. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  22. pygame.display.set_caption("L vs A Game")
  23. clock = pygame.time.Clock()
  24.  
  25. # Game variables
  26. line_position = SCREEN_WIDTH // 2
  27. line_speed = 10
  28. line_direction = 1 # 1 for right, -1 for left
  29. game_over = False
  30. button_pressed = False
  31.  
  32. # Player controls
  33. A_KEY = pygame.K_a
  34. L_KEY = pygame.K_l
  35.  
  36. def move_line():
  37. global line_position, line_direction
  38. if not button_pressed:
  39. line_position += line_speed * line_direction
  40. if line_position <= 0 or line_position >= SCREEN_WIDTH:
  41. line_direction *= -1
  42. line_position += line_speed * line_direction
  43.  
  44. def check_game_over():
  45. global game_over
  46. if line_position <= 0 or line_position >= SCREEN_WIDTH:
  47. game_over = True
  48.  
  49. def draw_game():
  50. screen.fill(BLACK)
  51. pygame.draw.line(screen, WHITE, (line_position, 0), (line_position, SCREEN_HEIGHT), LINE_WIDTH)
  52. pygame.draw.rect(screen, RED if line_direction == 1 else GREEN, (0, 0, line_position, SCREEN_HEIGHT), 0)
  53. pygame.draw.rect(screen, GREEN if line_direction == 1 else RED, (line_position, 0, SCREEN_WIDTH - line_position, SCREEN_HEIGHT), 0)
  54.  
  55. if game_over:
  56. font = pygame.font.Font(None, 74)
  57. text = font.render("Game Over!", True, WHITE)
  58. text_rect = text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
  59. screen.blit(text, text_rect)
  60.  
  61. pygame.display.flip()
  62.  
  63. # Main game loop
  64. running = True
  65. while running:
  66. for event in pygame.event.get():
  67. if event.type == pygame.QUIT:
  68. running = False
  69. elif event.type == pygame.KEYDOWN:
  70. if event.key == A_KEY and line_direction == -1:
  71. button_pressed = True
  72. elif event.key == L_KEY and line_direction == 1:
  73. button_pressed = True
  74. elif event.type == pygame.KEYUP:
  75. if event.key in [A_KEY, L_KEY]:
  76. button_pressed = False
  77.  
  78. if not game_over:
  79. move_line()
  80. check_game_over()
  81.  
  82. draw_game()
  83. clock.tick(FPS)
  84.  
  85. pygame.quit()
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement