I'm making a very simple game using pygame to practice. Im trying to make my "player" jump when spacebar is pressed. Here is the loop code I'm trying:
x,y=10,300
movex,movey=0,0
if event.type==KEYDOWN:
if event.key==K_LEFT:
movex = -0.2
elif event.key==K_RIGHT:
movex=+0.2
elif event.key==K_DOWN:
movey=+0.2
elif event.key==K_SPACE:
movey=-0.4
movey=+0.4
if event.type==KEYUP:
if event.key==K_LEFT:
movex = 0
elif event.key==K_RIGHT:
movex=0
elif event.key==K_DOWN:
movey=0
elif event.key==K_SPACE:
movey=0
x+=movex
y+=movey
screen.blit(player,(x,y))
The controls work except for the jump part (when I press the spacebar). It just like slides the player down. Can anyone tell me why it doesn't work and how to fix it?