You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4 KiB

import pygame
from .. import tools,setup
from .. import constants as C
class FlashingCoin(pygame.sprite.Sprite): # 继承pygame精灵类
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.frames = []
self.frame_index = 0
frame_rects = [(1,160,5,8),(9,160,5,8),(17,160,5,8),(9,160,5,8)] # 闪烁
self.load_frames(frame_rects)
self.image = self.frames[self.frame_index] # 使用图片第一帧数
self.rect = self.image.get_rect()
self.rect.x = 280
self.rect.y = 58
self.timer = 0 # 随游戏切换金币帧
def load_frames(self,frame_rects):
sheet = setup.GRAPHICS['item_objects']
for frame_rect in frame_rects:
self.frames.append(tools.get_image(sheet,*frame_rect,(0,0,0), C.BG_MULTI))
def update(self):
self.current_time = pygame.time.get_ticks()
frame_durations = [375,125,125,125] # 每图片帧数时间
if self.timer == 0:
self.timer = self.current_time # 如果初始时间为零改为当前时间
elif self.current_time - self.timer > frame_durations[self.frame_index]: # 此时时间-计时器时间>所在帧应有时间间隔
self.frame_index += 1
self.frame_index %= 4
self.timer = self.current_time # 没交换一次计时器时间调成当下时间
self.image = self.frames[self.frame_index]