Ejemplo n.º 1
0
def mainrun(scr_params=((640,480),0,32)):
    """mainrun(scr_params=((640,480),0,32)) - screen of main menu ImpactuX"""
    #print "FULLSCREEN:--- "+str(FULLSCREEN)
    i_exit = functions.iExit() #button functions
    i_run = functions.iRun()
    i_setup = functions.iSetup()
    i_record = functions.iRecord()
    i_restore = functions.iRestore()
    
    #ending_play=functions.Ending_play()
    button_press_checking=functions.Button_press_checking()
    
    #init vars
    
    f_s = 20 #font size
    b_s = 5 #border size
    
    bgif="."+os.sep+"pic"+os.sep+"bgstart.jpg"
    i_icon="."+os.sep+"pic"+os.sep+"impactuX.png"
    
    #soif1="."+os.sep+"sounds"+os.sep+"s1.ogg"
    
    pygame.init()
    
    #screen=pygame.display.set_mode(scr_params[0], FULLSCREEN, scr_params[2])
    screen=pygame.display.set_mode(scr_params[0], scr_params[1], scr_params[2])
    
    pygame.display.set_caption("ImpactuX Menu")
    m_icon=pygame.image.load(i_icon).convert_alpha()
    pygame.display.set_icon(m_icon)
    
    background=pygame.image.load(bgif).convert()
    #m_icon=pygame.image.load(i_icon).convert()
    
    textbuttons = \
    [objects.t_button(285, 40, "Start new game", i_run, f_s, b_s, BLACK, WHITE), \
    objects.t_button(270,90, "Restore game", i_restore, f_s, b_s, BLACK, GREEN), \
    objects.t_button(295,140, "Options", i_setup, f_s, b_s, BLACK, WHITE), \
    objects.t_button(300,190, "Score", i_record, f_s, b_s, BLACK, GREEN), \
    objects.t_button(305,240, "EXIT", i_exit, f_s, b_s, BLACK, RED)]
    
    textbuttons = objects.WidgetsPack(250, 70, 65, False, textbuttons)
    
    
    #textlabels = [objects.t_label(270, 390, "ImpactuX", i_exit, 32, 1, RED, None),]
    textbuttons.add_wig(objects.t_label(270, 390, "ImpactuX", i_exit, 32, 1, RED, None))
    #objects.t_button(315,240, "EXIT", ending_play, 20, 5, BLACK, red)]

    #font1=pygame.font.Font("."+os.sep+"fonts"+os.sep+"LiberationSans-Regular.ttf", 18)
    clock = pygame.time.Clock()
    
    run_now = True

####### main loop section #######
    while run_now:
        clock.tick(30) 
        #t=pygame.time.delay(100)
        for event in pygame.event.get():
            if event.type == QUIT:
                i_exit()
                #ending_play()
                return i_exit()
                
            if event.type == KEYUP:
                if event.key == K_ESCAPE:
                    run_now=False
                    return i_exit()

            elif event.type == MOUSEBUTTONDOWN:
                x_n0,y_n0=event.pos
                check_tb=button_press_checking(x_n0, y_n0, textbuttons.w_list)
                if check_tb[0]:
                    check_tb[1].ch_state(event.type)
    
            elif event.type == MOUSEMOTION:
                x_n0,y_n0=event.pos
                check_tb=button_press_checking(x_n0, y_n0, textbuttons.w_list)
                if check_tb[0]:
                    check_tb[1].ch_state(event.type)

            elif event.type == MOUSEBUTTONUP:
                if int(event.button) == 1:
                    x_n0,y_n0=event.pos
                    
                    check_tb=button_press_checking(x_n0, y_n0, textbuttons.w_list)
                    if check_tb[0]:
                        check_tb[1].ch_state(event.type)
                        return check_tb[1].doing()
                       
        screen.blit(background, (0,0))
        
        textbuttons.show_at(screen)
        #for b_obj in textbuttons.w_list:
        #    b_obj.show_at(screen)

        #for b_obj in textlabels:
        #    b_obj.show_at(screen)
    
        #pygame.display.update()
        pygame.display.flip()
