Сделал код, но почему то он не работает:(
Обсирайте мой код полностью, но найдите пожалуйста ошибку:)
class Player(pygame.sprite.Sprite):
def __init__(self, x, y):
self.speed = 5
self.attack = False
self.right = False
self.left = False
self.current_animation = 1
self.x = x
self.y = y
pygame.sprite.Sprite.__init__(self)
self.current_image = pygame.image.load("sprites/player/player_idle.png").convert_alpha()
self.current_image = pygame.transform.scale(self.current_image, (self.current_image.get_width()*1.2,
self.current_image.get_height()*1.2))
self.image = pygame.image.load("sprites/player/player_idle.png").convert_alpha()
def draw(self):
sc.blit(self.image, self.image.get_rect(center=(player.x - scroll.x, player.y - scroll.y)))
def rotating(self):
player_x = player.x - scroll.x
player_y = player.y - scroll.y
rel_x = pygame.mouse.get_pos()[0] - player_x
rel_y = pygame.mouse.get_pos()[1] - player_y
degress = math.degrees(math.atan2(rel_y, rel_x)) * -1
self.image = pygame.transform.rotate(self.current_image, degress)
def running(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_w]:
self.y -= self.speed
if keys[pygame.K_s]:
self.y += self.speed
if keys[pygame.K_a]:
self.x -= self.speed
if keys[pygame.K_d]:
self.x += self.speed
def attack(self):
if not self.attack and not self.right and not self.left:
self.current_image = pygame.image.load("sprites/player/player_idle.png").convert_alpha()
if pygame.mouse.get_pressed()[0] and not self.attack:
self.attack = True
self.current_animation = 1
anim = random.randint(1,2)
if anim == 1:
self.right = True
self.left = False
if anim == 2:
self.left = True
self.right = False
if self.attack and self.right:
if self.current_animation < 7:
self.current_image = pygame.image.load(f"sprites/player/player_attack_right_{self.current_animation}.png").convert_alpha()
self.current_animation += 1
else:
self.attack = False
if self.attack and self.left:
if self.current_animation < 7:
self.current_image = pygame.image.load(f"sprites/player/player_attack_left_{self.current_animation}.png").convert_alpha()
self.current_animation += 1
else:
self.attack = False
Ошибка
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/PyGames/main_game.py", line 172, in <module>
scene_game()
File "C:/Users/User/PycharmProjects/PyGames/main_game.py", line 165, in scene_game
player.attack()
TypeError: 'bool' object is not callable