So here's my code. What I want is for the player to move down, and while it's moving down, to cycle through images in the sequence (0, 1, 0, -1, 0...) but it doesn't do that.
import pygame, time
pygame.init()
Screen = pygame.display.set_mode((400, 400), 0, 32)
pygame.display.set_caption('Walk around')
GREEN = (0, 255, 0)
Screen.fill(GREEN)
MOVESPEED = 2
moveDown = False
moveUp = False
moveLeft = False
moveRight = False
direction = 'down'
moveCount = 1
imageset = 0
playerimagedown0 = pygame.image.load('C:\Users\Lauren\Documents\RPG dev\down0.gif')
playerimagedown1 = pygame.image.load('C:\Users\Lauren\Documents\RPG dev\down1.gif')
playerimagedownminus1 = pygame.image.load('C:\Users\Lauren\Documents\RPG dev\down-1.gif')
player = pygame.Rect(100, 100, 38, 92)
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
moveDown = True
direction = 'down'
if imageset == 0:
Screen.fill(GREEN)
Screen.blit(playerimagedown0, player)
pygame.display.update()
imageset = moveCount
print '0'
print moveCount
print imageset
elif imageset == -1:
Screen.fill(GREEN)
Screen.blit(playerimagedownminus1, player)
pygame.display.update()
moveCount = -moveCount
imageset = 0
print 'Neg 1'
print moveCount
print imageset
elif imageset == 1:
Screen.fill(GREEN)
Screen.blit(playerimagedown1, player)
pygame.display.update()
moveCount = -moveCount
imageset = 0
print '1'
print moveCount
print imageset
if event.type == pygame.KEYUP:
if event.key == pygame.K_DOWN:
moveDown = False
imageset = 0
if event.key == pygame.K_ESCAPE:
pygame.quit()
if direction == 'down':
Screen.fill(GREEN)
Screen.blit(playerimagedown0, player)
pygame.display.update()
if moveDown == True and player.bottom < 400:
player.top += MOVESPEED
time.sleep(0.02)
I think the problem might have to do with the second and third images not loading properly, because all I see is playerimagedown0. Also, the movement is not smooth.