Untitled
plain_text
a month ago
952 B
0
Indexable
Never
import pygame import sys # Initialize Pygame pygame.init() # Set up the screen screen = pygame.display.set_mode((800, 400)) pygame.display.set_caption("Running Game") # Define colors WHITE = (255, 255, 255) # Set up the player player = pygame.Rect(50, 300, 40, 40) # Set up player variables player_speed = 5 jump = False jump_count = 10 # Main 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_SPACE] and not jump: jump = True if jump: player.y -= (jump_count * abs(jump_count)) * 0.5 jump_count -= 1 if jump_count < -10: jump = False jump_count = 10 # Update player position player.y += player_speed # Draw everything screen.fill(WHITE) pygame.draw.rect(screen, (0, 0, 0), player) pygame.display.update()