Jul-12-2021, 03:05 PM
Hello,
i am trying to make a platformer game but every time I press a key the following error message:
File "D:\python project\pygametest\pygametest.py", line 39, in redrawwindow
game_window.blit(walkleft(walkcount//3),(x,y))
TypeError: 'pygame.Surface' object is not callable
Here is my code if it helps.
i am trying to make a platformer game but every time I press a key the following error message:
File "D:\python project\pygametest\pygametest.py", line 39, in redrawwindow
game_window.blit(walkleft(walkcount//3),(x,y))
TypeError: 'pygame.Surface' object is not callable
Here is my code if it helps.
import pygame import sys from pygame.constants import K_RIGHT pygame.init() screen_width = 800 screen_hight = 600 game_window = pygame.display.set_mode((screen_width, screen_hight)) pygame.display.set_caption("Window") walkleft = (pygame.image.load("D:\python project\pygametest\idle.png")) walkright = (pygame.image.load("D:\python project\pygametest\idleflip.png")) idle = (pygame.image.load("D:\python project\pygametest\eidle.png")) bg = (pygame.image.load("D:\python project\pygametest\ibg.png")) clock = pygame.time.Clock() x = 368 y = 268 width = 64 hight = 64 vel = 5 is_jump = False jumpcount = 10 left = False right = False walkcount = 0 def redrawwindow(): global walkcount game_window.blit(bg, (0,0)) if walkcount >= 27: walkcount = 0 if left: game_window.blit(walkleft(walkcount//3),(x,y)) walkcount += 1 elif right: game_window.blit(walkright(walkcount//3),(x,y)) walkcount += 1 else: game_window.blit(idle, (x,y)) pygame.display.update() game_running = True while game_running: clock.tick(30) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: game_running = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and x > vel: x -= vel right = False left = True elif keys[pygame.K_RIGHT] and x < screen_width - width - vel: x += vel right = True left = False else: right = False left = False walkcount = 0 if not (is_jump): if keys[pygame.K_SPACE]: is_jump = True right = False left = False walkcount = 0 else: if jumpcount >= -10: neg = 1 if jumpcount < 0: neg = -1 y -=(jumpcount ** 2) / 4 * neg jumpcount -= 1 else: is_jump= False jumpcount = 10 redrawwindow() pygame.quit() sys.exit()