可爱的Pico动画NPC人物演示.py

可爱的Pico动画NPC人物演示.py


以下是部分代码预览:

"""可爱的Pico动画NPC人物演示.py,这个程序演示的是一些可爱的小精灵时不时地移动走来走去的动画"""

__author__ = "李兴球"
__date__ = "2018年7月"

import pygame
from pygame.locals import *
from random import choice,randint
import time

class Pico():
    counter = 0
    def __init__(self,picoRight,picoLeft,screen):
        self.rightList = picoRight        # 向右走的图形列表
        self.leftList = picoLeft          # 向左走的图形列表
        self.list = [self.leftList,self.rightList]
        self.heading = choice([0,1])      # 朝向,1表示为右,0为左
        self.index = 0                    # 走动的图形列表索引
        self.image = self.list[self.heading][self.index]
        self.rect = self.image.get_rect()
        self.rect.x = randint(0,430)
        self.rect.y = Pico.counter * 50 + randint(140,150)
        pass
        
    def move(self):
        pass
    def draw(self):
        self.screen.blit(self.image,self.rect)

def 播放背景音乐():
    pygame.mixer.init()
    pygame.mixer.music.load("OpusOne.wav")
    pygame.mixer.music.play(-1,0)
    
def main():

        
    pygame.init()
    screen = pygame.display.set_mode((480,360))
    pygame.display.set_caption("可爱的Pico演示NPC人物,作者:李兴球")

    picoRight=[]
    picoRight.append(pygame.image.load("0右.png"))
    picoRight.append(pygame.image.load("1右.png"))
    picoRight.append(pygame.image.load("2右.png"))
    picoRight.append(pygame.image.load("3右.png"))


    picoLeft=[]
    picoLeft.append(pygame.image.load("0左.png"))
    picoLeft.append(pygame.image.load("1左.png"))
    picoLeft.append(pygame.image.load("2左.png"))
    picoLeft.append(pygame.image.load("3左.png"))

    背景图 = pygame.image.load("stage.png")
    Picos = [Pico(picoRight,picoLeft,screen) for i in range(4)]
    for pico in Picos:
        pygame.time.set_timer(pico.暂停事件, randint(960,3600)) # 随机时间 触发

    clock = pygame.time.Clock()
    运行中= True
    while 运行中:
        for event in pygame.event.get():
            if event.type == QUIT:运行中 = False
            pass
          
        for pico in Picos:
            pico.move()
            pico.下一个造型()
            
        screen.blit(背景图,(0,0))
        for pico in Picos:
            pico.draw()
            
        pygame.display.update()
        clock.tick(30)
    pygame.quit()

if __name__ == "__main__":

    播放背景音乐()
    main()

    
        
        

 

下载完整源代码与素材,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客