import pygame import sys import colorsys import math # Initialize Pygame pygame.init() # Set the dimensions of the window WINDOW_WIDTH = 600 WINDOW_HEIGHT = 600 # Create the window window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) pygame.display.set_caption("Chatgpt training") # Timer for background change clock = pygame.time.Clock() switch_time = 0.0000001 # milliseconds # Circle properties circle_radius = 15 circle_position = [WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2] circle_velocity = [0, 0] # Initial velocity gravity = 0.5 # Acceleration due to gravity jump_strength = -10 # Strength of the jump movement_speed = 5 # Speed of left and right movement jump_count = 0 # Number of jumps made max_jumps = 3 # Maximum number of jumps # Platform properties platforms = [ [50, 550, 150, 20], # Bottom left [400, 450, 200, 20], # Bottom right [100, 350, 200, 20], # Middle left [350, 250, 200, 20], # Middle right [200, 150, 200, 20] # Top ] # Moving platform properties moving_platform = [200, 100, 200, 20] moving_speed = 2 moving_direction = 1 # Triangle properties triangle_size = 20 base_triangle_speed = 2 triangle_acceleration = 0.001 triangle_spawn_interval = 5000 # milliseconds last_spawn_time = 0 triangles = [[100, 100, base_triangle_speed]] # Timer properties start_time = pygame.time.get_ticks() def draw_triangle(surface, color, position, size): x, y = position points = [ (x, y - size), (x - size, y + size), (x + size, y + size) ] pygame.draw.polygon(surface, color, points) def check_collision(circle_pos, circle_radius, triangle_pos, triangle_size): # Approximate the triangle as a circle for simplicity triangle_radius = triangle_size dist = math.hypot(circle_pos[0] - triangle_pos[0], circle_pos[1] - triangle_pos[1]) return dist < (circle_radius + triangle_radius) # Main loop running = True hue = 0 # Start with red (Hue value) 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_SPACE and jump_count < max_jumps: # Space key initiates a jump circle_velocity[1] = jump_strength jump_count += 1 elif event.key == pygame.K_LEFT: # Left arrow key moves the circle left circle_velocity[0] = -movement_speed elif event.key == pygame.K_RIGHT: # Right arrow key moves the circle right circle_velocity[0] = movement_speed elif event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: # Stop horizontal movement when arrow key released circle_velocity[0] = 0 # Convert the hue value to RGB rgb_color = colorsys.hsv_to_rgb(hue / 360, 1.0, 1.0) background_color = (int(rgb_color[0] * 255), int(rgb_color[1] * 255), int(rgb_color[2] * 255)) # Fill the window with the current background color window.fill(background_color) # Calculate complementary color (invert color) inverted_color = (255 - background_color[0], 255 - background_color[1], 255 - background_color[2]) # Apply gravity to velocity circle_velocity[1] += gravity # Update circle position based on velocity circle_position[0] += circle_velocity[0] circle_position[1] += circle_velocity[1] # Collision detection with window boundaries if circle_position[0] - circle_radius <= 0: circle_position[0] = circle_radius elif circle_position[0] + circle_radius >= WINDOW_WIDTH: circle_position[0] = WINDOW_WIDTH - circle_radius if circle_position[1] - circle_radius <= 0: circle_position[1] = circle_radius elif circle_position[1] + circle_radius >= WINDOW_HEIGHT: running = False # Circle fell to the bottom of the screen # Collision detection with platforms for platform in platforms: if (circle_position[1] + circle_radius >= platform[1] and circle_position[1] <= platform[1] + platform[3]) and \ (circle_position[0] + circle_radius >= platform[0] and circle_position[0] - circle_radius <= platform[0] + platform[2]): # Collision detected if circle_velocity[1] > 0: # Only if circle is moving downwards circle_position[1] = platform[1] - circle_radius # Adjust circle position to top of the platform circle_velocity[1] = 0 # Stop circle from falling further jump_count = 0 # Reset jump count # Update and draw the moving platform moving_platform[0] += moving_speed * moving_direction if moving_platform[0] <= 0 or moving_platform[0] + moving_platform[2] >= WINDOW_WIDTH: moving_direction *= -1 # Draw the moving platform pygame.draw.rect(window, inverted_color, moving_platform) # Collision detection with moving platform if (circle_position[1] + circle_radius >= moving_platform[1] and circle_position[1] <= moving_platform[1] + moving_platform[3]) and \ (circle_position[0] + circle_radius >= moving_platform[0] and circle_position[0] - circle_radius <= moving_platform[0] + moving_platform[2]): # Collision detected if circle_velocity[1] > 0: # Only if circle is moving downwards circle_position[1] = moving_platform[1] - circle_radius # Adjust circle position to top of the platform circle_velocity[1] = 0 # Stop circle from falling further jump_count = 0 # Reset jump count # Draw static platforms for platform in platforms: pygame.draw.rect(window, inverted_color, platform) # Update triangle positions and check for collisions for triangle in triangles: dx = circle_position[0] - triangle[0] dy = circle_position[1] - triangle[1] dist = math.hypot(dx, dy) if dist != 0: dx = dx / dist * triangle[2] dy = dy / dist * triangle[2] triangle[0] += dx triangle[1] += dy # Check for collision between circle and triangle if check_collision(circle_position, circle_radius, (triangle[0], triangle[1]), triangle_size): running = False # Draw the triangle with the complementary color draw_triangle(window, inverted_color, (triangle[0], triangle[1]), triangle_size) # Increase the base triangle's speed over time base_triangle_speed += triangle_acceleration # Spawn new triangles every five seconds current_time = pygame.time.get_ticks() if current_time - last_spawn_time >= triangle_spawn_interval: triangles.append([100, 100, base_triangle_speed / 2]) last_spawn_time = current_time # Draw the circle with the complementary color pygame.draw.circle(window, inverted_color, circle_position, circle_radius) # Calculate and render the timer elapsed_time = (pygame.time.get_ticks() - start_time) / 1000 # Convert milliseconds to seconds font = pygame.font.SysFont(None, 36) timer_text = font.render(f"Time: {elapsed_time:.2f}", True, inverted_color) window.blit(timer_text, (WINDOW_WIDTH - 150, 10)) # Update the display pygame.display.update() # Control the frame rate clock.tick(60) # Increment the hue for the next frame hue += 1 if hue >= 360: hue = 0 # Quit Pygame pygame.quit() sys.exit()