moved position system over to use vector2
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user