Untitled
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
import pygame import sys # Initialize Pygame pygame.init() # Set up display screen = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Simple Action Game") # Colors WHITE = (255, 255, 255) RED = (255, 0, 0) # Player player_image = pygame.Surface((50, 50)) player_image.fill(RED) player_rect = player_image.get_rect() player_rect.centerx = screen.get_rect().centerx player_rect.bottom = screen.get_rect().bottom # Projectiles projectiles = [] # Game loop clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: projectile = pygame.Rect(player_rect.centerx - 5, player_rect.top, 10, 20) projectiles.append(projectile) # Move player keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player_rect.x -= 5 if keys[pygame.K_RIGHT]: player_rect.x += 5 # Move projectiles for projectile in projectiles: projectile.y -= 5 if projectile.y < 0: projectiles.remove(projectile) # Draw everything screen.fill(WHITE) screen.blit(player_image, player_rect) for projectile in projectiles: pygame.draw.rect(screen, RED, projectile) pygame.display.flip() clock.tick(60) pygame.quit() sys.exit()