예제 #1
0
 def loop(self):
     pygame.event.clear()
     music.stop_music()
     music.play_music(CREDITSMUSIC)
     self._load_credits()
     self._draw_screen()
     pygame.time.delay(200)
     music.stop_music()
     return self.father
예제 #2
0
 def loop(self):
     pygame.event.clear()
     music.stop_music()
     music.play_music(CREDITSMUSIC)
     self._load_credits()
     self._draw_screen()
     pygame.time.delay(200)
     music.stop_music()
     return self.father
예제 #3
0
 def _waitKey(self):
     while True:
         pygame.event.clear()
         event = pygame.event.wait()
         if (event.type == QUIT):
             sys.exit(0)
         elif (pygame.key.get_pressed()[K_RETURN]) or (pygame.key.get_pressed()[K_ESCAPE]):
             music.stop_music()
             return self.father
예제 #4
0
 def toggle_music(self):
     """Toggles the music setting (sets it to off if it's on, sets it to on if it's off)"""
     self.game_data.set_music_on(not self.game_data.is_music_on())
     self.settings_buttons[1].set_images(self.get_music_button_img(),
                                         self.get_music_button_img_h())
     if not self.game_data.is_music_on():
         music.stop_music()
     else:
         self.sound.play_music()
예제 #5
0
    def loop(self):
        while not self.done:
            self.clock.tick(CLOCK_TICS)
            self.screen.blit(self.background, (0,0))    

            for event in pygame.event.get():
                self.control(event)

            self._draw_text()
            pygame.display.flip()
        music.stop_music()
        return self.text
예제 #6
0
def load_game_over(screen_center: Tuple[int, int], screen):
    music.stop_music()
    music.play_game_over_music()
    misc_group.empty()
    obstacles_group.empty()
    gameplay_group.empty()
    misc_group.update()

    game_over_sprite = game_over.Menu()
    misc_group.add(game_over_sprite)

    gameplay_group.update()
    misc_group.update()
예제 #7
0
 def loop(self):
     music.stop_music()
     if (not os.path.exists(HISCORES)) and (self.score <= 0):
         text_list=["HIGH SCORE","I\'m sorry","Nobody has been saved.","Nobody has stopped being zombie"]
         music.play_music(PLAYMUSIC)
         self.draw_screen(text_list)
         return self._waitKey()
     else:
         self.top_scores = self._load_score()
         if self.score > 0:
             self._add()
         text_list = self._convert()
         text_list[0:0]=['HIGH SCORES']
         music.play_music(PLAYMUSIC)
         self.draw_screen(text_list)
         return self._waitKey()
예제 #8
0
    def control(self, event):

        if event.type == QUIT:
            sys.exit(0)

        if event.type == KEYDOWN:
            if event.key == K_DOWN:
                self.control_down = 0
            if event.key == K_UP:
                self.control_up = 0
            if event.key == K_RIGHT:
                self.control_right = 0
            if event.key == K_LEFT:
                self.control_left = 0
            if event.key in (K_SPACE, K_s):
                self.hero.twist_right()
                music.play_scream()
            if event.key == K_a:
                self.hero.twist_left()
                music.play_scream()

            if event.key == K_ESCAPE:
                pygame.mixer.music.set_volume(0.5)
                mem = Menu(self.screen, self.options,
                           "Do you want to quit?").loop()
                pygame.mixer.music.set_volume(1.0)

                if mem == self.father:
                    music.stop_music()
                    self.exit = True

        if event.type == KEYUP:
            if event.key == K_DOWN:
                self.control_down = -1
            if event.key == K_UP:
                self.control_up = -1
            if event.key == K_RIGHT:
                self.control_right = -1
            if event.key == K_LEFT:
                self.control_left = -1
예제 #9
0
    def control(self, event):
        
        if event.type == QUIT:
            sys.exit(0)

        if event.type == KEYDOWN:
            if event.key == K_DOWN:
                self.control_down = 0
            if event.key == K_UP:
                self.control_up = 0
            if event.key == K_RIGHT:
                self.control_right = 0
            if event.key == K_LEFT:
                self.control_left = 0
            if event.key in(K_SPACE, K_s):
                self.hero.twist_right()
                music.play_scream()
            if event.key == K_a:
                self.hero.twist_left()
                music.play_scream()

            if event.key == K_ESCAPE:
                pygame.mixer.music.set_volume(0.5)
                mem = Menu(self.screen, self.options, "Do you want to quit?").loop()
                pygame.mixer.music.set_volume(1.0)

                if mem == self.father:
                    music.stop_music()
                    self.exit = True

        if event.type == KEYUP:
            if event.key == K_DOWN:
                self.control_down = -1
            if event.key == K_UP:
                self.control_up = -1
            if event.key == K_RIGHT:
                self.control_right = -1
            if event.key == K_LEFT:
                self.control_left = -1
