diff --git a/Code pygame du prof.py b/Code pygame du prof.py new file mode 100644 index 0000000..db2d5d8 --- /dev/null +++ b/Code pygame du prof.py @@ -0,0 +1,52 @@ +import pygame +import sys + +# Initialize Pygame +pygame.init() + +# Screen dimensions +WIDTH, HEIGHT = 640, 480 +screen = pygame.display.set_mode((WIDTH, HEIGHT)) +pygame.display.set_caption("Simple Pygame Game") + +# Clock to control frame rate +clock = pygame.time.Clock() +FPS = 30 + +# Player properties +player_size = 40 +player_color = (0, 255, 250) +player_x = 0 +player_y = 0 +player_speed = 10 + +# Main game loop +running = True +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + # Handle key presses + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + player_x -= player_speed + if keys[pygame.K_RIGHT]: + player_x += player_speed + if keys[pygame.K_UP]: + player_y -= player_speed + if keys[pygame.K_DOWN]: + player_y += player_speed + if keys[pygame.K_SPACE]: + player_x += 20 + # Draw everything + screen.fill((0, 0, 0)) # Black background + pygame.draw.rect(screen, player_color, (player_x, player_y, player_size, player_size)) + + # Update display and tick clock + pygame.display.flip() + clock.tick(FPS) + +# Clean up +pygame.quit() +sys.exit()