successfully added card snapping

This commit is contained in:
2023-12-12 20:45:01 +01:00
parent a25f4c3eba
commit 77fb62ca5f
8 changed files with 33 additions and 16 deletions

View File

@ -62,15 +62,22 @@ class App:
if event.type == pygame.QUIT:
self.onCleanup()
elif pygame.mouse.get_pressed()[0]: # Wenn linke Maustaste gedrückt wird
print("mousebutton down")
mouse_x, mouse_y = pygame.mouse.get_pos()
mouse_pos = pygame.Vector2(mouse_x, mouse_y)
for card in self.cards:
if card.rect.collidepoint(mouse_pos):
card.setDragging(True)
print(card.getDragging())
# Berechnung des Offset zwischen der Karte und der Mausposition
card.setOffset(mouse_pos - card.getPos())
# card.setOffset(mouse_pos - card.getPos())
for field in self.__world.getBoardFields():
if field.getRect().collidepoint(mouse_pos):
if field.getSide() == "Player":
if field.getType() == "MonsterField" and card.getType() == "MonsterCard":
# todo: resize card so that it fits into the card field
pygame.transform.scale(card.image,(int((field.getRect().width - 10)),int((field.getRect().height - 10))))
card.rect.center = field.getRect().center
card.setDragging(False)
self.__window.getScreen().blit(card.image, field.getRect().center)
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1: # Wenn linke Maustaste losgelassen wird