Write a python program to create the game of chrome dino using pygame rects
- User
Write a python program to create the game of chrome dino using pygame rects
Assistant
Sure! Here's an example of how you could create the game of Chrome Dino using Pygame and rectangles:
import pygame # Initialize Pygame pygame.init() # Set the screen dimensions screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) # Set the title of the window pygame.display.set_caption("Chrome Dino") # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) # Define some rectangles player_rect = pygame.Rect(50, screen_height/2, 50, 50) obstacle_rect = pygame.Rect(50, screen_height/2, 100, 50) # Define some speeds player_speed = 5 obstacle_speed = 2 # Define some scores player_score = 0 obstacle_score = 0 # Main game loop while True: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() # Move the player rectangle keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player_rect.x -= player_speed if keys[pygame.K_RIGHT]: player_rect.x += player_speed # Move the obstacle rectangle obstacle_rect.x += obstacle_speed # Collision detection if player_rect.colliderect(obstacle_rect): # Increase the obstacle score obstacle_score += 1 # Reset the player position player_rect.x = 50 player_rect.y = screen_height/2 # Draw everything screen.fill(BLACK) pygame.draw.rect(screen, WHITE, player_rect) pygame.draw.rect(screen, GREEN, obstacle_rect) # Update the scores player_score_text = f"Player Score: {player_score}" obstacle_score_text = f"Obstacle Score: {obstacle_score}" pygame.draw.rect(screen, WHITE, (50, 10, 50, 20), 2) pygame.draw.rect(screen, BLACK, (50, 10, 50, 20), 1) pygame.draw.text(screen, player_score_text, (50, 20), 24, WHITE) pygame.draw.text(screen, obstacle_score_text, (50, 40), 24, GREEN) # Update the screen pygame.display.flip() pygame.time.Clock().tick(60)This code creates a window with a black background, and draws two rectangles: one for the player, and one for the obstacle. The player rectangle is white, and the obstacle rectangle is green. The player rectangle can be moved using the left and right arrow keys, and the obstacle rectangle moves automatically. If the player rectangle collides with the obstacle rectangle, the obstacle score increases, and the player rectangle is reset to its starting position. The player score and obstacle score are displayed on the screen using text.
This is just a basic example, and you can add more features to make the game more interesting, such as adding more obstacles, implementing collision detection for the top and bottom of the screen, and adding a game over screen.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.