酷酷的爆炸效果类_Pygame版

"""
   酷酷的爆炸效果类
"""
import time
import pygame
from random import randint
from pygame.locals import *

class Explosion(pygame.sprite.Sprite):
    """
       爆炸效果类,继承自Sprite
    """
    def __init__(self,pos,frames,interval,group):
        """
           frames:帧图,interval:帧播放间隔时间
        """
        pygame.sprite.Sprite.__init__(self)
        self.frames = frames
        # 下面是每个帧图的矩形对象
        self.rects = [f.get_rect(center=pos) for f in frames]        
        self._index = 0               # 帧起始索引
        self._amounts = len(frames)   # 帧数
        self._interval = interval     # 帧播放时间的间隔
        self.start_time = time.time() # 起始时间
        self.set_costume()        
        self.add(group)               # 增加自己到组中

    def set_costume(self):
        """设置造型"""
        self.image = self.frames[self._index]
        self.rect = self.rects[self._index]

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