Code: Alles auswählen
def gameloop(self):
while self.playing:
self.input()
self.update()
self.draw()
def input(self):
if pygame.mouse.get_pressed()[0]:
self.mouseDown = True
for dot in self.all_dots:
if not dot.connected and pygame.sprite.collide_circle(self.mouse, dot):
if self.startDot is None:
self.startDot = dot
self.currentDot = dot
else:
self.lines_list.append((self.currentDot.rect.center, dot.rect.center))
dot.connected = True
self.currentDot = dot
else:
if self.mouseDown:
self.check()
if pygame.mouse.get_pressed()[1]:
self.playing = False
pygame.quit()
def update(self):
self.mouse.update_sprite()
self.all_dots.update()
def draw(self):
screen.fill(lightBlue)
self.all_dots.draw(screen)
if self.mouseDown and self.startDot is not None:
pygame.draw.line(screen, white, self.currentDot.rect.center, self.mouse.rect.center, 10)
for line in self.lines_list:
pygame.draw.line(screen, white, line[0], line[1], 10)
self.all_sprites.draw(screen)
pygame.display.flip()
def check(self):
if self.currentDot is self.startDot:
if self.startDot is not None:
self.startDot.connected = False
self.startDot = None
elif self.pattern.lines_list == self.lines_list:
self.playing = False
else:
pygame.quit()