Search code examples
pythonimagepygameblit

Why do I get an error when I blit an image


I'm Trying to put an enemy into a game That I am making. but when I run the project the python reports a 'TypeError'

File "C:\Users\Zee_S\OneDrive\Desktop\python projects\lil Shooter\Player\Lil Shooter.py", line 153, in draw
    screen.blit(ZwalkRight[self.walkcount//3] (self.x, self.y))
TypeError: 'pygame.Surface' object is not callable
[Finished in 1.4s]

but I looked at my code an it looked fine

class Enemy(object):

    ZwalkRight = [pygame.image.load('ZR1.png'), pygame.image.load('ZR2.png'),]
    ZwalkLeft = [pygame.image.load('ZL1.png'), pygame.image.load('ZL2.png'),]
        
    def __init__(self, x, y, width, height, end):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.end = end
        self.path = [self.x, self.end]
        self.walkcount = 0
        self.velo = 3

    def draw(self,win):
        self.move()
        if self.walkcount + 1 <= 33:
            self.walkcount = 0

        if self.velo > 0:
            screen.blit(self.ZwalkRight[self.walkcount//3] (self.x, self.y))
            walkcount += 1
        else:
            win.blit(self.ZwalkLeft[self.walkcount //3] (self.x, self.y))
            walkcount += 1
    def move(self):
        if self.velo > 0:
            if self.x +  self.velo < self.path[1]:
                self.x += self.velo
            else:
                self.velo = self.velo * -1
                self.walkcount = 0
        else:
            if self.x - self.vel > self.path[0]:
                self.x += self.velo
            else:
                self.velo = self.velo * -1
                self.walkcount = 0

And the problem cant be that I have forgotten to draw the image because I have here

def redrawGameWindow():
    screen.blit(bg, (0,-100))
    man.draw(screen)
    zombie.draw(screen)
    for bullet in bullets:
        bullet.draw(screen)
    pygame.display.update()

    
    pygame.display.update()

man = Player(300, 508, 64, 64)
zombie = Enemy(100, 508, 64, 64, 450)
bullets = []
run = True
while run:
     [...]

can someone fix or even explain why I am getting this error


Solution

  • You’re missing a comma after the closing square bracket in your call to blit:

    screen.blit(self.ZwalkRight[self.walkcount//3] (self.x, self.y))

    screen.blit(self.ZwalkRight[self.walkcount//3], (self.x, self.y))