import pygame import time from game.const import game as G try: pygame.mixer.init() except Exception as e: print(e) PATH = "res/sound" sounds_dic = {} def play(name): global sounds_dic last_time = sounds_dic.get(name) try: if not last_time: sound = pygame.mixer.Sound(G.GAME_PATH + "\\" + PATH + '/' + name + ".wav") sound.set_volume(G.SOUND_VOLUME) sound.play() else: if time.time() - last_time >= 0.1: sound = pygame.mixer.Sound(G.GAME_PATH + "\\" + PATH + '/' + name + ".wav") sound.set_volume(G.SOUND_VOLUME) sound.play() sounds_dic[name] = time.time() except Exception as e: print(e) def playWin(name): try: sound = pygame.mixer.Sound(G.GAME_PATH + "\\" + "res/music" + '/' + name + ".ogg") sound.set_volume(G.SOUND_VOLUME) sound.play() except Exception as e: print(e)