예제 #10
0
def main():
    #Initialize 
    pygame.init()
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption(WINDOW_TITLE)
    icon = utils.load_image(ICON, (0,0,0))
    pygame.display.set_icon(icon)

    #Introduction
    images = [utils.load_image(image) for image in INTRO_IMAGES]
    visual = Visual(screen, images, INTRO_TIMES)
    music.play_music(INTROMUSIC, 1)
    visual.loop()
    music.stop_music()
    
    #Shooter opcion
    opcion = menu
    while opcion is not exit:
        change = opcion(screen).loop()
        if change:
            opcion = change
    opcion()        #Exit
예제 #11
0
    def _draw_screen(self):
        pygame.display.set_caption(WINDOW_TITLE)
        background = utils.load_image(CREDITIMAGE)

        clock = pygame.time.Clock()
        separator = 3

        title = 'CREDITS'
        title_img = self.font3.render(title, True, WHITE)
        title_img2 = self.font3.render(title, True, BLUE)
        topleft = (background.get_rect().width -
                   title_img.get_rect().width) / 2, 30
        topleft2 = (
            (background.get_rect().width - title_img.get_rect().width) /
            2) - separator, 30 - separator
        background.blit(title_img2, topleft2)
        background.blit(title_img, topleft)

        self.screen.blit(background, (0, 0))
        pygame.display.flip()
        hor_step = self.font2.get_height()

        while True:
            for text_list in self.credits:
                done = False
                timeloop = 0
                state = 0
                xFinal = 0

                while not done:
                    clock.tick(CLOCK_TICS)
                    pygame.display.flip()
                    self.screen.blit(background, (0, 0))
                    y = hor_step + 340

                    timeloop += 1
                    if timeloop == CLOCK_TICS:
                        state = 1
                        done = True

                    for i, text_item in enumerate(text_list):
                        img = self.font2.render(text_item, True, WHITE)
                        img2 = self.font2.render(text_item, True, BLUE)
                        x2 = self.screen.get_width() / 2
                        if (state == 0) and (i % 2 == 0):
                            x1 = x2 - ((WIDTH * 0.86) * (50 - timeloop) / 50)
                        elif (state == 0) and (i % 2 == 1):
                            x1 = x2 + ((WIDTH * 0.86) * (50 - timeloop) / 50)
                        else:
                            x1 = x2

                        if self._verifyKey():
                            music.stop_music()
                            return self.father

                        x = (x1 + (x2 - x1) * (1 - math.exp(-timeloop / 20.0)))
                        x -= img.get_width() / 2
                        self.screen.blit(img2, (x - separator, y - separator))
                        self.screen.blit(img, (x, y))
                        y += hor_step + 10

                pygame.time.delay(100)
                if self._verifyKey():
                    music.stop_music()
                    return self.father
                pygame.time.delay(100)

                done = False
                timeloop = CLOCK_TICS

                while not done:
                    clock.tick(CLOCK_TICS)
                    pygame.display.flip()
                    self.screen.blit(background, (0, 0))
                    y = hor_step + 340

                    timeloop -= 1
                    if timeloop == 0:
                        done = True

                    for i, text_item in enumerate(text_list):
                        img = self.font2.render(text_item, True, WHITE)
                        img2 = self.font2.render(text_item, True, BLUE)
                        #x2 = self.screen.get_width()/2
                        if (i % 2 == 0):
                            x1 = (x2 + ((WIDTH * 0.86) * (50 - timeloop) / 50))
                        elif (i % 2 == 1):
                            x1 = (x2 - ((WIDTH * 0.86) * (50 - timeloop) / 50))
                        x = (x1 + (x2 - x1) * (1 - math.exp(-timeloop / 20.0)))
                        x -= img.get_width() / 2

                        if self._verifyKey():
                            music.stop_music()
                            return self.father

                        self.screen.blit(img2, (x - separator, y - separator))
                        self.screen.blit(img, (x1 - x2, y))
                        y += hor_step + 10

                if self._verifyKey():
                    music.stop_music()
                    return self.father

            pygame.time.delay(200)
예제 #12
0
from microbit import display, accelerometer, sleep, button_a, button_b
from music import pitch, stop as stop_music


