added fixed fps of 60 and changed input axis system to support multiple inputs

This commit is contained in:
steev 2023-12-05 22:07:34 +01:00
parent 5d17e5a487
commit 0b5aef794a
4 changed files with 8 additions and 4 deletions

View File

@ -11,7 +11,8 @@ class App:
__running:bool = True __running:bool = True
__player = pygame.Rect((300,250, 50,50)) __player = pygame.Rect((300,250, 50,50))
__FPS = 60 __FPS = 60
__speed = 1 __speed = 5
__clock = pygame.time.Clock()
def __init__(self, width:int=800, height:int=600, title:str="default title"): def __init__(self, width:int=800, height:int=600, title:str="default title"):
self.__window = Window(width=width, height=height, title=title) self.__window = Window(width=width, height=height, title=title)
@ -20,6 +21,9 @@ class App:
def startGameLoop(self): def startGameLoop(self):
while self.__running: while self.__running:
self.__clock.tick(self.__FPS)
#temporary refresh #temporary refresh
self.__window.getScreen().fill((0,0,0)) self.__window.getScreen().fill((0,0,0))
pygame.draw.rect(self.__window.getScreen(), (255,0,0), self.__player) pygame.draw.rect(self.__window.getScreen(), (255,0,0), self.__player)

View File

@ -12,11 +12,11 @@ class InputHandler:
# construct x and y velocity input axis # construct x and y velocity input axis
if InputHandler.getPressed()[pygame.K_a]: if InputHandler.getPressed()[pygame.K_a]:
xvel = -1 xvel = -1
elif InputHandler.getPressed()[pygame.K_d]: if InputHandler.getPressed()[pygame.K_d]:
xvel = 1 xvel = 1
elif InputHandler.getPressed()[pygame.K_w]: if InputHandler.getPressed()[pygame.K_w]:
yvel = -1 yvel = -1
elif InputHandler.getPressed()[pygame.K_s]: if InputHandler.getPressed()[pygame.K_s]:
yvel = 1 yvel = 1
return tuple((xvel, yvel)) return tuple((xvel, yvel))