joaomaia commited on
Commit
bb7c4e7
·
1 Parent(s): 5c60e50

Add game files and setup for Streamlit deployment

Browse files
Files changed (1) hide show
  1. app.py +45 -39
app.py CHANGED
@@ -1,8 +1,6 @@
1
  import streamlit as st
2
  import pygame
3
  import numpy as np
4
- from pygame.locals import *
5
- from PIL import Image
6
 
7
  # Inicializa o Pygame
8
  pygame.init()
@@ -15,50 +13,58 @@ screen_height = 480
15
  screen = pygame.display.set_mode((screen_width, screen_height))
16
  pygame.display.set_caption("A Jornada do Discípulo")
17
 
18
- # Função principal do jogo
19
- def run_game():
20
- # Configurações do jogo
21
- player_pos = [screen_width // 2, screen_height // 2]
22
- player_size = 50
23
- player_color = (0, 128, 255)
24
 
25
- running = True
26
- clock = pygame.time.Clock()
 
27
 
28
- while running:
29
- for event in pygame.event.get():
30
- if event.type == pygame.QUIT:
31
- running = False
32
- elif event.type == pygame.KEYDOWN:
33
- if event.key == pygame.K_ESCAPE:
34
- running = False
35
 
36
- keys = pygame.key.get_pressed()
37
- if keys[pygame.K_LEFT]:
38
- player_pos[0] -= 5
39
- if keys[pygame.K_RIGHT]:
40
- player_pos[0] += 5
41
- if keys[pygame.K_UP]:
42
- player_pos[1] -= 5
43
- if keys[pygame.K_DOWN]:
44
- player_pos[1] += 5
45
 
46
- screen.fill((0, 0, 0))
47
- pygame.draw.rect(screen, player_color, (player_pos[0], player_pos[1], player_size, player_size))
 
 
48
 
49
- # Converter a tela do Pygame para uma imagem e exibir no Streamlit
50
- image = pygame.surfarray.array3d(pygame.display.get_surface())
51
- image = np.rot90(image, 3)
52
- image = np.fliplr(image)
53
- st.image(image, caption='Jogo em execução', use_column_width=True)
54
 
55
- pygame.display.flip()
56
- clock.tick(30)
57
-
58
- pygame.quit()
 
59
 
60
  # Integração com Streamlit
61
  st.title('A Jornada do Discípulo')
62
- st.write("O jogo será iniciado abaixo.")
63
 
64
- run_game()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pygame
3
  import numpy as np
 
 
4
 
5
  # Inicializa o Pygame
6
  pygame.init()
 
13
  screen = pygame.display.set_mode((screen_width, screen_height))
14
  pygame.display.set_caption("A Jornada do Discípulo")
15
 
16
+ # Configurações do jogador
17
+ player_pos = [screen_width // 2, screen_height // 2]
18
+ player_size = 50
19
+ player_color = (0, 128, 255)
20
+ player_velocity = [0, 0]
 
21
 
22
+ # Função para renderizar o jogo
23
+ def render_game():
24
+ global player_pos, player_velocity
25
 
26
+ # Mover jogador
27
+ player_pos[0] += player_velocity[0]
28
+ player_pos[1] += player_velocity[1]
 
 
 
 
29
 
30
+ # Limitar a posição do jogador dentro da tela
31
+ if player_pos[0] < 0:
32
+ player_pos[0] = 0
33
+ elif player_pos[0] > screen_width - player_size:
34
+ player_pos[0] = screen_width - player_size
 
 
 
 
35
 
36
+ if player_pos[1] < 0:
37
+ player_pos[1] = 0
38
+ elif player_pos[1] > screen_height - player_size:
39
+ player_pos[1] = screen_height - player_size
40
 
41
+ # Renderizar a tela
42
+ screen.fill((0, 0, 0))
43
+ pygame.draw.rect(screen, player_color, (*player_pos, player_size, player_size))
 
 
44
 
45
+ # Converter a tela do Pygame para uma imagem e exibir no Streamlit
46
+ image = pygame.surfarray.array3d(pygame.display.get_surface())
47
+ image = np.rot90(image, 3)
48
+ image = np.fliplr(image)
49
+ st.image(image, caption='Jogo em execução', use_column_width=True)
50
 
51
  # Integração com Streamlit
52
  st.title('A Jornada do Discípulo')
 
53
 
54
+ # Controles do jogador
55
+ col1, col2, col3 = st.columns(3)
56
+ with col1:
57
+ if st.button('Esquerda'):
58
+ player_velocity[0] = -5
59
+ with col2:
60
+ if st.button('Parar'):
61
+ player_velocity = [0, 0]
62
+ with col3:
63
+ if st.button('Direita'):
64
+ player_velocity[0] = 5
65
+ if st.button('Cima'):
66
+ player_velocity[1] = -5
67
+ if st.button('Baixo'):
68
+ player_velocity[1] = 5
69
+
70
+ render_game()