TypeError: 'tuple' object is not callable Как это исправить?
import pygame
pygame.init()
display_width = 800
display_height = 600
display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("Run Dinosaur! Run!")
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
user_width = 60
user_height = 100
user_x = display_width // 4
user_y = display_height - user_height - 100
clock = pygame.time.Clock()
make_jump = False
jump_counter = 30
def run_game():
global make_jump
game = True
while game:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
key = pygame.key.get_pressed()
if key(pygame.K_SPACE):
make_jump = True
if make_jump == True:
jump()
display.fill((255, 255, 255))
pygame.draw.rect(display, (247, 240, 22), (user_x, user_y, user_width, user_height))
pygame.display.update()
clock.tick(60)
def jump():
global user_y, jump_counter, make_jump
if jump_counter >= -30 / 2.5:
jump_counter -= 1
else:
jump_counter = 30
make_jump = False
run_game()
Traceback (most recent call last):
File "C:/Users/UserSoft/PycharmProjects/dinogame/dinogame.py", line 59, in <module>
run_game();
File "C:/Users/UserSoft/PycharmProjects/dinogame/dinogame.py", line 36, in run_game
if key(pygame.K_SPACE):
TypeError: 'tuple' object is not callable
Ответы (1 шт):
Автор решения: Эникейщик
→ Ссылка
Сравнение делается так:
if key == pygame.K_SPACE:
Вместо этого
if make_jump == True:
достаточно просто
if make_jump: