Added keyevent loop

Added Model
This commit is contained in:
2024-07-07 18:45:04 +02:00
parent bf2a04e74a
commit 35fca2dec8
3 changed files with 87 additions and 0 deletions

36
main.py
View File

@@ -16,6 +16,11 @@ PLAYGROUND = pygame.Surface((1024,728))
gamestate = True
pacman = pygame.image.load("models/pacman_1.png")
pacman_posx = 0
pacman_posy = 0
pacman_movespeed = 5
movedirection = {"up":False, "down":False, "left":False, "right":False}
while(gamestate==True):
@@ -27,17 +32,48 @@ while(gamestate==True):
gamestate = False
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_UP):
movedirection["up"] = True
movedirection["down"] = False
print("hoch")
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_DOWN):
movedirection["down"] = True
movedirection["up"] = False
print("runter")
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_LEFT):
movedirection["left"] = True
movedirection["right"] = False
print("links")
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_RIGHT):
movedirection["right"] = True
movedirection["left"] = False
print("rechts")
if(movedirection["up"] == True):
pacman_posy -= pacman_movespeed
if(movedirection["down"] == True):
pacman_posy += pacman_movespeed
if(movedirection["right"] == True):
if(pacman_posx != MAINSCREEN_SIZE[0]):
pacman_posx += pacman_movespeed
print(pacman_posx)
print(MAINSCREEN_SIZE[0])
if(movedirection["left"] == True):
if(pacman_posx != -1):
pacman_posx -= pacman_movespeed
#print(pacman_posx)
#print(pacman_posy)
MAINSCREEN.blit(pacman, (pacman_posx,pacman_posy))
pygame.display.flip()
clock.tick(60)