nord vpnnord vpn
Ad

Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.7 kB
0
Indexable
Never
import pygame
import sys

# Initialize Pygame
pygame.init()

# Screen dimensions
screen_width = 800
screen_height = 600

# Colors
white = (255, 255, 255)

# Create the screen
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Shooting Game")

# Player settings
player_width = 50
player_height = 50
player_x = (screen_width - player_width) // 2
player_y = screen_height - player_height

# Bullet settings
bullet_width = 10
bullet_height = 20
bullet_x = 0
bullet_y = player_y
bullet_speed = 5
bullet_state = "ready"  # "ready" means the bullet is not on the screen, "fire" means it's moving

# Player movement
player_speed = 5

def player(x, y):
    pygame.draw.rect(screen, white, (x, y, player_width, player_height))

def fire_bullet(x, y):
    global bullet_state
    bullet_state = "fire"
    pygame.draw.rect(screen, white, (x, y, bullet_width, bullet_height))

# Game loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Player movement
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        player_x -= player_speed
    if keys[pygame.K_RIGHT]:
        player_x += player_speed

    # Bullet movement
    if bullet_state == "fire":
        fire_bullet(bullet_x, bullet_y)
        bullet_y -= bullet_speed

    if bullet_y <= 0:
        bullet_state = "ready"
        bullet_y = player_y

    # Redraw the screen
    screen.fill((0, 0, 0))
    player(player_x, player_y)
    
    pygame.display.update()

# Quit the game
pygame.quit()
sys.exit()

nord vpnnord vpn
Ad