漫天飞雪效果动画_pygame淡入淡出_scratch转python

"""本程序描述了一幅满天飞雪的动画场景,动态背景之雪山下雪神秘音乐,这是把一个scratch作品用python表现出来的作品."""

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

class Snow(pygame.sprite.Sprite):
    
    def __init__(self,screen_size):
        
        self.sw,self.sh = screen_size
        pygame.sprite.Sprite.__init__(self)
        self.radius = randint(1,8)
        self.image = pygame.Surface((2*self.radius,2*self.radius))
        self.image.set_colorkey((0,0,0))
        pygame.draw.circle(self.image,(250,250,250),(self.radius,self.radius),self.radius) # 画白点
        self.yspeed = self.radius/3                                  # 越大往下移越快
        self.rect = self.image.get_rect()
        self.reset()
        
    def update(self):
        """往下移动雪花"""
        self.rect.move_ip(0,self.yspeed)
        if  self.rect.top > self.sh:self.reset()

    def reset(self):
        """ 设定位置"""
        self.rect.centerx = randint(0,self.sw)
        self.rect.bottom = randint(-2* self.sh,10)        
        

class Fade_background :
    """淡入淡出动态背景类,把一系列帧图像做为背景不断地渐隐渐现的显示"""
    
    def __init__(self,images,size):
        """images:已转换成surface的对象列表,size:屏幕尺寸"""        
        
        self.screen_size = size
        self.images = images                   # images是surface列表
        self.image_index = 0                   # 切换造型从0开始
        self.images_amount = len(images)       # 造型数量
        self.set_shape(self.image_index)       # 设置初始造型和透明度为0
        self.wait_time = 0                     # 淡入后显示的时间

    def update(self):
        """淡入淡出地显示图像,然后换一幅图像"""
        

You must log in to read the rest of this article. Please log in or register as a user.