-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·154 lines (117 loc) · 4.88 KB
/
main.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import pygame, andechserBerg, os
pygame.init()
GESTORBEN = pygame.USEREVENT+1
STARTE_WANDERUNG = pygame.USEREVENT+2
class Lobby:
def __init__(self, fenster:pygame.Surface, toene) -> None:
self.fenster = fenster
self.sprites = pygame.sprite.Group()
self.uhr = pygame.time.Clock()
def anzeigen(self) -> pygame.event.Event:
f = pygame.sprite.Sprite()
f.image = andechserBerg.Helfer.aspect_scale(pygame.image.load(
"media/lobby1.png"), (self.fenster.get_width(), self.fenster.get_width()) )
f.rect = f.image.get_rect()
self.sprites.add(f)
i = 0
while True:
i +=1
for event in pygame.event.get():
if (event.type == pygame.KEYUP):
if(event.key == pygame.K_SPACE):
return pygame.event.Event(STARTE_WANDERUNG)
if(event.key == pygame.K_q):
os._exit(0)
self.sprites.update()
self.sprites.draw(self.fenster)
if (i % 30 <= 15):
andechserBerg.Helfer \
.text("Zum Starten: Hau auf die Leertaste!", self.fenster, (400, self.fenster.get_height() - 300), 50, (255,0,0))
andechserBerg.Helfer.text("Ulti einsetzen: Space", self.fenster, (self.fenster.get_width() - 200, self.fenster.get_height() - 70), 50)
pygame.display.flip()
self.uhr.tick(50)
class Wanderung:
N_MIN_OBJEKTE = 7
MAX_PROMILLE = 15
def __init__(self, fenster:pygame.Surface, toene):
super().__init__()
self.fenster = fenster
self.toene = toene
self.sprites = pygame.sprite.LayeredUpdates()
self.strasse = andechserBerg.Strasse(self.sprites, self.fenster.get_size())
self.strasse.rect.y = -self.strasse.rect.height+self.fenster.get_height()
self.sprites.add(self.strasse)
self.wanderer = andechserBerg.Wanderer(self.toene, self.fenster.get_size())
self.sprites.add(self.wanderer)
self.uhr = pygame.time.Clock()
self.t_kollision_top = -100
self.t_kollision_flop= -100
def wandere(self) -> pygame.event.Event:
i = 0
while True:
i+=1
for event in pygame.event.get():
if (False
or event.type == GESTORBEN
or event.type == pygame.KEYUP and event.key == pygame.K_q):
return event
n_neue_objekte = int (self.N_MIN_OBJEKTE - len(self.sprites) + i / 100)
for j in range(n_neue_objekte):
try:
self.sprites.add(andechserBerg.ZufallsObjekt(self.fenster.get_size(), self.sprites))
except:
pass
for sprite in self.sprites:
if type(sprite) is andechserBerg.ZufallsObjekt and pygame.sprite.collide_rect(self.wanderer, sprite):
if sprite.gut:
self.wanderer.punkte +=1
self.toene.fressen.play()
if (self.wanderer.promille > 0):
self.wanderer.promille -= 1
self.t_kollision_top = pygame.time.get_ticks()
else:
self.wanderer.promille += 1
self.toene.saufen.play()
self.t_kollision_flop = pygame.time.get_ticks()
if self.wanderer.promille > self.MAX_PROMILLE:
self.sterbe()
sprite.kill()
if pygame.time.get_ticks() - self.t_kollision_flop < 100:
self.fenster.fill((255, 0, 0))
elif pygame.time.get_ticks() - self.t_kollision_top < 100:
self.fenster.fill((0, 255, 0))
else:
self.fenster.fill((255, 255, 255))
self.sprites.update()
self.sprites.draw(self.fenster)
andechserBerg.Helfer.text("Menüs verzehrt: " + str(self.wanderer.punkte), self.fenster, (self.fenster.get_width() - 150, self.fenster.get_height() - 50), 30)
andechserBerg.Helfer.text("Promille: {0:.1f}".format(self.wanderer.promille*0.1), self.fenster, (90, self.fenster.get_height() - 50), 30)
pygame.display.flip()
self.uhr.tick(50)
def sterbe(self):
self.fenster.fill((255,255,255))
self.toene.kotzen.play()
andechserBerg.Helfer.text("Magen auspumpen erforderlich", self.fenster, (self.fenster.get_width() / 2, self.fenster.get_height() / 2), 50)
andechserBerg.Helfer.text(str(self.wanderer.punkte) + " Menüs verzehrt", self.fenster, (self.fenster.get_width() / 2, self.fenster.get_height() / 2 + 60), 30)
pygame.display.flip()
pygame.time.wait(3000)
pygame.event.post(pygame.event.Event(GESTORBEN))
class Game:
def __init__(self) -> None:
self.toene = andechserBerg.Toene()
self.fenster = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
self.Lobby = Lobby(self.fenster, self.toene)
def spiele(self):
while True:
lobbyEvent = self.Lobby.anzeigen()
if (lobbyEvent.type == STARTE_WANDERUNG):
self.Wanderung = Wanderung(self.fenster, self.toene)
wanderungsEvent = self.Wanderung.wandere()
if (wanderungsEvent.type == pygame.QUIT):
pygame.quit()
os._exit(0)
else:
pygame.quit()
os._exit(0)
spiel = Game()
spiel.spiele()