def updown():
    for p in range(10, 1000, 10):
        pitch(p, wait=False)
        sleep(10)
    for p in range(1000, 10, -10):
        pitch(p, wait=False)
        sleep(10)


def accel():
    while not button_a.is_pressed():
        p = abs(accelerometer.get_z())
        pitch(p, wait=False)
        sleep(10)


while True:
    stop_music()
    display.show('?')
    if button_a.is_pressed():
        updown()
    if button_b.is_pressed():
        accel()
    sleep(10)
예제 #13
0
    def _draw_screen(self):
        pygame.display.set_caption(WINDOW_TITLE)
        background = utils.load_image(CREDITIMAGE)

        clock = pygame.time.Clock()
        separator = 3

        title = 'CREDITS'
        title_img = self.font3.render(title, True, WHITE)
        title_img2 = self.font3.render(title, True, BLUE)
        topleft = (background.get_rect().width - title_img.get_rect().width) / 2, 30
        topleft2 = ((background.get_rect().width - title_img.get_rect().width) / 2)-separator, 30-separator
        background.blit(title_img2, topleft2)
        background.blit(title_img, topleft)
 
        self.screen.blit(background, (0, 0))
        pygame.display.flip()
        hor_step = self.font2.get_height()

        while True:
            for text_list in self.credits:
                done = False
                timeloop = 0
                state = 0
                xFinal = 0

                while not done:
                    clock.tick(CLOCK_TICS)
                    pygame.display.flip()
                    self.screen.blit(background, (0, 0))
                    y = hor_step + 340

                    timeloop += 1
                    if timeloop == CLOCK_TICS:
                        state = 1
                        done = True

                    for i,text_item in enumerate(text_list):
                        img = self.font2.render(text_item, True, WHITE)
                        img2 = self.font2.render(text_item, True, BLUE)
                        x2 = self.screen.get_width()/2
                        if (state == 0) and (i%2 == 0):
                            x1 = x2 - ((WIDTH * 0.86) * (50 - timeloop) / 50)
                        elif (state == 0) and (i%2 == 1):
                            x1 = x2 + ((WIDTH * 0.86) * (50 - timeloop) / 50)
                        else:
                            x1=x2
 
                        if self._verifyKey():
                            music.stop_music()
                            return self.father

                        x = (x1+(x2-x1)*(1-math.exp(-timeloop/20.0)))
                        x -= img.get_width()/2
                        self.screen.blit(img2, (x-separator, y-separator))
                        self.screen.blit(img, (x, y))
                        y += hor_step + 10

                pygame.time.delay(100)
                if self._verifyKey():
                    music.stop_music()
                    return self.father
                pygame.time.delay(100)

                done = False
                timeloop = CLOCK_TICS

                while not done:
                    clock.tick(CLOCK_TICS)
                    pygame.display.flip()
                    self.screen.blit(background, (0, 0))
                    y = hor_step + 340

                    timeloop -= 1
                    if timeloop == 0:
                        done = True

                    for i,text_item in enumerate(text_list):
                        img = self.font2.render(text_item, True, WHITE)
                        img2 = self.font2.render(text_item, True, BLUE)
                        #x2 = self.screen.get_width()/2
                        if (i%2 == 0):
                            x1 = (x2 + ((WIDTH * 0.86) * (50 - timeloop) / 50))
                        elif (i%2 == 1):
                            x1 = (x2 - ((WIDTH * 0.86) * (50 - timeloop) / 50))
                        x = (x1+(x2-x1)*(1-math.exp(-timeloop/20.0)))
                        x -= img.get_width()/2

                        if self._verifyKey():
                            music.stop_music()
                            return self.father
                        
                        self.screen.blit(img2, (x-separator, y-separator))
                        self.screen.blit(img, (x1-x2, y))
                        y += hor_step + 10

                if self._verifyKey():
                    music.stop_music()
                    return self.father

            pygame.time.delay(200)
예제 #14
0
        spider.draw(screen)
        for bullet in stinger.all_bullets:
            bullet.draw(screen)
        for shot in venom.all_shots:
            shot.draw(screen)
        for smash in hand.all_hands:
            smash.draw(screen)

        pygame.display.flip()

        #events
        for event in pygame.event.get():
            if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN
                                             and event.key == pygame.K_ESCAPE):
                menu = 0
                music.stop_music()
            else:
                #convert mouse coordinates if needed
                event2 = event
                #this is the most unpythonic code ever written. It has to be done, as event objects are immutable
                if event.type == pygame.MOUSEBUTTONDOWN or event.type == pygame.MOUSEBUTTONUP:
                    event2 = pygame.event.Event(
                        event.type,
                        pos=event.pos - Vec2d(screen.offset, 0),
                        button=event.button)  #compensate for  screen movement
                elif event.type == pygame.MOUSEMOTION:
                    event2 = pygame.event.Event(event.type,
                                                pos=event.pos -
                                                Vec2d(screen.offset, 0))
                spider.proccess_event(event2)
