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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
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() |