Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pygame | |
| import numpy as np | |
| # Inicializa o Pygame | |
| pygame.init() | |
| # Tamanho da tela do jogo | |
| screen_width = 640 | |
| screen_height = 480 | |
| # Configurações da tela | |
| screen = pygame.display.set_mode((screen_width, screen_height)) | |
| pygame.display.set_caption("A Jornada do Discípulo") | |
| # Configurações do jogador | |
| player_pos = [screen_width // 2, screen_height // 2] | |
| player_size = 50 | |
| player_color = (0, 128, 255) | |
| player_velocity = [0, 0] | |
| # Função para renderizar o jogo | |
| def render_game(): | |
| global player_pos, player_velocity | |
| # Mover jogador | |
| player_pos[0] += player_velocity[0] | |
| player_pos[1] += player_velocity[1] | |
| # Limitar a posição do jogador dentro da tela | |
| if player_pos[0] < 0: | |
| player_pos[0] = 0 | |
| elif player_pos[0] > screen_width - player_size: | |
| player_pos[0] = screen_width - player_size | |
| if player_pos[1] < 0: | |
| player_pos[1] = 0 | |
| elif player_pos[1] > screen_height - player_size: | |
| player_pos[1] = screen_height - player_size | |
| # Renderizar a tela | |
| screen.fill((0, 0, 0)) | |
| pygame.draw.rect(screen, player_color, (*player_pos, player_size, player_size)) | |
| # Converter a tela do Pygame para uma imagem e exibir no Streamlit | |
| image = pygame.surfarray.array3d(pygame.display.get_surface()) | |
| image = np.rot90(image, 3) | |
| image = np.fliplr(image) | |
| st.image(image, caption='Jogo em execução', use_column_width=True) | |
| # Integração com Streamlit | |
| st.title('A Jornada do Discípulo') | |
| # Controles do jogador | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| if st.button('Esquerda'): | |
| player_velocity[0] = -5 | |
| with col2: | |
| if st.button('Parar'): | |
| player_velocity = [0, 0] | |
| with col3: | |
| if st.button('Direita'): | |
| player_velocity[0] = 5 | |
| if st.button('Cima'): | |
| player_velocity[1] = -5 | |
| if st.button('Baixo'): | |
| player_velocity[1] = 5 | |
| render_game() | |