Я пробую прыгать код в моей программе, но персонажи не прыгают. (Элементы управления персонажа 1 - это «a», «d», а элементы управления персонажа 2 - «стрелка влево» и «стрелка вправо». Как получить, чтобы символ 1 прыгал с помощью w, а символ 2 - со стрелкой вверх. что не так с кодом, так как я впервые использую прыжковую механику.
import pygame
pygame.init()
win = pygame.display.set_mode((700, 480))
pygame.display.set_caption("First project")
run = True
red = (255, 0, 0)
green = (0, 255, 0)
def drawbg():
pygame.display.update()
win.fill((255, 255, 255))
class person(object):
def __init__(self, x, y, width, height):
self.x = x
self.y = y
self.width = width
self.height = height
self.vel = 5
self.IsJump = False
self.jumpCount = 10
man = person(100, 400, 50, 60)
man2 = person(500, 400, 50, 60)
while run:
pygame.time.delay(25)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and man2.x > man2.vel:
man2.x -= man2.vel
if keys[pygame.K_RIGHT] and man2.x < 700 - man2.width - man2.vel:
man2.x += man2.vel
if keys[pygame.K_a] and man.x > man.vel:
man.x -= man.vel
if keys[pygame.K_d] and man.x < 700 - man.width - man.vel:
man.x += man.vel
if not man.IsJump and keys[pygame.K_SPACE]:
man.IsJump = True
man.JumpCount = 10
if man.IsJump:
if man.JumpCount >= -10:
neg = 1
if man.JumpCount < 0:
neg = -1
man.y -= (man.JumpCount ** 2) / 2 * neg
man.JumpCount -= 1
else:
man.IsJump = False
man.JumpCount = 10
pygame.draw.rect(win, red, (man.x, man.y, man.width, man.height))
pygame.draw.rect(win, green, (man2.x, man2.y, man2.width, man2.height))
drawbg()
pygame.quit()