added server communication between client and server
This commit is contained in:
@ -1,17 +1,18 @@
|
||||
import pygame
|
||||
|
||||
from Classes.Objects.World import World
|
||||
from Classes.Objects.BoardField import BoardField
|
||||
from Classes.Game.BoardField import BoardField
|
||||
|
||||
class InputHandler:
|
||||
# returns pressed key
|
||||
@staticmethod
|
||||
def getPressed():
|
||||
return pygame.key.get_pressed()
|
||||
|
||||
# takes in movement inputs and maps them to x and y axis
|
||||
@staticmethod
|
||||
def getInputAxis() -> tuple:
|
||||
xvel:int = 0
|
||||
yvel:int = 0
|
||||
xvel = 0
|
||||
yvel = 0
|
||||
|
||||
# construct x and y velocity input axis
|
||||
if InputHandler.getPressed()[pygame.K_a] or InputHandler.getPressed()[pygame.K_LEFT]:
|
||||
@ -25,22 +26,23 @@ class InputHandler:
|
||||
|
||||
return tuple((xvel, yvel))
|
||||
|
||||
def getMousePos(self) -> pygame.Vector2:
|
||||
@staticmethod
|
||||
def getMousePos() -> pygame.Vector2:
|
||||
return pygame.Vector2(pygame.mouse.get_pos())
|
||||
|
||||
# get field under mousbutton
|
||||
def getMouseHover(self, world:World) -> BoardField:
|
||||
mouse_pos = self.getMousePos()
|
||||
x_pos = mouse_pos.x / world.getCardWidth()
|
||||
y_pos = mouse_pos.y / world.getCardHeight()
|
||||
@staticmethod
|
||||
def getMouseHover(mouse_pos: pygame.Vector2, world_card_width: int, world_card_height: int, board_fields: list) -> BoardField:
|
||||
x_pos = mouse_pos.x / world_card_width
|
||||
y_pos = mouse_pos.y / world_card_height
|
||||
|
||||
for field in world.getBoardFields():
|
||||
for field in board_fields:
|
||||
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
|
||||
field_width = world_card_width # Annahme: Jedes Feld hat eine Breite von 1 Einheit
|
||||
field_height = world_card_height # 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
|
||||
return None
|
||||
|
@ -1,8 +1,8 @@
|
||||
import pygame
|
||||
from pygame.locals import *
|
||||
|
||||
from Classes.Objects.BoardField import BoardField
|
||||
from Classes.Objects.World import World
|
||||
from Classes.Game.BoardField import BoardField
|
||||
from Classes.Game.World import World
|
||||
|
||||
class Window:
|
||||
__width:int = 800
|
||||
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user