Анимация и классы в Pygame

Есть игра

import pygame

WIGHT = 1000
HIGHT = 500

pygame.init()
win = pygame.display.set_mode((WIGHT, HIGHT))
pygame.display.set_caption('Super_Trump')
clock = pygame.time.Clock()

walkRight = [
    pygame.image.load('img/Trump_right_1.png'),
    pygame.image.load('img/Trump_right_2.png'),
    pygame.image.load('img/Trump_right_3.png'),
    pygame.image.load('img/Trump_right_4.png'),
    pygame.image.load('img/Trump_right_5.png'),
    pygame.image.load('img/Trump_right_6.png')
]

walkLeft = [
    pygame.image.load('img/Trump_left_1.png'),
    pygame.image.load('img/Trump_left_2.png'),
    pygame.image.load('img/Trump_left_3.png'),
    pygame.image.load('img/Trump_left_4.png'),
    pygame.image.load('img/Trump_left_5.png'),
    pygame.image.load('img/Trump_left_6.png'),
]

playerStand = pygame.image.load('img/Trump_stand.png')

playerJump = pygame.image.load('img/Trump_jump.png')

playerJumpRight = pygame.image.load('img/Trump_right_jump.png')

playerJumpLeft = pygame.image.load('img/Trump_left_jump.png')

isJump = False
jumpCount = 10

jump = False

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.wight = 60
        self.hight = 71
        self.speed = 5
        self.x = 50
        self.y = HIGHT - self.hight - 40
        self.left = False
        self.right = False

    def update(self):
        global lastMove, animCount, jump
        keys = pygame.key.get_pressed()
        if keys[pygame.K_a]:
            self.x -= self.speed
            self.left = True
            self.right = False
            lastMove = 'left'

        elif keys[pygame.K_d]:
            self.x += self.speed
            self.left = False
            self.right = True
            lastMove = 'right'

        else:
            self.left = False
            self.right = False
            self.animCount = 0

        if self.x < 5:
            self.x = 5
        elif self.x > 1000:
            self.x = 1000

        if animCount + 1 >= 30:
            animCount = 0

        if self.left and not jump:
            win_blit = walkLeft[animCount // 5], (x, y)
            animCount += 1
        elif self.right and not jump:
            win_blit = walkRight[animCount // 5], (x, y)
            animCount += 1
        elif jump and not self.right and not self.left:
            win_blit = playerJump, (x, y)
        elif jump and right and not left:
            win_blit = playerJumpRight, (x, y)
        elif jump and not right and left:
            win_blit = playerJumpLeft, (x, y)
        else:
            win_blit = playerStand, (x, y)
        if not (isJump):
            if keys[pygame.K_w] or keys[pygame.K_SPACE]:
                isJump = True
                jump = True
            else:
                if jumpCount >= -10:
                    if jumpCount < 0:
                        y += (jumpCount ** 2) / 2
                    else:
                        y -= (jumpCount ** 2) / 2
                    jumpCount -= 1
                else:
                    isJump = False
                    jumpCount = 10
                    jump = False
player = Player()
all_sprites.add(player)

running = True
while running:
    clock.tick(30)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    all_sprites.update()

    win.blit(bg, (0, 0))
    player.update()
    all_sprites.draw(win)
    pygame.display.update()

pygame.quit()

в картинках можете поставить любые фото, суть вопроса не в этом, а в том можно ли как-то анимировать игрока в его классе или это все писать в цикле, я попытался, постоянно выдает ошибку


Ответы (0 шт):