-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
121 lines (102 loc) · 3.73 KB
/
Copy pathgame.py
File metadata and controls
121 lines (102 loc) · 3.73 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Engine principal
#
# Modulos usados no jogo
import impata, lab, play, support, vector2d
import pygame, random, sys
from pygame.locals import *
from pygame.sprite import *
# Inicializacao
pygame.init()
tela = pygame.display.set_mode((1024, 768), 0, 32)
pygame.display.set_caption("py Fun k")
#
##############################################
#
# Loop principal
def main (nivel, som_ativado):
# Instanciacao dos objetos e grupos
grupo = RenderUpdates()
labirinto = lab.Labirinto(nivel)
jogador = play.Jogador()
saida = lab.Porta(840, 320)
impatas = Group()
paredes = Group()
objetos = Group()
for impt in range(nivel):
impatas.add(impata.Impata(512, 404, nivel))
som = support.carrega_som("ambient%d.ogg" % nivel)
if som_ativado == 1:
som.play(-1)
pegar = support.carrega_som("catch%d.ogg" % nivel)
colide = support.carrega_som("crash%d.ogg" % nivel)
fim = support.carrega_som('finish.ogg')
# Composicao do background
support.compoe_fundo(tela, "background%d.jpg" % nivel)
labirinto.constroi(tela, nivel)
labirinto.cria_objetos(paredes, objetos, nivel)
objetos.draw(tela)
while True:
# Sair
for evento in pygame.event.get():
if evento.type == QUIT:
som.stop()
return "saiu"
if evento.type == KEYDOWN and evento.key == K_ESCAPE:
som.stop()
return "saiu"
teclas = pygame.key.get_pressed()
direcao = vector2d.Vector2(0, 0)
if teclas[K_LEFT]:
direcao.x = -1 # --> (-1, 0)
if teclas[K_RIGHT]:
direcao.x = +1 # --> (+1, 0)
if teclas [K_UP]:
direcao.y = -1 # --> (0, -1)
if teclas[K_DOWN]:
direcao.y = +1 # --> (0, +1)
support.compoe_fundo(tela, "background%d.jpg" % nivel)
labirinto.constroi(tela, nivel)
objetos.draw(tela)
for impt in impatas:
impt.move()
jogador.move(direcao)
# Movimentos do impata
direcoes = [-1, 1]
for impt in impatas:
if spritecollideany(impt, paredes):
impt.volta()
eixo = random.choice(direcoes)
if eixo == -1:
impt.direcao.y = 0
impt.direcao.x = random.choice(direcoes)
else:
impt.direcao.x = 0
impt.direcao.y = random.choice(direcoes)
tela.blit(impt.image, impt.rect.center)
# Movimentos do jogador
if spritecollideany(jogador, paredes):
jogador.volta()
tela.blit(jogador.image, jogador.rect.center)
if spritecollideany(jogador, objetos):
pegar.play()
spritecollide(jogador, objetos, True)
jogador.pontuacao += 10
if spritecollideany(jogador, impatas) and jogador.vidas > 0:
colide.play()
jogador.vidas -= 1
jogador.posicao = vector2d.Vector2(152, 564)
impatas.add(impata.Impata(512, 404, nivel))
if jogador.vidas == 0:
pygame.time.delay(500)
som.stop()
return "perdeu"
if jogador.rect.colliderect(saida.rect) and jogador.pontuacao == 150:
fim.play()
som.stop()
return "ganhou"
font = support.carrega_fonte('tallpaul.ttf', 60)
text = font.render("Nivel: "+str(nivel)+" Score: "+str(jogador.pontuacao)+" Vidas: "+str(jogador.vidas), 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = tela.get_rect().centerx
tela.blit(text, textpos)
pygame.display.update()