print('Hello world!')import pygame
import random

# Inicializando o Pygame
pygame.init()

# Definindo o tamanho da tela
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Futebol 2D Simples")

# Cores
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
RED = (255, 0, 0)

# Definindo o jogador
player_width = 50
player_height = 50
player_x = screen_width // 2
player_y = screen_height - player_height - 20
player_speed = 5

# Definindo a bola
ball_radius = 15
ball_x = player_x + player_width // 2
ball_y = player_y - ball_radius
ball_speed_x = 0
ball_speed_y = 0

# Definindo o gol
goal_width = 150
goal_height = 10
goal_x = (screen_width - goal_width) // 2
goal_y = 0

# Função para desenhar o campo e os objetos
def draw_game():
    screen.fill(GREEN)
    pygame.draw.rect(screen, WHITE, (goal_x, goal_y, goal_width, goal_height))  # Gol
    pygame.draw.rect(screen, BLACK, (player_x, player_y, player_width, player_height))  # Jogador
    pygame.draw.circle(screen, WHITE, (ball_x, ball_y), ball_radius)  # Bola

def handle_player_movement(keys):
    global player_x, player_y
    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 keys[pygame.K_UP] and player_y > 0:
        player_y -= player_speed
    if keys[pygame.K_DOWN] and player_y < screen_height - player_height:
        player_y += player_speed

def handle_ball_movement():
    global ball_x, ball_y, ball_speed_x, ball_speed_y, player_x, player_y
    # Se a bola se move, atualiza a posição
    ball_x += ball_speed_x
    ball_y += ball_speed_y
    
    # Bola volta para o jogador se ela for chutada
    if ball_y < 0:
        ball_x = player_x + player_width // 2
        ball_y = player_y - ball_radius
        ball_speed_x = 0
        ball_speed_y = 0
        
    # Verifica se a bola entrou no gol
    if goal_x < ball_x < goal_x + goal_width and ball_y - ball_radius <= goal_height:
        print("Gol!")
        ball_x = player_x + player_width // 2
        ball_y = player_y - ball_radius
        ball_speed_x = 0
        ball_speed_y = 0

def handle_shooting():
    global ball_speed_x, ball_speed_y
    # Chutando a bola
    ball_speed_x = random.choice([-5, 5])
    ball_speed_y = -5

# Loop principal do jogo
running = True
while running:
    pygame.time.delay(30)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Checar teclas pressionadas
    keys = pygame.key.get_pressed()
    handle_player_movement(keys)

    # Se pressionar espaço, chuta a bola
    if keys[pygame.K_SPACE]:
        handle_shooting()

    # Mover bola
    handle_ball_movement()

    # Desenhar os objetos na tela
    draw_game()

    # Atualizar a tela
    pygame.display.update()

# Fechar o jogo
pygame.quit()

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: