TypeError: 'int' object is not callable

I am new to python. I am making a little game with 2D zombies but an error is displayed when I run the code. I searched and tried everything but nothing worked.
Here is a part of the main code:

for shuriken in game.player.all_projectile:
    shuriken.move()

Here is a part of game.py code:

class Game:
    def __init__(self):
        self.all_monster = pygame.sprite.Group()
        self.all_player = pygame.sprite.Group()
        self.player = Player(self)
        self.all_player.add(self.player)

    def check_collision(self, sprite, group):
        return pygame.sprite.spritecollide(sprite, group, False)

And here is the code of projectile.py(the error report the last line of this code):

class Shuriken(pygame.sprite.Sprite):

    def __init__(self, player, velocity, x):
        super().__init__()
        self.player = player
        self.velocity = velocity
        self.image = pygame.image.load('assets/shuriken.png')
        self.image = pygame.transform.scale(self.image, (40, 40))
        self.rect = self.image.get_rect()
        self.rect.x = player.rect.x + x
        self.rect.y = player.rect.y + 30
        self.velo_adaptation = self.rect.x
        self.origin_image = self.image
        self.angle = 1

    def rotate(self):

        self.angle += -5
        self.image = pygame.transform.rotozoom(self.origin_image, self.angle, 1)
        self.rect = self.image.get_rect(center=self.rect.center)

    def delete(self):
        self.player.all_projectile.remove()


    def move(self):
        self.rect.x = self.velo_adaptation
        self.velo_adaptation += self.velocity
        self.rotate()
        for zombie in self.player.game.check_collision(self, self.player.game.all_monster):
            self.delete()
            zombie.damage(self.player.attack)

        if self.rect.x > 1080:
            self.delete()
 
(Edit)And here is the zombie class:

class Zombie(pygame.sprite.Sprite):

def __init__(self, game):
    super().__init__()
    self.health = 100
    self.game = game
    self.max_health = 100
    self.damage = 5
    self.image = pygame.image.load('assets/zombie.png')
    self.image = pygame.transform.scale(self.image, (150, 150))
    self.rect = self.image.get_rect()
    self.rect.x = 950
    self.rect.y = 550
    self.velocity = 0.2

def damage(self, attack):
    self.health -= attack
    self.update_health_bar()

def update_health_bar(self, surface):

    bar_color = (113, 206, 45)
    bar_position = [self.rect.x + 30, self.rect.y + -10, self.health, 5]
    pygame.draw.rect(surface, bar_color, bar_position)

def forward(self):

    if not self.game.check_collision(self, self.game.all_player):

>Solution :

class Zombie(pygame.sprite.Sprite):
    def __init__(self, game):
        ...
        self.damage = 5

    def damage(self, attack):
        ...

The Zombie class has conflicting definitions for the damage attribute. It can’t be both an integer and a function. Rename one of them.

Leave a Reply