I've been working on my code, and I'm trying to write the code so that it teleports the enemy when someone presses the space bar. The only problem is that I can't seem to figure out how the variables work. Everything else in the code works just fine, but it seems that the game can't recognise keyboard input, since the only thing that happens when I start the game is that the heartbeat moves across the line.
Is there anyone who could help me? Thanks in advance!
#Main Loop
While True:
#End the run
if keys[pygame.K_ESCAPE]:
run = False
#Input recognition
event = pygame.event.get()
if keys[pygame.K_SPACE]:
Space = True
pygame.display.flip()
#Code for the movement of the heartbeat
if Space is False:
x += 2.5
if x == 600:
x -= 600
clock.sleep(0.75) #Reset time for next beat
if Space is True:
if x >= 550:
screen.blit(pb, [x, 120])
clock.sleep(0.75)
if x <= 500:
screen.blit(pb, [x, 120])
clock.sleep(0.75)
redrawGameWindow()
I also have the line
Space = False
Earlier in the code.
Any answer helps. :)