diff --git a/Game Client/.vscode/settings.json b/Game Client/.vscode/settings.json new file mode 100644 index 0000000..9de5ddc --- /dev/null +++ b/Game Client/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "pygame", + "yvel" + ] +} \ No newline at end of file diff --git a/Game Client/Classes/System/App.py b/Game Client/Classes/System/App.py new file mode 100644 index 0000000..36d6af4 --- /dev/null +++ b/Game Client/Classes/System/App.py @@ -0,0 +1,41 @@ +import pygame +from pygame.locals import * + +from Classes.System.Window import Window +from Classes.System.InputHandler import InputHandler + + +class App: + + __window:Window + __running:bool = True + __player = pygame.Rect((300,250, 50,50)) + __FPS = 60 + __speed = 1 + + def __init__(self, width:int=800, height:int=600, title:str="default title"): + self.__window = Window(width=width, height=height, title=title) + self.startGameLoop() + + def startGameLoop(self): + while self.__running: + #temporary refresh + self.__window.getScreen().fill((0,0,0)) + pygame.draw.rect(self.__window.getScreen(), (255,0,0), self.__player) + + self.__player.move_ip((InputHandler.getInputAxis()[0]*self.__speed),(InputHandler.getInputAxis()[1]*self.__speed)) + + # event handler + for event in pygame.event.get(): + if event.type == pygame.QUIT: + self.onCleanup() + + # emits update to the game + pygame.display.update() + + def setRunning(self, running:bool): + self.__running = running + + def onCleanup(self): + self.__running = False + pygame.quit() \ No newline at end of file diff --git a/Game Client/Classes/System/InputHandler.py b/Game Client/Classes/System/InputHandler.py new file mode 100644 index 0000000..5fc910e --- /dev/null +++ b/Game Client/Classes/System/InputHandler.py @@ -0,0 +1,23 @@ +import pygame + +class InputHandler: + # returns pressed key + def getPressed(): + return pygame.key.get_pressed() + + def getInputAxis() -> tuple: + xvel:int = 0 + yvel:int = 0 + + # construct x and y velocity input axis + if InputHandler.getPressed()[pygame.K_a]: + xvel = -1 + elif InputHandler.getPressed()[pygame.K_d]: + xvel = 1 + elif InputHandler.getPressed()[pygame.K_w]: + yvel = -1 + elif InputHandler.getPressed()[pygame.K_s]: + yvel = 1 + + return tuple((xvel, yvel)) + \ No newline at end of file diff --git a/Game Client/Classes/System/Window.py b/Game Client/Classes/System/Window.py new file mode 100644 index 0000000..9cb1f25 --- /dev/null +++ b/Game Client/Classes/System/Window.py @@ -0,0 +1,37 @@ +import pygame +from pygame.locals import * + +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 + + self.__screen = pygame.display.set_mode((self.__width, self.__height)) + pygame.display.init() + + pygame.display.set_caption = self.__title + + # set framerate + + + def Render(self): + 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 \ No newline at end of file diff --git a/Game Client/Classes/System/__pycache__/App.cpython-311.pyc b/Game Client/Classes/System/__pycache__/App.cpython-311.pyc new file mode 100644 index 0000000..6f39121 Binary files /dev/null and b/Game Client/Classes/System/__pycache__/App.cpython-311.pyc differ diff --git a/Game Client/Classes/System/__pycache__/InputHandler.cpython-311.pyc b/Game Client/Classes/System/__pycache__/InputHandler.cpython-311.pyc new file mode 100644 index 0000000..22552dc Binary files /dev/null and b/Game Client/Classes/System/__pycache__/InputHandler.cpython-311.pyc differ diff --git a/Game Client/Classes/System/__pycache__/Window.cpython-311.pyc b/Game Client/Classes/System/__pycache__/Window.cpython-311.pyc new file mode 100644 index 0000000..242fbcc Binary files /dev/null and b/Game Client/Classes/System/__pycache__/Window.cpython-311.pyc differ diff --git a/Game Client/Classes/__pycache__/App.cpython-311.pyc b/Game Client/Classes/__pycache__/App.cpython-311.pyc new file mode 100644 index 0000000..90821aa Binary files /dev/null and b/Game Client/Classes/__pycache__/App.cpython-311.pyc differ diff --git a/Game Client/Classes/__pycache__/Window.cpython-311.pyc b/Game Client/Classes/__pycache__/Window.cpython-311.pyc new file mode 100644 index 0000000..c689e06 Binary files /dev/null and b/Game Client/Classes/__pycache__/Window.cpython-311.pyc differ diff --git a/Game Client/main.py b/Game Client/main.py new file mode 100644 index 0000000..d243f0c --- /dev/null +++ b/Game Client/main.py @@ -0,0 +1,7 @@ +import pygame +from Classes.System.App import App + +if __name__ == "__main__": + pygame.init() + game = App() + game.onExecute() \ No newline at end of file