我想不通一种使用pygame和pyganim为我的游戏增加跳跃的方法

时间:2019-06-21 08:20:19

标签: python python-3.x pygame sprite

我需要有关实现跳转的帮助

我尝试了一些教程,但是没有用,任何人都可以帮助我吗 使用pyganim进行角色动画,使用pygame进行游戏。 我要做的是制作一款带有酷炫动画的平台游戏 和邪恶的人物

import pygame  
import pyganim
import sys

pygame.init()
window = pygame.display.set_mode((720,480),0,32)
pygame.display.set_caption('Game')
clock = pygame.time.Clock()

background = pygame.image.load('textures/backgrounds/background.png')
background = pygame.transform.scale(background, (720, 480))

knightsize=pygame.image.load('textures/knight/idle/idle_left/idle_1.png')
knight  = pygame.Rect((0, 480), knightsize.get_size())

left = False
right = False
attacking = False

while True:
        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT]:
                knight.centerx -= 5
                window.blit(background, (0,0))
                run_left.blit(window, knight)
                left = True
                right = False
                attacking = False

        elif keys[pygame.K_RIGHT]:
                knight.centerx += 5
                window.blit(background, (0,0))
                run_right.blit(window, knight)
                left = False
                right = True
                attacking = False

        elif keys[pygame.K_KP0]:
                if left:
                        window.blit(background, (0,0))
                        attack_left.blit(window, knight)
                        attacking = True
                elif right:
                        window.blit(background, (0,0))
                        attack_right.blit(window, knight)
                        attacking = True
                else:
                        window.blit(background, (0,0))
                        attack_right.blit(window, knight)
                        attacking = True

        else:

                if left:
                        window.blit(background, (0,0))
                        idle_left.blit(window, knight)
                elif right:
                        window.blit(background, (0,0))
                        idle_right.blit(window, knight)
                else:
                        window.blit(background, (0,0))
                        idle_right.blit(window, knight)

        attacking = False

        knight.clamp_ip(window.get_rect())
        pygame.display.update()
        clock.tick(60)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

0 个答案:

没有答案