- import pygame
- # Initialize Pygame
- pygame.init()
- # Set up the game window
- screen_width = 800
- screen_height = 600
- screen = pygame.display.set_mode((screen_width, screen_height))
- pygame.display.set_caption("Run, Jump, and Duck Game")
- # Set up the player
- player_width = 50
- player_height = 50
- player_x = 100
- player_y = screen_height - player_height - 50
- player_speed = 5
- player_jump_height = 100
- player_is_jumping = False
- # Set up the game loop
- clock = pygame.time.Clock()
- game_over = False
- # Main game loop
- while not game_over:
- # Handle events
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- game_over = True
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_SPACE and not player_is_jumping:
- player_is_jumping = True
- if event.key == pygame.K_DOWN:
- player_height = 25
- player_y += 25
- if event.key == pygame.K_UP:
- player_height = 50
- player_y -= 25
- # Move the player
- 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 < screen_width - player_width:
- player_x += player_speed
- if player_is_jumping:
- if player_jump_height >= 0:
- player_y -= player_jump_height
- player_jump_height -= 10
- else:
- player_is_jumping = False
- player_jump_height = 100
- # Draw the player
- pygame.draw.rect(screen, (255, 0, 0), (player_x, player_y, player_width, player_height))
- # Update the screen
- pygame.display.update()
- clock.tick(60)
- # Quit Pygame
- pygame.quit()
[text] game1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: