I am trying to make a platformer and I am stumped about how to code it so that however long you hold the up arrow, it will only cause the y change to change once until you let go and repress it.(There will be double jump but I haven't gotten there yet. I haven't gotten to gravity either.) Here is my code:
import pygame
import time
import random
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
car_width = 64
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Platformer')
clock = pygame.time.Clock()
game_loop():
score = 0
x = (display_width * 0.45)
y = (display_height * 0.8)
y_change = -5
x_change = 0
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -5
elif event.key == pygame.K_RIGHT:
x_change = 5
elif event.key == pygame.K_UP:
y_change = 25
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_change = 0
gameloop()
pygame.quit()
quit()
Can anybody help?