Ejemplo n.º 2
0
def mainrun(scr_params=((640,480),0,32)):
    """mainrun(scr_params=((640,480),0,32), lvl=0 g_score=0) - screen of level story 
    scene in ImpactuX"""
    i_exit=functions.iExit() #button functions
    i_run=functions.iRun()
    i_menu=functions.iMenu()
    i_restore=functions.iRestore()
    i_record=functions.iRecord()

    
    #ending_play=functions.Ending_play()
    button_press_checking=functions.Button_press_checking()
    
    #init vars
    f_s = 20 #font size
    b_s = 5 #border size
    
    bgif="."+os.sep+"pic"+os.sep+"bgset.jpg"

    pygame.init()
    
    screen=pygame.display.set_mode(scr_params[0], scr_params[1], scr_params[2])
    
    background=pygame.image.load(bgif).convert()

    
    m_list=pygame.display.list_modes()
    m_list.sort()
    m_index=m_list.index(scr_params[0])


    textbuttons = \
    [objects.t_button(55, 430, "Save", i_run, f_s, b_s, BLACK, GREEN), \
    objects.t_button(295,430, "Cancel", i_menu, f_s, b_s, WHITE, RED), \
    objects.t_button(555,430, "EXIT", i_exit, f_s, b_s, BLACK, RED)]
    
    textbuttons = objects.WidgetsPack(30, 430, 250, True, textbuttons)
    if scr_params[1]==0:
        b1_l="Set Fullscreen"
    else:
        b1_l="Set Windowed"
        
    if m_index>=(len(m_list)-1):
        m_next=0
    else:
        m_next=m_index+1
    
    buttons_sets = \
    [\
     objects.t_button(55, 430, b1_l, i_restore, f_s, b_s, BLACK, CYAN,"mode"), \
     #objects.t_button(57, 430, "Set: "+str(m_list[m_next]), i_record, f_s, b_s, BLACK, CYAN,"resolution"), \
     ]
    buttons_sets = objects.WidgetsPack(250, 150, 50, False, buttons_sets)

    textlabels = [objects.t_label(270, 230, "ImpactuX", i_exit, 32, 1, RED, None),\
                  objects.t_label(20, 380, "Options", i_exit, 22, 1, GREEN, None)\
                  ]
    textlabels = objects.WidgetsPack(250, 30, 30, False, textlabels)
        #font1=pygame.font.Font("."+os.sep+"fonts"+os.sep+"LiberationSans-Regular.ttf", 18)
    pygame.display.set_caption("ImpactuX settings")
    clock = pygame.time.Clock()
    run_now = True
    n_scr_param=scr_params[1]
    n_scr_res=scr_params[0]

####### main loop section #######
    while run_now:
        clock.tick(30) 
        #t=pygame.time.delay(100)
        for event in pygame.event.get():
            if event.type == QUIT:
                i_exit()
                #ending_play()
                return i_exit()
                
            if event.type == KEYUP:
                if event.key == K_ESCAPE:
                    run_now=False
                    return i_exit()

            elif event.type == MOUSEBUTTONDOWN:
                x_n0,y_n0=event.pos
                check_tb=button_press_checking(x_n0,y_n0, textbuttons.w_list)
                if check_tb[0]:
                    check_tb[1].ch_state(event.type)
                check_tb=button_press_checking(x_n0,y_n0, buttons_sets.w_list)
                if check_tb[0]:
                    check_tb[1].ch_state(event.type)
    
            elif event.type == MOUSEMOTION:
                x_n0, y_n0=event.pos
                check_tb=button_press_checking(x_n0,y_n0, textbuttons.w_list)
                if check_tb[0]:
                    check_tb[1].ch_state(event.type)
                check_tb=button_press_checking(x_n0,y_n0, buttons_sets.w_list)
                if check_tb[0]:
                    check_tb[1].ch_state(event.type)

            elif event.type == MOUSEBUTTONUP:
                if int(event.button) == 1:
                    x_n0,y_n0=event.pos
                    
                    check_tb=button_press_checking(x_n0, y_n0, textbuttons.w_list)
                    if check_tb[0]:
                        check_tb[1].ch_state(event.type)
                        ddd = check_tb[1].doing()
                        if ddd == "run":
                            functions.save_set(game_dict={"screen_width":n_scr_res[0],\
                                                          "screen_height":n_scr_res[1],\
                                                          "screen_flags":n_scr_param,\
                                                          "screen_depth":scr_params[2]}, \
                                               g_file="conf_game.ini", \
                                               g_section="screen")
                        return ddd
                    check_tb=button_press_checking(x_n0,y_n0, buttons_sets.w_list)
                    if check_tb[0]:
                        check_tb[1].ch_state(event.type)
                        ddd = check_tb[1].doing()
                        if ddd == "restore":
                            if n_scr_param==0:
                                buttons_sets.set_named_obj_str("mode", "Set Windowed")
                                n_scr_param='"fullscreen"'
                                
                            else:
                                buttons_sets.set_named_obj_str("mode", "Set Fullscreen")
                                n_scr_param=0
                        elif ddd=="record":
                            m_index=m_next
                            n_scr_res=m_list[m_index]
                            if m_index>=(len(m_list)-1):
                                m_next=0
                            else:
                                m_next=m_index+1
                            buttons_sets.set_named_obj_str("resolution", "Set: "+str(m_list[m_next]))

        screen.blit(background, (0,0))
        textbuttons.show_at(screen)
        textlabels.show_at(screen)
        buttons_sets.show_at(screen)
    
        pygame.display.flip()