added old code, fixed it (mostly), merged some new code to the old code, made it mostly runnable
This commit is contained in:
76
New_Client/App.py
Normal file
76
New_Client/App.py
Normal file
@@ -0,0 +1,76 @@
|
||||
import pygame
|
||||
from Classes.Engine.EventHandler import EngineEventHandler
|
||||
from Classes.Engine.InputHandler import InputHandler
|
||||
from Classes.Engine.Logger import Logger
|
||||
from Classes.Engine.TCPClient import TCPClient
|
||||
|
||||
from Classes.Engine.Window import Window
|
||||
from Classes.Game.World import World
|
||||
from Classes.Game.NetworkEvents.Login import Login
|
||||
|
||||
|
||||
class App:
|
||||
|
||||
__running:bool
|
||||
__FPS:int = 60
|
||||
__clock:pygame.time.Clock()
|
||||
__myFont:pygame.font
|
||||
__window:Window
|
||||
__world:World
|
||||
__inputHandler: InputHandler
|
||||
__tcpClient: TCPClient
|
||||
__eventHandler: EngineEventHandler
|
||||
logger:Logger
|
||||
|
||||
def __init__(self, logger:Logger, width:int=1280, height:int=720, title:str="default title"):
|
||||
self.logger = logger
|
||||
|
||||
self.logger.info("initializing dependencies")
|
||||
pygame.init()
|
||||
pygame.font.init()
|
||||
self.__myFont = pygame.font.SysFont('Comic Sans MS', 30)
|
||||
self.__window = Window(width=width, height=height, title=title)
|
||||
self.__world = World(self.logger, self.__window.getScreen())
|
||||
self.__inputHandler = InputHandler()
|
||||
|
||||
# attempt to connect to server
|
||||
try:
|
||||
self.logger.info("logging into server")
|
||||
self.__tcpClient = TCPClient("127.0.0.1", "54322", self.__world, self.__inputHandler)
|
||||
Login(self.__tcpClient) # will login to the server
|
||||
except Exception as e:
|
||||
print(f"failed to login due to error {e}")
|
||||
print("server connection failed or got refused")
|
||||
pass
|
||||
|
||||
def startGameLoop(self):
|
||||
self.__running = True
|
||||
|
||||
while self.__running:
|
||||
|
||||
self.__clock.tick(self.__FPS)
|
||||
|
||||
self.__window.getScreen().fill((0,0,0))
|
||||
|
||||
# render world
|
||||
self.__window.drawWorld(self.__world)
|
||||
|
||||
# updates all cards inside the cards Spritegroup at each step the gameloops does
|
||||
self.__world.getCards().update()
|
||||
self.__world.getHandCards().update()
|
||||
|
||||
# draw groups
|
||||
self.__window.drawSpriteGroup(self.__world.getCards())
|
||||
self.__window.drawSpriteGroup(self.__world.getHandCards())
|
||||
|
||||
self.__eventHandler.handleEvent(pygame.event.get())
|
||||
|
||||
# emits update to the game
|
||||
pygame.display.update()
|
||||
|
||||
self.__running = False
|
||||
|
||||
# ensures the gameloop stops running and the pygame instance is stopped properly
|
||||
def onCleanup(self):
|
||||
self.__running = False
|
||||
pygame.quit()
|
||||
Reference in New Issue
Block a user