added mouse dragging to cards

This commit is contained in:
2023-12-12 18:29:40 +01:00
parent 8c544556ed
commit a25f4c3eba
10 changed files with 64 additions and 24 deletions

View File

@@ -31,10 +31,10 @@ class App:
def startGameLoop(self):
# create sprite groups
cards = pygame.sprite.Group()
self.cards = pygame.sprite.Group()
testMonsterCard = MonsterCard((500,500), "Assets/Cards/MonsterCards/testmonstercard/")
cards.add(testMonsterCard)
testMonsterCard = MonsterCard(pygame.Vector2(500,500), "Assets/Cards/MonsterCards/testmonstercard/", self.__inputHandler)
self.cards.add(testMonsterCard)
while self.__running:
self.__clock.tick(self.__FPS)
@@ -42,14 +42,13 @@ class App:
self.__window.getScreen().fill((0,0,0))
# render world
self.__inputHandler.getMouseHover(self.__world)
self.__window.drawWorld(self.__world)
# update sprite groups
cards.update()
self.cards.update()
# draw groups
self.__window.drawSpriteGroup(cards)
self.__window.drawSpriteGroup(self.cards)
# event handler
self.handleEvent(pygame.event.get())
@@ -62,10 +61,21 @@ class App:
for event in events:
if event.type == pygame.QUIT:
self.onCleanup()
if event.type == pygame.MOUSEBUTTONDOWN:
pass
if event.type == pygame.MOUSEBUTTONUP:
pass
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())
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1: # Wenn linke Maustaste losgelassen wird
for card in self.cards:
card.setDragging(False)
# sets the running state for the gameloop
def setRunning(self, running:bool):