Added keyevent loop
Added Model
This commit is contained in:
36
main.py
36
main.py
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user