import pygame
import sys
import math
Inicialização do Pygame
pygame.init()
Configurações da janela
WIDTH, HEIGHT = 400, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Demo - Luzes e Borrões: A Ponte")
Cores
BACKGROUND_COLOR = (100, 200, 100)
BRIDGE_COLOR = (150, 75, 0)
WATER_COLOR = (0, 0, 255)
CLOUD_COLOR = (0, 0, 0, 150)
Estados do jogo
GAME_STATES = ['intro', 'exploration', 'dialogue', 'falling', 'transition']
game_state = 'intro'
dialogue_index = 0
dialogues = [
"12 de Janeiro de 1980. Oliver, 15 anos, está sobre uma ponte abandonada...",
"Ninguém lembrou seu aniversário. A dor o leva a decidir pular...",
"Ele fecha os olhos, respira fundo e salta...",
"Uma nuvem escura surge! Ele é transportado para um laboratório estranho.",
"Torphí: 'Eis que te apresento uma oportunidade única de uma nova vida...'"
]
Carregar sprites
try:
player_img = pygame.image.load("oliver_front.png").convert_alpha()
player_back_img = pygame.image.load("oliver_back.png").convert_alpha()
player_side_img = pygame.image.load("oliver_side.png").convert_alpha()
player_img = pygame.transform.scale(player_img, (20, 20))
player_back_img = pygame.transform.scale(player_back_img, (20, 20))
player_side_img = pygame.transform.scale(player_side_img, (20, 20))
except FileNotFoundError:
print("Erro: Sprites não encontrados. Certifique-se de que oliver_front.png, oliver_back.png e oliver_side.png estão no diretório.")
sys.exit()
Classes
class Player:
def init(self, x, y):
self.x = x
self.y = y
self.speed = 3
self.direction = 'front'
self.frame = 0
def update(self):
keys = pygame.key.get_pressed()
prev_x, prev_y = self.x, self.y
if keys[pygame.K_LEFT]:
self.x -= self.speed
self.direction = 'side'
if keys[pygame.K_RIGHT]:
self.x += self.speed
self.direction = 'side'
if keys[pygame.K_UP]:
self.y -= self.speed
self.direction = 'back'
if keys[pygame.K_DOWN]:
self.y += self.speed
self.direction = 'front'
self.x = max(0, min(self.x, WIDTH - 20))
self.y = max(0, min(self.y, HEIGHT - 20))
if self.x != prev_x or self.y != prev_y:
self.frame = (self.frame + 1) % 2
def draw(self, surface):
img = player_img if self.direction == 'front' else player_back_img if self.direction == 'back' else player_side_img
if game_state == 'falling':
rotated_img = pygame.transform.rotate(img, fall_progress * 0.1)
surface.blit(rotated_img, (self.x + 10 - rotated_img.get_width() // 2, self.y + fall_progress - rotated_img.get_height() // 2))
else:
surface.blit(img, (self.x, self.y))
def handle_input(self):
global game_state
if pygame.key.get_pressed()[pygame.K_SPACE]:
dx = self.x - bridge.x
dy = self.y - bridge.y
if math.sqrt(dx * dx + dy * dy) < 30:
game_state = 'dialogue'
class Bridge:
def init(self, x, y):
self.x = x
self.y = y
def draw(self, surface):
pygame.draw.rect(surface, BRIDGE_COLOR, (self.x, self.y, 50, 20))
pygame.draw.rect(surface, WATER_COLOR, (self.x, self.y + 20, 50, 50))
Variáveis de animação
fall_progress = 0
cloud_size = 0
clock = pygame.time.Clock()
player = Player(50, 50)
bridge = Bridge(200, 300)
Loop principal
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if game_state == 'intro':
screen.fill((0, 0, 0))
font = pygame.font.Font(None, 36)
text = font.render("Demo: Luzes e Borrões - A Ponte\nPressione ESPAÇO para começar", True, (255, 255, 255))
text_rect = text.get_rect(center=(WIDTH // 2, HEIGHT // 2))
screen.blit(text, text_rect)
if pygame.key.get_pressed()[pygame.K_SPACE]:
game_state = 'exploration'
elif game_state == 'exploration':
screen.fill(BACKGROUND_COLOR)
player.update()
player.draw(screen)
bridge.draw(screen)
player.handle_input()
elif game_state == 'dialogue':
screen.fill((0, 0, 0))
font = pygame.font.Font(None, 24)
text = font.render(dialogues[dialogue_index], True, (255, 255, 255))
text_rect = text.get_rect(center=(WIDTH // 2, HEIGHT // 2 - 20))
screen.blit(text, text_rect)
prompt = font.render("Pressione ESPAÇO para continuar", True, (255, 255, 255))
screen.blit(prompt, prompt.get_rect(center=(WIDTH // 2, HEIGHT - 20)))
if pygame.key.get_pressed()[pygame.K_SPACE] or pygame.key.get_pressed()[pygame.K_RETURN]:
dialogue_index += 1
if dialogue_index == 3:
game_state = 'falling'
fall_progress = 0
elif dialogue_index >= len(dialogues):
dialogue_index = len(dialogues) - 1
elif game_state == 'falling':
screen.fill(BACKGROUND_COLOR)
bridge.draw(screen)
player.draw(screen)
fall_progress += 5
if fall_progress > 100:
game_state = 'transition'
cloud_size = 0
elif game_state == 'transition':
screen.fill((50, 50, 50)) # Fundo do laboratório
cloud = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
pygame.draw.ellipse(cloud, CLOUD_COLOR, (WIDTH // 2 - cloud_size // 2, HEIGHT // 2 - cloud_size // 2, cloud_size, cloud_size))
screen.blit(cloud, (0, 0))
cloud_size += 5
if cloud_size > 200:
game_state = 'dialogue'
dialogue_index = 3
font = pygame.font.Font(None, 24)
text = font.render("Transportado...", True, (255, 255, 255))
screen.blit(text, text.get_rect(center=(WIDTH // 2, HEIGHT // 2)))
pygame.display.flip()
clock.tick(60) # 60 FPS
pygame.quit()
sys.exit()
Top comments (0)