| 1234567891011121314151617181920212223242526272829 |
- import pygame
- from client_local.const import game as G
- from collections import defaultdict
- from datetime import timedelta
- pygame.mixer.init()
- PATH = "res/sound"
- # 用于记录每种音效的上一次播放时间
- last_play_time = defaultdict(lambda: -1)
- # 时间间隔阈值(毫秒)
- TIME_THRESHOLD = 100
- def play(name):
- global last_play_time
- current_time = pygame.time.get_ticks()
- # 检查是否超过时间间隔阈值
- if current_time - last_play_time[name] > TIME_THRESHOLD:
- sound = pygame.mixer.Sound(PATH + '/' + name + ".wav")
- sound.set_volume(G.SOUND_VOLUME)
- sound.play()
- last_play_time[name] = current_time
- def playWin(name):
- sound = pygame.mixer.Sound("res/music" + '/' + name + ".ogg")
- sound.set_volume(G.SOUND_VOLUME)
- sound.play()
|