Персонаж игры не прыгает

IT Денис

Новичок
Пользователь
Май 5, 2020
18
1
3
вот код пишу вроде должен прыгать но он не прыгает помогите пожалуйста
1.Windows
2.Python 3.8
Python:
import pygame

pygame.init()

display_width = 800
display_height = 600

display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("RUN!")

icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)

usr_width = 60
usr_height = 100
usr_x = display_width // 3
usr_y = display_height - usr_height - 100
clock = pygame.time.Clock()

make_jump = False
jump_counter = 30



def gamerun():
    game = True
    global make_jump
    while game:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        keys = pygame.key.get_pressed()
        if keys[pygame.K_SPACE]:
            make_jump = True
        if make_jump:
            jump()


display.fill((255, 255, 255))


pygame.draw.rect(display, (41, 34, 61), (usr_x, usr_y, usr_width, usr_height))

pygame.display.update()
clock.tick(60)


def jump():
    global usr_y, jump_counter, make_jump
    if jump_counter >= -30:
        usr_y -= jump_counter
        jump_counter -= 1
    else:
        jump_counter = 30
        make_jump = False



gamerun()
 
Последнее редактирование:

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Вот пример:
Python:
import pygame
import time

pygame.init()

display_width = 800
display_height = 600

display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("RUN!")

icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)

usr_width = 60
usr_height = 100
usr_x = display_width // 3
usr_y = display_height - usr_height - 100
clock = pygame.time.Clock()

make_jump = False
jump_counter = 30


def gamerun():
    game = True
    global make_jump
    while game:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        keys = pygame.key.get_pressed()
        if keys[pygame.K_SPACE]:
            make_jump = True
        if make_jump:
            jump()
        time.sleep(0.01)
        display.fill((255, 255, 255))
        pygame.draw.rect(display, (41, 34, 61), (usr_x, usr_y, usr_width, usr_height))
        pygame.display.update()


display.fill((255, 255, 255))
pygame.draw.rect(display, (41, 34, 61), (usr_x, usr_y, usr_width, usr_height))

pygame.display.update()
clock.tick(60)


def jump():
    global usr_y, jump_counter, make_jump
    if jump_counter >= -30:
        usr_y -= jump_counter
        jump_counter -= 1
    else:
        jump_counter = 30
        make_jump = False


gamerun()
 
  • Мне нравится
Реакции: Student

Student

throw exception
Команда форума
Администратор
Апр 2, 2020
195
103
43
Москва
@stud_55 крутой пример! :cool: (y)
 

IT Денис

Новичок
Пользователь
Май 5, 2020
18
1
3
Вот пример:
Python:
import pygame
import time

pygame.init()

display_width = 800
display_height = 600

display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("RUN!")

icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)

usr_width = 60
usr_height = 100
usr_x = display_width // 3
usr_y = display_height - usr_height - 100
clock = pygame.time.Clock()

make_jump = False
jump_counter = 30


def gamerun():
    game = True
    global make_jump
    while game:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        keys = pygame.key.get_pressed()
        if keys[pygame.K_SPACE]:
            make_jump = True
        if make_jump:
            jump()
        time.sleep(0.01)
        display.fill((255, 255, 255))
        pygame.draw.rect(display, (41, 34, 61), (usr_x, usr_y, usr_width, usr_height))
        pygame.display.update()


display.fill((255, 255, 255))
pygame.draw.rect(display, (41, 34, 61), (usr_x, usr_y, usr_width, usr_height))

pygame.display.update()
clock.tick(60)


def jump():
    global usr_y, jump_counter, make_jump
    if jump_counter >= -30:
        usr_y -= jump_counter
        jump_counter -= 1
    else:
        jump_counter = 30
        make_jump = False


gamerun()
Спасибо огромное!
 

Форум IT Специалистов