Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =================================
- Code Generated by GPT-4:
- =================================
- import pygame
- import random
- import time
- pygame.init()
- width, height = 800, 600
- screen = pygame.display.set_mode((width, height))
- clock = pygame.time.Clock()
- # Initial position of the line
- line_x = width // 2
- def move_line():
- global line_x
- move_rate = random.choice([-5, 5]) # Line moves left or right randomly
- while 0 < line_x < width:
- line_x += move_rate
- yield
- if line_x <= 0 or line_x >= width:
- break
- # Main game loop
- running = True
- line_movement = move_line()
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_a and move_rate > 0: # Player A stops the line moving left
- line_movement = move_line()
- elif event.key == pygame.K_l and move_rate < 0: # Player L stops the line moving right
- line_movement = move_line()
- next(line_movement, None) # Move the line
- screen.fill((0, 0, 0))
- pygame.draw.line(screen, (255, 255, 255), (line_x, 0), (line_x, height))
- pygame.display.flip()
- clock.tick(60)
- pygame.quit()
- =================================
- Code Generated by LlaMA-3:
- =================================
- import pygame
- import random
- import time
- # Initialize Pygame
- pygame.init()
- # Set up the game window dimensions
- WINDOW_WIDTH = 800
- WINDOW_HEIGHT = 600
- screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
- # Set up the title of the window
- pygame.display.set_caption("Territory Tussle")
- # Define some colors
- WHITE = (255, 255, 255)
- BLACK = (0, 0, 0)
- RED = (255, 0, 0)
- GREEN = (0, 255, 0)
- # Set up the game variables
- player_A_territory = 50
- player_L_territory = 50
- line_x = WINDOW_WIDTH / 2
- line_speed = 2
- player_A_score = 0
- player_L_score = 0
- moving_right = True
- game_over = False
- # Set up the game clock
- clock = pygame.time.Clock()
- # Game loop
- while True:
- # Event handling
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_a:
- if not moving_right:
- moving_right = True
- line_speed = 2
- elif event.key == pygame.K_l:
- if moving_right:
- moving_right = False
- line_speed = 2
- elif event.type == pygame.KEYUP:
- line_speed = 2
- # Move the line
- if moving_right:
- line_x += line_speed
- else:
- line_x -= line_speed
- # Check for boundary collisions
- if line_x <= 0:
- line_x = 0
- elif line_x >= WINDOW_WIDTH:
- line_x = WINDOW_WIDTH
- # Update the game state
- if player_A_territory <= 0 or player_L_territory <= 0:
- game_over = True
- elif player_A_territory >= 100 or player_L_territory >= 100:
- game_over = True
- # Draw everything
- screen.fill(WHITE)
- pygame.draw.line(screen, BLACK, (line_x, 0), (line_x, WINDOW_HEIGHT), 2)
- pygame.draw.rect(screen, RED, (0, 0, line_x, WINDOW_HEIGHT))
- pygame.draw.rect(screen, GREEN, (line_x, 0, WINDOW_WIDTH - line_x, WINDOW_HEIGHT))
- # Game over banner
- if game_over:
- banner_font = pygame.font.SysFont("Arial", 50)
- banner_text = banner_font.render("Game Over! Press R to restart.", True, BLACK)
- screen.blit(banner_text, (100, 100))
- # Restart button
- restart_font = pygame.font.SysFont("Arial", 30)
- restart_text = restart_font.render("R", True, BLACK)
- screen.blit(restart_text, (100, 200))
- # Dominance percentage
- if player_A_score + player_L_score > 0:
- dominance_font = pygame.font.SysFont("Arial", 20)
- if player_A_territory >= 100:
- dominance_text = dominance_font.render(f"Player A dominance: 100%", True, BLACK)
- else:
- dominance_text = dominance_font.render(f"Player A dominance: {player_A_score / (player_A_score + player_L_score) * 100:.2f}%", True, BLACK)
- screen.blit(dominance_text, (100, 300))
- if player_L_territory >= 100:
- dominance_text = dominance_font.render(f"Player L dominance: 100%", True, BLACK)
- else:
- dominance_text = dominance_font.render(f"Player L dominance: {player_L_score / (player_A_score + player_L_score) * 100:.2f}%", True, BLACK)
- screen.blit(dominance_text, (100, 350))
- # Update the display
- pygame.display.flip()
- # Cap the frame rate
- clock.tick(60)
- # Check for restart
- keys = pygame.key.get_pressed()
- if keys[pygame.K_r] and game_over:
- player_A_territory = 50
- player_L_territory = 50
- line_x = WINDOW_WIDTH / 2
- game_over = False
- =================================
- Code generated by Claude 3 Sonnet:
- =================================
- import pygame
- import random
- import time
- # Initialize Pygame
- pygame.init()
- # Set up the game window
- WINDOW_WIDTH = 800
- WINDOW_HEIGHT = 600
- window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
- pygame.display.set_caption("Line Game")
- # Define colors
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- RED = (255, 0, 0)
- BLUE = (0, 0, 255)
- # Game variables
- player1_territory = WINDOW_WIDTH // 2
- player2_territory = WINDOW_WIDTH // 2
- line_position = WINDOW_WIDTH // 2
- line_moving = False
- line_speed = 5
- line_direction = 0 # 0 = left, 1 = right
- move_interval = 3 # seconds
- # Game loop
- running = True
- clock = pygame.time.Clock()
- last_move_time = time.time()
- while running:
- clock.tick(60) # Limit frame rate
- # Handle events
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- # Player input
- keys = pygame.key.get_pressed()
- if keys[pygame.K_a] and line_moving and line_direction == 1:
- line_moving = False
- if keys[pygame.K_l] and line_moving and line_direction == 0:
- line_moving = False
- # Move the line
- if not line_moving:
- current_time = time.time()
- if current_time - last_move_time > move_interval:
- line_moving = True
- line_direction = random.randint(0, 1)
- last_move_time = current_time
- if line_moving:
- if line_direction == 0: # Move left
- line_position -= line_speed
- else: # Move right
- line_position += line_speed
- # Update player territories
- player1_territory = line_position
- player2_territory = WINDOW_WIDTH - line_position
- # Check for game over
- if player1_territory <= 0:
- print("Player 2 wins!")
- running = False
- elif player2_territory <= 0:
- print("Player 1 wins!")
- running = False
- # Clear the window
- window.fill(BLACK)
- # Draw the line
- pygame.draw.line(window, WHITE, (line_position, 0), (line_position, WINDOW_HEIGHT), 2)
- # Draw player territories
- pygame.draw.rect(window, RED, (0, 0, player1_territory, WINDOW_HEIGHT))
- pygame.draw.rect(window, BLUE, (player1_territory, 0, player2_territory, WINDOW_HEIGHT))
- # Update the display
- pygame.display.flip()
- # Quit Pygame
- pygame.quit()
Advertisement
Comments
-
- Prompt:
- I want to create a game.
- To players play against each other in the same computer. One is in control of the letter L and the other controls the letter A.
- We have a field divided by two with a line. Each player controls 50% of the field. The player who controls A controls the left half and the one who controls L controls the right half
- At a random momemnt, the line will move towards either the left or the right.
- The player who is losing ground must pres the button as fast as possible to prevent the line from moving anymore.
- When that's done, the line will stay in place and players will have to wait until the line starts to move at a random moment to a random location.
- The player who ends up controling 0% of the screen loses and the game ends
-
- Code created by Reka Core:
- import pygame
- import random
- import time
- # Initialize Pygame
- pygame.init()
- # Game window dimensions
- WINDOW_WIDTH = 800
- WINDOW_HEIGHT = 400
- # Create the game window
- screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
- # Set the window title
- pygame.display.set_caption("Letter Game")
- # Line movement speed
- LINE_SPEED = 5
- # Player colors
- PLAYER_A_COLOR = (255, 0, 0)
- PLAYER_L_COLOR = (0, 0, 255)
- # Game field dimensions
- FIELD_WIDTH = WINDOW_WIDTH
- FIELD_HEIGHT = WINDOW_HEIGHT // 2
- # Player-controlled areas
- player_a_area = FIELD_WIDTH // 2
- player_l_area = FIELD_WIDTH // 2
- # Line position
- line_x = WINDOW_WIDTH // 2
- line_y = FIELD_HEIGHT
- # Line direction
- line_direction = random.choice([-1, 1])
- # Game loop
- running = True
- while running:
- # Handle events
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_a and line_x <= FIELD_WIDTH * 3 // 4:
- line_x = FIELD_WIDTH * 3 // 4
- line_direction = 1
- time.sleep(random.uniform(0, 5))
- elif event.key == pygame.K_l and line_x >= FIELD_WIDTH // 4:
- line_x = FIELD_WIDTH // 4
- line_direction = -1
- time.sleep(random.uniform(0, 5))
- # Move the line in a specific direction
- line_x += line_direction * LINE_SPEED
- # Check if a player is losing ground
- if line_x <= FIELD_WIDTH // 4:
- player_l_area -= LINE_SPEED
- line_x = FIELD_WIDTH // 2 - player_a_area
- elif line_x >= FIELD_WIDTH * 3 // 4:
- player_a_area -= LINE_SPEED
- line_x = FIELD_WIDTH // 2 + player_l_area
- # Update player-controlled areas
- player_a_area = FIELD_WIDTH // 2 - line_x
- player_l_area = line_x - FIELD_WIDTH // 2
- # Draw the game field
- screen.fill((255, 255, 255))
- pygame.draw.line(screen, (0, 0, 0), (line_x, line_y), (line_x, WINDOW_HEIGHT), 2)
- pygame.draw.rect(screen, PLAYER_A_COLOR, (0, 0, player_a_area, FIELD_HEIGHT))
- pygame.draw.rect(screen, PLAYER_L_COLOR, (player_a_area, 0, player_l_area, FIELD_HEIGHT))
- # Update the display
- pygame.display.flip()
- # Wait for the next line movement
- time.sleep(0.1)
- # Game over screen
- pygame.display.set_caption("Game Over")
- screen.fill((255, 255, 255))
- if player_a_area == 0:
- winner = "Player L"
- elif player_l_area == 0:
- winner = "Player A"
- text = pygame.font.Font(None, 36).render(f"Winner: {winner}", True, (0, 0, 0))
- text_rect = text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2))
- screen.blit(text, text_rect)
- pygame.display.flip()
- time.sleep(3)
- # Quit Pygame
- pygame.quit()
Add Comment
Please, Sign In to add comment
Advertisement