I am making a simple game in pygame. Everything seems to be running correctly and there are no errors, but the code to move the sprite doesn't seem to work. If I set the sprite to move automatically it works fine, so I think it's a problem with the key press detection system. Here's the main game loop:
running = True
while running:
# basic game function checks
pygame.display.flip()
clock.tick(60)
movementtest(testX, testY)
# checking if the game has been closed
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
# movement code
if movingleft:
testX -= testX
if movingright:
testX += testX
if movingup:
testY += testY
if movingdown:
testY -= testY
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
if not movingright:
movingleft = True
if event.key == pygame.K_d:
if not movingleft:
movingright = True
if event.key == pygame.K_w:
if not movingdown:
movingup = True
if event.key == pygame.K_s:
if not movingup:
movingdown = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_a:
movingleft = False
if event.key == pygame.K_d:
movingright = False
if event.key == pygame.K_w:
movingup = False
if event.key == pygame.K_s:
movingdown = False
Why isn't it detecting my key inputs? I will post the pre-loop code if needed.