added engine base window and applogic
This commit is contained in:
parent
da68c8ee8d
commit
2b073bfdfe
6
Game Client/.vscode/settings.json
vendored
Normal file
6
Game Client/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"pygame",
|
||||
"yvel"
|
||||
]
|
||||
}
|
41
Game Client/Classes/System/App.py
Normal file
41
Game Client/Classes/System/App.py
Normal file
@ -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()
|
23
Game Client/Classes/System/InputHandler.py
Normal file
23
Game Client/Classes/System/InputHandler.py
Normal file
@ -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))
|
||||
|
37
Game Client/Classes/System/Window.py
Normal file
37
Game Client/Classes/System/Window.py
Normal file
@ -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
|
BIN
Game Client/Classes/System/__pycache__/App.cpython-311.pyc
Normal file
BIN
Game Client/Classes/System/__pycache__/App.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
Game Client/Classes/System/__pycache__/Window.cpython-311.pyc
Normal file
BIN
Game Client/Classes/System/__pycache__/Window.cpython-311.pyc
Normal file
Binary file not shown.
BIN
Game Client/Classes/__pycache__/App.cpython-311.pyc
Normal file
BIN
Game Client/Classes/__pycache__/App.cpython-311.pyc
Normal file
Binary file not shown.
BIN
Game Client/Classes/__pycache__/Window.cpython-311.pyc
Normal file
BIN
Game Client/Classes/__pycache__/Window.cpython-311.pyc
Normal file
Binary file not shown.
7
Game Client/main.py
Normal file
7
Game Client/main.py
Normal file
@ -0,0 +1,7 @@
|
||||
import pygame
|
||||
from Classes.System.App import App
|
||||
|
||||
if __name__ == "__main__":
|
||||
pygame.init()
|
||||
game = App()
|
||||
game.onExecute()
|
Loading…
x
Reference in New Issue
Block a user