Esempio n. 1
0
 def __init__(self):
     if (SoundManager.instance is None):
         SoundManager.instance = self
     else:
         return
     
     SoundClass = None
     self.play_func = None
     self.stop_func = None
     self.available = True
     
     if (QSound.isAvailable()):
         SoundClasse = QSound
         self.play_func = pyqt_play_sound
         self.stop_func = pyqt_stop_sound
     else:
         try:
             import pygame
             pygame.init()
             pygame.mixer.set_num_channels(12)
             
             SoundClass = pygame.mixer.Sound
             self.play_func = pygame_play_sound
             self.stop_func = pygame_stop_sound
         except:
             QMessageBox.warning(None,'PyAsteroids - Sound',
                 'This platform does not provide sound facilites through Qt nor PyGame. \
                 Sound is disabled')
             
             self.available = False
             return
     
     self.sounds = {}
     
     for sec in ConfigManager.getSections('sounds'):
         self.sounds[sec] = {}
         
         for audio_descr in ConfigManager.getOptions('sounds', sec):
             file, vol = map(str.strip, ConfigManager.getVal('sounds',sec,audio_descr).split('||'))
             vol = float(vol)
             
             sound = SoundClass(file)
             
             if (not (SoundClass is QSound)):
                 sound.set_volume(vol)
             
             self.sounds[sec][audio_descr] = sound
Esempio n. 2
0
 def __init__(self, level_number, level):
     self.level_number = level_number
     
     self.info = {}
     self.fields = set()
     
     self.level = level
     self.player_state = Player.get_instance()
             
     cfg = Config('interface', 'Settings')
     font_name = cfg.get('field_font')
     font_size = cfg.get('field_font_sz')
     self.field_font = FontManager.getFont(font_name)
     self.field_font.setPointSize(font_size)
     self.field_color = QColor.fromRgb(*cfg.get('field_color'))
     
     for f_name in ConfigManager.getOptions('interface', 'Fields'):
         s = ConfigManager.getVal('interface', 'Fields', f_name)
         s = map(str.strip, s.split('||'))
         
         img = QImage('resources/images/'+s[0])
         img_pos = QPoint(*eval(s[1]))
         info_rect = QRect(*eval(s[2]))
         scale = float(s[3])
         
         if (len(s) >= 5):
             font = QFont(self.field_font)
             font.setPointSize(int(s[4]))
         else:
             font = self.field_font
         
         img_w, img_h = img.width(), img.height()
         img_rect = QRect(
             img_pos.x(), img_pos.y(),
             int(img_w*scale), int(img_h*scale)
         )
         
         self.info[f_name] = ''
         
         self.fields.add(Field(f_name, img, img_rect, info_rect, font))
     
     self.radar = Radar.from_config('E-Radar', self)
     self.missile = GuidedMissile.from_config('GuidedMissile', self)