removed server added client code

This commit is contained in:
2024-02-28 21:10:21 +01:00
parent 4ff9591f92
commit 57621537c4
35 changed files with 1093 additions and 512 deletions

View File

@ -0,0 +1,53 @@
import pygame
from Classes.Game.BoardField import BoardField
class InputHandler:
# returns pressed key
@staticmethod
def getPressed():
return pygame.key.get_pressed()
# returns pressed key
@staticmethod
def getMousePressed():
return pygame.mouse.get_pressed()
# takes in movement inputs and maps them to x and y axis
@staticmethod
def getInputAxis() -> tuple:
xvel = 0
yvel = 0
# construct x and y velocity input axis
if InputHandler.getPressed()[pygame.K_a] or InputHandler.getPressed()[pygame.K_LEFT]:
xvel = -1
if InputHandler.getPressed()[pygame.K_d] or InputHandler.getPressed()[pygame.K_RIGHT]:
xvel = 1
if InputHandler.getPressed()[pygame.K_w] or InputHandler.getPressed()[pygame.K_UP]:
yvel = -1
if InputHandler.getPressed()[pygame.K_s] or InputHandler.getPressed()[pygame.K_DOWN]:
yvel = 1
return tuple((xvel, yvel))
@staticmethod
def getMousePos() -> pygame.Vector2:
return pygame.Vector2(pygame.mouse.get_pos())
# get field under mousbutton
@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 board_fields:
field_x = field.getPos().x
field_y = field.getPos().y
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

View File

@ -0,0 +1,47 @@
import pygame
class Label:
rect:pygame.rect
image:pygame.image
__screen:pygame.surface
__text:str
__pos:pygame.Vector2
__font:pygame.font
font:pygame.font
__name:str
def __init__(self, name:str, screen:pygame.surface, text:str, pos:pygame.Vector2, size:float=20, color:str="white"):
self.__font = pygame.font.SysFont("Arial", size)
self.font = pygame.font.SysFont("Arial", size)
self.image = self.font.render(text, 1, color)
_, _, w, h = self.image.get_rect()
self.__pos = pos
self.rect = pygame.Rect(self.__pos.x, self.__pos.y, w, h)
self.__screen = screen
self.__text = text
self.__name = name
def getText(self) -> str:
return self.__text
def getFont(self) -> pygame.font:
return self.__font
def getPos(self) -> pygame.Vector2:
return self.__pos
def getName(self) -> str:
return self.__name
def setText(self, newtext:str, color:str="white"):
self.image = self.font.render(newtext, 1, color)
def setFont(self, font:pygame.font, size:float, color:str="white"):
self.__font = pygame.font.SysFont(font, size)
self.change_text(self.text, color)
def setPos(self, pos:pygame.Vector2):
self.__pos = pos
def draw(self):
self.__screen.blit(self.image, (self.rect))

View File

@ -0,0 +1,54 @@
import pygame
from pygame.locals import *
from Classes.Game.BoardField import BoardField
from Classes.Game.World import World
class Window:
__width:int = 800
__height:int = 600 # takes 80% of width which tranlates to 640
__title:str = "python game engine"
__screen:pygame.Surface
__clock:pygame.time.Clock
def __init__(self, width:int=800, height:int=600, title:str="python game engine"):
self.__width = width
self.__height = height
self.__title = title
pygame.init()
self.__screen = pygame.display.set_mode((self.__width, self.__height))
self.__screen.fill((236, 240, 241)) # Hier liegt der Fehler, es muss eine Tuple übergeben werden
pygame.display.set_caption(self.__title)
self.__clock = pygame.time.Clock()
self.__framerate = 60 # Framerate auf 60 FPS festlegen
# set framerate (where the fuck is it?)
def Render(self):
# dear future me figure out what past me did!
pass
def setWidth(self, width:int):
self.__width = width
def setHeight(self, height:int):
self.__height = height
def setTitle(self, title:str):
self.__title = title
def getScreen(self) -> pygame.surface:
return self.__screen
# draws a passed sprite group to the screen
def drawSpriteGroup(self, group:pygame.sprite.Group):
group.draw(self.__screen)
# draws a given group of rectangles onto the screen
def drawWorld(self, world:World):
for field in world.getBoardFields():
pygame.draw.rect(self.__screen, field.getColor(), field.getRect())
for label in world.getLabels():
label.draw()