I make a little small mini-game Parkour where the character jumps from platform to platform, but I can’t get the character to move normally. I made another game, and it worked correctly, but this is not. When I hold the left / right arrow key, it moves only one pixel at a time. Here is v
Parkour_MoveLeft=Parkour_MoveRight=Parkour_Jump='no'
Parkour_Speed=1
Parkour_X=0
Parkour_Y=0
Parkour_Rows=0
Parkour_Col=0
Now here is my code for the part of the game that I'm having problems with:
if location=='Parkour':
Window.fill(Black)
WindowW = 700
WindowH = 700
Window=pygame.display.set_mode((WindowW, WindowH),0, 32)
pygame.draw.rect(Window, Blue, Parkour_Character)
num=0
for point in Parkour_Grids:
mat=Parkour_Lvl_1[num]
num+=1
if mat=='a':
point['collide']='no'
if mat=='p':
pygame.draw.rect(Window, Green, point['rect'])
point['collide']='yes'
for point in Parkour_Grids:
if point['collide']=='yes':
if Parkour_Character.colliderect(point['left']):
Parkour_MoveRight='no'
if Parkour_Character.colliderect(point['right']):
Parkour_MoveLeft='no'
if Parkour_Character.colliderect(point['bottom']):
Parkour_MoveUp='no'
if Parkour_Character.colliderect(point['top']):
Parkour_MoveDown='no'
Parkour movement
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_RIGHT:
Parkour_MoveRight='yes'
if event.key == K_LEFT:
Parkour_MoveLeft='yes'
if event.type == KEYUP:
if event.key == K_RIGHT:
Parkour_MoveRight='no'
if event.key == K_LEFT:
Parkour_MoveLeft='no'
if Parkour_MoveLeft=='yes':
Parkour_Character.right-=Parkour_Speed
if Parkour_MoveRight=='yes':
Parkour_Character.right+=Parkour_Speed
Level map
Parkour_Lvl_1=['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','p','p','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','p','p','p','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a']
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
Parkour_Grids.append({'rect':pygame.Rect(Parkour_X, Parkour_Y, 80, 30),'right':1,'left':1,'top':1,'bottom':1,'type':'air','collide':'yes'})
Parkour_X+=80
Parkour_Col+=1
if Parkour_Col==40:
Parkour_Col=0
Parkour_X=0
Parkour_Y+=70
Parkour_Rows+=1
if Parkour_Rows==10:
break
for point in Parkour_Grids:
point['right']=pygame.Rect(point['rect'].left+70,point['rect'].top , 6, 70)
point['left']=pygame.Rect(point['rect'].right-76,point['rect'].top , 6, 70)
point['top']=pygame.Rect(point['rect'].left+6,point['rect'].top-15 , 58, 6)
point['bottom']=pygame.Rect(point['rect'].left+6,point['rect'].bottom+6 , 58,6)
Does anyone have any help on what I can do? This is the same code in another game I made (with different variables), but this one doesn't seem to work.