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,15 +31,16 @@ class InputHandler:
# get field under mousbutton
def getMouseHover(self, world:World) -> BoardField:
mouse_pos = self.getMousePos()
xPos = [int(v//world.getCardWidth()) for v in mouse_pos.x]
yPos = [int(v//world.getCardHeifht()) for v in mouse_pos.y]
x_pos = mouse_pos.x / world.getCardWidth()
y_pos = mouse_pos.y / world.getCardHeight()
try:
for field in world.getBoardFields():
for x in xPos:
for y in yPos:
if x == field.getPos().x and y == field.getPos().y:
return field
except IndexError: pass
for field in world.getBoardFields():
field_x = field.getPos().x
field_y = field.getPos().y
field_width = world.getCardWidth() # Annahme: Jedes Feld hat eine Breite von 1 Einheit
field_height = world.getCardHeight() # Annahme: Jedes Feld hat eine Höhe von 1 Einheit
if field_x <= x_pos < field_x + field_width and field_y <= y_pos < field_y + field_height:
return field
return None