Untitled
import pygame import random # Initialize Pygame pygame.init() # Screen Dimensions WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Poop Game") # Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) BROWN = (139, 69, 19) RED = (255, 0, 0) # Player Settings player_width = 50 player_height = 50 player_x = WIDTH // 2 player_y = HEIGHT - player_height - 10 player_speed = 5 # Poop Settings poop_width = 20 poop_height = 20 poop_speed = 7 poop_active = False poop_x, poop_y = player_x + player_width // 2, player_y # Target Settings target_width = 100 target_height = 20 target_x = random.randint(0, WIDTH - target_width) target_y = 100 # Game Variables score = 0 clock = pygame.time.Clock() # Font font = pygame.font.SysFont("Arial", 30) # Main Game Loop running = True while running: screen.fill(WHITE) # Event Handling for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Player Controls keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and player_x > 0: player_x -= player_speed if keys[pygame.K_RIGHT] and player_x < WIDTH - player_width: player_x += player_speed if keys[pygame.K_SPACE] and not poop_active: poop_active = True poop_x = player_x + player_width // 2 poop_y = player_y # Move Poop if poop_active: poop_y -= poop_speed if poop_y < 0: poop_active = False # Check Collision with Target if ( target_y < poop_y < target_y + target_height and target_x < poop_x < target_x + target_width ): score += 1 target_x = random.randint(0, WIDTH - target_width) poop_active = False # Draw Player pygame.draw.rect(screen, BLACK, (player_x, player_y, player_width, player_height)) # Draw Poop if poop_active: pygame.draw.rect(screen, BROWN, (poop_x, poop_y, poop_width, poop_height)) # Draw Target pygame.draw.rect(screen, RED, (target_x, target_y, target_width, target_height)) # Display Score score_text = font.render(f"Score: {score}", True, BLACK) screen.blit(score_text, (10, 10)) # Update Display pygame.display.flip() # Frame Rate clock.tick(30) # Quit Pygame pygame.quit()
Leave a Comment