-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgames.py
79 lines (63 loc) · 2.85 KB
/
games.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pygame
from Window import Window
'''
https://colab.research.google.com/drive/1Wo_1joBc29aJPyZAYTCluojcmqRSAXAM#scrollTo=e6rkBMLUC3iR
'''
#inicia o programa do pygames
pygame.init()
pygame.font.init() # textos na tela
objeto = pygame.font.Font('nome_arquivo', 64)#importar a fonte
print('certo')
w = Window(1024, 600) #cria objeto janela com dimensões 600x400
win = pygame.display.set_mode(w.returnWinSize()) #inicializa a janela do jogo
pygame.display.set_caption('Nome_do_Jogo')
win.fill(w.returnColor()) #insere a cor na janela
# criamos uma instância do relógio
clock = pygame.time.Clock()
# Desenhando linhas na tela pygame.draw.line(superficie, cor, ponto_inicial, ponto_final, largura)
pygame.draw.line(win, (255,0,0), (0,0), (512,300), 10)
pygame.draw.line(win, (0,255,0), (0,600), (512,300), 10)
pygame.draw.line(win, (0,0,255), (512,300), (1024,600), 10)
pygame.draw.line(win, (255,255,255), (512,300), (1024,0), 10)
pygame.display.update()
# desenhando circulos na tela pygame.draw.circle(superficie, cor, centro, raio)
pygame.draw.circle(win, (127,127,127), (512,300), 150)
pygame.display.update()
# desenhando retangulo na tela pygame.draw.rect(superficie, cor, retangulo)
ret = pygame.Rect((300,300), (424, 150)) # criando um objeto retangulo - pygame.Rect((x,y), (largura, altura))
pygame.draw.rect(win, (255,127,255), ret)
pygame.display.update()
# inicio do game-loop
run = True
while run:
pygame.display.update() #atualiza a tela
#chamamos o tick do relógio para 30 fps e armazenamos o delta de tempo (diferença de tempo entre um ciclo e outro)
clock.tick(30)
#leitura de eventos
for event in pygame.event.get():
if event.type == pygame.QUIT: #botão "x" utilizado para fechar janela
run = False
if event.type == pygame.MOUSEBUTTONDOWN: #verifica se um botão do mouse foi pressionado
if event.button == 1:
print("O botão esquerdo do mouse foi clicado!")
#superf = objeto.render(text, antialias, cor)
superf = objeto.render('text', True, (0,0,0))
win.blit(superf)
mouseX, mouseY = pygame.mouse.get_pos()
if event.type == pygame.KEYDOWN: #verifica se uma tecla foi pressionada
if event.key == pygame.K_ESCAPE: #caso a tecla "esc" do teclado tenha sido a tecla pressionada, encerramos o loop/jogo
run = False
elif event.key == pygame.K_LEFT:
print("←")
elif event.key == pygame.K_RIGHT:
print("→")
elif event.key == pygame.K_UP:
print("↑")
elif event.key == pygame.K_DOWN:
print("↓")
# event.button == 1 => botão esquerdo
# event.button == 2 => botão do scroll
# event.button == 3 => botão direito
# event.button == 4 => qualquer botão
pygame.font.quit()
pygame.quit()