import pygame import sys import random # Initialize Pygame pygame.init() # Set the screen size screen_width = 1000 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Horse Skateboarder - Infinite Runner") # Load images horse_img = pygame.image.load('horse.png') skateboard_img = pygame.image.load('skateboard.png') # Resize images horse_img = pygame.transform.scale(horse_img, (200, 150)) skateboard_img = pygame.transform.scale(skateboard_img, (250, 80)) # Set initial positions horse_x = screen_width // 2 - 100 horse_y = screen_height - 230 horse_speed = 5 floating = False # Game variables jumping = False jump_height = 20 gravity = 1 y_velocity = 0 flip_angle = 0 flipping = False flip_speed = 20 # Obstacle variables obstacle_width = 50 obstacle_height = 50 grindable_obstacle_height = 20 obstacle_speed = 5 grindable_obstacles = [] obstacles = [] def create_obstacle(): if random.random() < 0.005: obstacle_x = screen_width obstacle_y = screen_height - 150 new_obstacle = pygame.Rect(obstacle_x, obstacle_y, obstacle_width, obstacle_height) obstacles.append(new_obstacle) def create_grindable_obstacle(): if random.random() < 0.004: grindable_x = screen_width grindable_y = screen_height - 190 # Positioned slightly higher grindable_width = random.randint(160, 240) # Longer grindable obstacles grindable_obstacles.append(pygame.Rect( grindable_x, grindable_y, grindable_width, grindable_obstacle_height )) # Clock clock = pygame.time.Clock() # Game loop while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: horse_x -= horse_speed if keys[pygame.K_RIGHT]: horse_x += horse_speed if keys[pygame.K_SPACE] and floating: floating = False jumping = True y_velocity = -jump_height if keys[pygame.K_SPACE] and not jumping and not flipping: jumping = True y_velocity = -jump_height if keys[pygame.K_f] and jumping and not flipping: flipping = True flip_angle = 0 if jumping: horse_y += y_velocity y_velocity += gravity if horse_y >= screen_height - 230: horse_y = screen_height - 230 jumping = False if flipping: flip_angle += flip_speed if flip_angle >= 360: flip_angle = 0 flipping = False for obstacle in obstacles[:]: obstacle.x -= obstacle_speed if obstacle.x < 0: obstacles.remove(obstacle) for grindable in grindable_obstacles[:]: grindable.x -= obstacle_speed if grindable.x < 0: grindable_obstacles.remove(grindable) create_obstacle() create_grindable_obstacle() screen.fill((255, 255, 255)) pygame.draw.rect(screen, (0, 0, 0), (0, screen_height - 50, screen_width, 50)) for obstacle in obstacles: pygame.draw.rect(screen, (0, 255, 0), obstacle) for grindable in grindable_obstacles: pygame.draw.rect(screen, (169, 169, 169), grindable) for grindable in grindable_obstacles: if grindable.colliderect(pygame.Rect(horse_x, horse_y + 100, 250, 80)): floating = True horse_y = grindable.y - 150 # Align horse and skateboard properly on gray part break else: floating = False if floating: rotated_horse = pygame.transform.rotate(horse_img, 45) rotated_skateboard = pygame.transform.rotate(skateboard_img, 45) screen.blit(rotated_skateboard, (horse_x, horse_y + 100)) screen.blit(rotated_horse, (horse_x, horse_y)) else: screen.blit(skateboard_img, (horse_x, horse_y + 100)) rotated_horse = pygame.transform.rotate(horse_img, flip_angle) screen.blit(rotated_horse, (horse_x, horse_y)) pygame.display.update() clock.tick(60)