예제 #15
0
def tuling_reply(msg):

    #####let robot who is me
    #    if msg['FromUserName'] == my_ID:
    #        return 'I know you'
    #####send command
    #    get_IP = ['*ip','*IP']
    #    for i in get_IP:
    #            if msg['Text'] == i:
    #                (status_cmd,output_cmd) = commands.getstatusoutput('ls')
    #                return u'return : '+str(status_cmd)+u'\nresult : \n' + str(output_cmd)

    #    cf = ConfigParser.ConfigParser()
    #    cf.read('admin.conf')

    #######  get robot switch and admin ID ######### now disable by Pedro
    #    robot_switch = cf.get('switch','RobotSwitch')
    #    my_ID = cf.get('admin','ID')
    #    if msg['Text'].startswith('**'):
    #        cf = ConfigParser.ConfigParser()
    #        cf.read('admin.conf')
    #        stop_cmd = ['baibai','bai','bye','byebye','shutdown','stop','close']
    #        start_cmd = ['hi','hello','open','girl','start']
    #        if robot_switch == 'True':
    #        if True:
    #            for i in stop_cmd:
    #                if i == msg['Text'][2:]:
    #                    cf.set('switch','RobotSwitch','False')
    #                    cf.write(open("admin.conf","w"))
    #                    return 'robot shutdown successfully'
    #
    #        else:
    #            for i in start_cmd:
    #                if i == msg['Text'][2:]:
    #                    cf.set('switch','RobotSwitch','True')
    #                    cf.write(open("admin.conf","w"))
    #                    return 'robot reboot successfully'

    ####send message to admin
    admin_id = itchat.search_friends(name=info.admin_name)[0]['UserName']
    if msg['FromUserName'] != admin_id:
        itchat.send(
            u'I received %s\u2005 %s' %
            (msg['User']['NickName'], msg['Content']), admin_id)

#my_ID will change when you login after logoff
    if msg['Text'].startswith('*'):
        ######  help  ##############
        if msg['Text'][1:] == 'help':
            return '''******************
*help                               --get this message
*setadmin                      --XXXX
speakXXXX                    --speak XXXX by sounder
糗百+页数(1/2/3...)      --爬取糗百纯文本内容
天气+地点                      --查询天气
温度                                 --查询宿舍温度
[音乐]
播放                                 --音乐播放+[歌曲序号]
停止                                 --音乐停止/音乐暂停
更新列表                         --音乐更新
读取列表                         --音乐列表+[列表页数]
[get fil/img/vid/msg]
/Pedro/python/file/    <----file saved in this path when you send /img/vid/fil/voi to it
*get+fil/img/vid/msg+:/!+filepath    <---- if you get the file in /Pedro/python/file/XXX pls use '!',or, use ':' with whole path
******************
'''

######  set admin ID #######
        cf = ConfigParser.ConfigParser()
        cf.read(info.admin_file)
        my_ID = cf.get('admin', 'ID')
        if msg['Text'][1:] == 'setadmin':
            cf.set('admin', 'ID', msg['FromUserName'])
            cf.write(open(info.admin_file, "w"))
            return 'set You as Admin successfully !'

######  if is admin , run command  #######
        if msg['FromUserName'] == my_ID:

            ########music function   not ready#######
            #            if msg['Text'][1:] == 'close':
            #                close_music()
            #                return 'music OFF'
            #            elif msg['Test'][1:6] == 'play:':
            #                itchat.send(interact_select_song(msg['Text'][6:]),my_ID)
            #            else:
            if msg['Text'][1:4] == 'get':
                ##########   *get[img,fil,msg,vid]:[][filename]:[path]
                get_file(msg['Text'][4:7], msg['Text'][7], msg['Text'][8:])
                return 'post file to you successfully,pls check!'
            else:
                (status_cmd,
                 output_cmd) = commands.getstatusoutput(msg['Text'][1:])

                return u'return : ' + str(status_cmd) + u'\nresult : \n' + str(
                    output_cmd)
        else:
            return 'Wrong admin ID, pls check'
#    elif robot_switch == 'True':

