def __init__(self): pygame.init() self.win = pygame.display.set_mode((1920,1080)) pygame.display.set_caption("The Hoopsters") self.background_image = pygame.image.load("assets/background.png") self.helga = Helga() self.naomi = Naomi() self.bullets = []
class main: def __init__(self): pygame.init() self.win = pygame.display.set_mode((1920, 1080)) pygame.display.set_caption("The Hoopsters") self.background_image = pygame.image.load("assets/background.png") self.helga = Helga() self.naomi = Naomi() self.bullets = [] def remove_bullets(self): for bullet in self.bullets: if bullet.horizontal_coordinate <= 0 or bullet.horizontal_coordinate >= 1920 - bullet.width: self.bullets.remove(bullet) def render_bullets(self): for bullet in self.bullets: bullet.render() def move_bullets(self): for bullet in self.bullets: bullet.move() def check_if_helga_got_hit(self): for bullet in self.bullets: if self.helga.got_hit(bullet): self.bullets.remove(bullet) def check_if_game_should_exit(self): for event in pygame.event.get(): if event.type == pygame.QUIT: return True return False def run_game(self): game_is_running = True while game_is_running: pygame.time.delay(30) game_is_running = not self.check_if_game_should_exit() self.game_is_running = self.check_if_game_should_exit() self.win.blit(self.background_image, (0, 0)) if self.helga.health > 0: self.helga.move() self.naomi.react_to_keypress(self.bullets) self.move_bullets() self.check_if_helga_got_hit() self.naomi.got_hit(self.helga) self.helga.render() if self.naomi.health > 0: self.naomi.render(False) self.render_bullets() self.remove_bullets() else: self.win.blit(load("assets/mitsuwa.png"), (800, 475, 300, 300)) self.naomi.horizontal_coordinate = 600 self.naomi.render(True) pygame.display.update()
def main(): load_config() init_logging() loop = asyncio.get_event_loop() helga = Helga(loop=loop) def ask_exit(signal_name): logging.info("Got signal {}: exiting…".format(signal_name)) helga.shutdown() for signal_name in ('SIGINT', 'SIGTERM'): loop.add_signal_handler(getattr(signal, signal_name), functools.partial(ask_exit, signal_name)) # TODO: Add signal handler for SIGHUP (reload config) try: loop.run_until_complete(helga.get_updates()) finally: loop.close()
'date': datetime.datetime.fromtimestamp(config.getint('message', 'origtime')), 'file': os.path.join(spool_path, wav_file)}) return messages def encode_opus(filename): args = ['opusenc', '--quiet', filename, '-'] with open(filename, 'rb') as ih: proc = subprocess.Popen(args=args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = proc.communicate() if err or len(out) == 0: print('error', err) opus_data = BytesIO(out) # convice aiohttp to set the correct header opus_data.name = 'voicemail.opus' return opus_data if __name__ == '__main__': load_config() init_logging() loop = asyncio.get_event_loop() helga = Helga(loop=loop) messages = [] with shelve.open(os.path.join(config.workdir, 'chat.shelve')) as s: for mail in get_voicemail(): cmd = SendMessage(chat_id=s['teddydestodes'], text='New Voicemail from {caller} at {date}'.format(caller=mail['from'], date=str(mail['date']))) messages.append(helga._execute_command(cmd)) cmd = SendVoice(chat_id=s['teddydestodes'], voice=encode_opus(mail['file'])) messages.append(helga._execute_command(cmd, headers={'content-type': 'audio/opus'})) loop.run_until_complete(asyncio.gather(*messages))