moved position system over to use vector2

This commit is contained in:
2023-12-11 15:32:33 +01:00
parent 4acb99cc84
commit 8c544556ed
14 changed files with 273 additions and 60 deletions

View File

@@ -1,5 +1,8 @@
import pygame
from Classes.Objects.World import World
from Classes.Objects.BoardField import BoardField
class InputHandler:
# returns pressed key
def getPressed():
@@ -21,4 +24,22 @@ class InputHandler:
yvel = 1
return tuple((xvel, yvel))
def getMousePos(self) -> pygame.Vector2:
return pygame.Vector2(pygame.mouse.get_pos())
# 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]
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
return None