如何使动画在pygame中跳转?

时间:2018-07-29 16:21:00

标签: python pygame

所以我试图在pygame中制作一个无限的类似跑步者的游戏。我希望角色具有的唯一功能是跳转(很明显,我希望角色的两个Sprite图像在彼此之间同时更改。我如何使动画跳转?对不起,我不太擅长解释如何我的情况,这是我的代码:

import pygame


screen_width = 800
screen_height = 800
white = (255,255,255)
black = (0,0,0)


class Player(pygame.sprite.Sprite):
    def __init__(self,image,image2,x,y):
        super().__init__()

        self.image = pygame.image.load('dog1.png')
        self.image2 = pygame.image.load('dog3.png')
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.jumping = False


    def jump(self):
        pass





class Platform(pygame.sprite.Sprite):
    def __init__(self,color,x,y,height,width):
        super().__init__()
        self.image = pygame.Surface([width,height])
        self.image.fill(color)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y


#init game
pygame.init()

#set screen
screen = pygame.display.set_mode((screen_width,screen_height))

pygame.display.set_caption("Dino the Russell")

#set clock
clock = pygame.time.Clock()

#load dog image sprites
dog1 = pygame.image.load('dog1.png')
dog2 = pygame.image.load('dog3.png')



#create sprite list
all_sprites_list = pygame.sprite.Group()

player = Player(dog1,dog2,250,415)

platform = Platform(black,0,500,15,800)
all_sprites_list.add(platform)




#create a variable that determines which sprite is active 
dogCurrentImage = 1




gameLoop = True
while gameLoop:

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


    screen.fill((white))

    #current sprite image 
    if (dogCurrentImage == 1):
        screen.blit(dog1, (250,415))

    if (dogCurrentImage == 2):
        screen.blit(dog2,(250,415))

    if (dogCurrentImage==1):
        dogCurrentImage = 2

    else:
        dogCurrentImage = 1

    #key handling:
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_SPACE:



    all_sprites_list.draw(screen)
    pygame.display.update()

    clock.tick(5)

pygame.quit()

0 个答案:

没有答案