######  speak words you send me  #######
    if msg['Text'].startswith('speak'):
        cf = ConfigParser.ConfigParser()
        cf.read(info.admin_file)
        token = cf.get('token', 'key')
        url = 'http://tsn.baidu.com/text2audio?tex="%s"&lan=zh&per=0&pit=1&spd=7&cuid=9805555&ctp=1&tok=%s' % (
            msg['Text'][5:].strip().replace(' ', ',').replace('\n',
                                                              '。'), token)
        os.system('mpg123  "%s" & ' % url)
        return 'speak words successfully'

#########  音乐  #######
    if msg['Text'].startswith(u'音乐'):
        if msg['Text'][2:].startswith(u'暂停') or msg['Text'][2:].startswith(
                u'停止'):
            return music.stop_music()
        elif msg['Text'][2:].startswith(u'更新'):
            return music.update_music()
        elif msg['Text'][2:].startswith(u'列表'):
            if len(msg['Text']) == 4:
                return music.list_music('1')
            else:
                return music.list_music(msg['Text'][4:])

        elif msg['Text'][2:].startswith(u'播放'):
            if len(msg['Text']) == 4:
                return music.play_music('1')
            else:
                return music.play_music(msg['Text'][4:])

#########  temperature  #######
    if msg['Text'].startswith(u'温度'):
        if len(msg['Text']) == 2:
            return str(temperature.temp())

#########  糗百  #######
    if msg['Text'].startswith(u'糗百'):
        if len(msg['Text']) == 2:
            page = '1'
        elif msg['Text'][2:].isdigit():
            page = msg['Text'][2:]
        else:
            page = '1'
        (status_cmd, output_cmd) = commands.getstatusoutput(
            'python /Pedro/python/functions/qiubai.py ' + page)

        return u'return : ' + str(status_cmd) + u'\nresult : \n' + str(
            output_cmd.decode('utf-8'))

########  天气   #######
    if msg['Text'].startswith(u'天气'):
        if len(msg['Text']) == 2:
            local = '东丽'
        else:
            local = msg['Text'][2:]
        (status_cmd, output_cmd) = commands.getstatusoutput(
            'python /Pedro/python/functions/weather.py ' + local)
        if status_cmd != 0:
            return u'天气查询失败,请输入正确地址'
        return u'return : ' + str(status_cmd) + u'\nresult : \n' + str(
            output_cmd.decode('utf-8'))
######### reply in normal #######
    defaultReply = 'I received: ' + msg['Text']
    ######### reply by tuling #######
    reply = get_response(msg['Text'])
    return reply or defaultReply
    return
예제 #16
0
 def beGameover(cls):
     cls.state = "IDLE"
     music.stop_music()
     music.sfx_death()
예제 #17
0
def process(query):

    if 'play' in query and 'music' not in query:
        answer = get_answer_from_memory('play')
    else:
        answer = get_answer_from_memory(query)

    if answer == "get time details":
        return ("Time is " + get_time())

    elif answer == "check internet connection":
        if check_internet_connection():
            return "internet is connected"
        else:
            return "internet is not connected"

    elif answer == "tell date":
        return "Date is " + get_date()

    elif answer == "on speak":
        return turn_on_speech()

    elif answer == "off speak":
        return turn_off_speech()

    elif answer == "close browser":
        close_browser()
        return "closing browser"

    elif answer == "open facebook":
        open_facebook()
        return "opening facebook"

    elif answer == "open google":
        open_google()
        return "opening google"

    elif answer == "play music":
        return play_music()

    elif answer == 'play':
        return play_specific_song(query)

    elif answer == "pause music":
        return pause_music()

    elif answer == "stop music":
        return stop_music()

    elif answer == "next song":
        return next_song()

    elif answer == "previous song":
        return previous_song()

    elif answer == 'change wallpaper':
        return change_wallpaper()

    elif answer == 'get news':
        return get_news()

    elif answer == 'change name':
        output("Okay! what do you want to call me")
        temp = take_input()
        if temp == assistant_details.name:
            return "Can't change. I think you're happy with my old name"
        else:
            update_name(temp)
            assistant_details.name = temp
            return "Now you can call me " + temp

    else:
        output("Dont know this one should i search on internet?")
        ans = take_input()
        if "yes" in ans:
            answer = check_on_wikipedia(query)
            if answer != "":
                return answer

        else:
            output("can you please tell me what it means?")
            ans = take_input()
            if "it means" in ans:
                ans = ans.replace("it means", "")
                ans = ans.strip()

                value = get_answer_from_memory(ans)
                if value == "":
                    return "Can't help with this one "

                else:
                    insert_question_and_answer(query, value)
                    return "Thanks i will remember it for the next time"

            else:
                return "can't help with this one"