I'm new to Python and I've been trying to make a simple game where you can move a square to the left, to the right and make it jump. For the last couple of days I've been trying to make the jump movement without success. Could someone help me?
import pygame
pygame.init()
xscreen, yscreen = 1000, 500
screen = pygame.display.set_mode((xscreen, yscreen))
pygame.display.set_caption("Pygame")
width, height = 50, 50
x, y = 950, 200
vel, jumping_points = 10, 10
run = True
while run:
pygame.time.delay(100)
# Checks if the player wants to quit the game.
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# Checks if a key was pressed and moves the square accordingly.
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and x + width < xscreen:
x += vel
if keys[pygame.K_LEFT] and x > 0:
x -= vel
# Unfinished jump movement.
if keys[pygame.K_SPACE] and y > 0:
while True:
if jumping_points >= -10:
y -= (jumping_points ** 2) / 5
jumping_points -= 1
animation()
else:
jumping_points = 10
break
# Updates the screen surface.
animation()
pygame.quit()
Edit: Removed, not important to the question.