added mouse dragging to cards
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user