SUPPLY_TIME = USEREVENT
定时器,自定义事件
pygame.time.set_timer(SUPPLY_TIME, 30 * 1000)
30*1000(毫秒)为30秒,30秒触发一次
if paused:
pygame.time.set_timer(SUPPLY_TIME, 0)
pygame.mixer.music.pause()
pygame.mixer.pause()
else:
pygame.time.set_timer(SUPPLY_TIME, 30 * 1000)
pygame.mixer.music.unpause()
pygame.mixer.unpause()
暂停的时候,仍有背景音乐,过一会会发现有补给的出现声音
还会有大飞机的出场轰轰声,因为设置了(-1)循环播放
这算一个小BUG,
这音效是在事件这触发,而暂停管的是主逻辑
所以在暂停这添加代码
第一行为把定时器关闭,第二行为关闭音乐,第三行关闭音效。
(这是在if paused 为真时触发)
BULLET2_NUM = 8
for i in range(BULLET2_NUM//2):
bullets[bullet2_index].reset((me.rect.centerx-33, me.rect.centery))
bullets[bullet2_index+1].reset((me.rect.centerx+30, me.rect.centery))
bullet2_index = (bullet2_index + 2) % BULLET2_NUM
普通子弹,屏幕出现4发,以4为一个循环索引值就行
而超级子弹,子弹为8发,子弹速度为12,
需要BULLET2_NUM//2
bullet2_index+1
bullet2_index + 2
才能表现出超级子弹的特征