コード例 #1
0
def pause_screen(pause_flag = True):

    start = starting_intro()

    start.main_menu(pause_flag)
    logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
    ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
    while start.run:
        pygame.display.set_caption('FoodForce2')
        threades.screen.fill((0,0,0))
        threades.screen.blit(ff_logo,threades.resize_pos((40,50)))
        
        for e in gui.setEvents(pygame.event.get()):
            if e.type == pygame.QUIT:
                safe_exit()
            if e.type == QUIT:
                safe_exit()
            if e.type==mesh.CONNECT :
                game_sharing.sharing_handler(e.type,None,'')
            #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
            elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                game_sharing.sharing_handler(e.type,e.handle,'')
            #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
            elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                game_sharing.sharing_handler(e.type,e.handle,e.content)
            #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()


        desktop2.update()
        desktop2.draw()
        pygame.display.update()
    threades.total_update_flag = True
コード例 #2
0
    def controls(self,button = None):
        """"show controllers
        """
        self.remove_buttons()
        self.lightgreen_color = (0,100,0)
        self.green_color = (0,150,0)
        self.black_color = (0,0,0)
        myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40))

        # Custom gui.Window Style
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont1
        win_style['font-color'] = self.green_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = (0,150,0)
        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,270.0))
        size_win =threades.resize_pos((900.0,600.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = "     Controls " , style = win_style, shadeable = False, closeable = False)
        self.win.onClose = lambda button: self.main_menu(self.pause_flag)
        self.win.surf.set_alpha(140)

        control_text = """\n\n  Setup Facility           :       s \n\n  Upgrade Facility       :       u \n\n  Buy/Sell                    :       b \n\n  Scroll threades.screen up       :       up arrow \n\n  Scroll threades.screen down   :       down arrow \n\n  Scroll threades.screen left      :       left arrow \n\n  Scroll threades.screen right    :       right arrow """
        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(25))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 1
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.lightgreen_color
        labelStyleCopy['border-color'] = self.black_color
        self.message_label = gui.Label(position = threades.resize_pos((80,80),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Setup Facility ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,130),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Upgrade Facility ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,180),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Buy/Sell ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,230),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen up ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,280),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen down", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,330),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen left ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,380),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen right ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,430),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Focus ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,480),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "De Focus ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,80),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,130),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,180),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,230),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,280),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,330),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,380),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,430),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,480),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,80),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "s ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,130),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "u ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,180),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "b ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,230),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "up arrow ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,280),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "down arrow ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,330),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "left arrrow ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,380),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "right arrow ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,430),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "f ", style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,480),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "d ", style = labelStyleCopy)

        self.win.surf.set_alpha(255)
        self.ok_button = gui.Button(position = threades.resize_pos((480,550),(600.0,600.0),self.win.size), size = threades.resize_pos((80,30),(600.0,600.0),self.win.size), parent = self.win, text = "  OK  ",style = self.button_style)

        self.ok_button.onClick = self.close_win
        self.controls_run = True
        logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
        while self.controls_run:
            pygame.display.set_caption('FoodForce2')
            threades.screen.fill((0,0,0))
            threades.screen.blit(ff_logo,threades.resize_pos((40,50)))

            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.controls_run = False
                        self.win.close()

                if e.type==mesh.CONNECT :
                    game_sharing.sharing_handler(e.type,None,'')
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
                elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                    game_sharing.sharing_handler(e.type,e.handle,'')
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
                elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                    game_sharing.sharing_handler(e.type,e.handle,e.content)
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()

                
            desktop2.update()
            desktop2.draw()
            pygame.display.update()
コード例 #3
0
    def aboutUsWindow(self,button = None):
        ''' Displays the credits
        '''
        
        self.remove_buttons()
        self.lightgreen_color = (0,100,0)
        self.green_color = (0,150,0)
        self.black_color = (0,0,0)
        myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40))

        # Custom gui.Window Style
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont1
        win_style['font-color'] = self.green_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = (0,150,0)
        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,270.0))
        size_win =threades.resize_pos((900.0,600.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = "     About Us " , style = win_style, shadeable = False, closeable = False,moveable = False)
        self.win.onClose = lambda button: self.main_menu(self.pause_flag)
        #self.win.surf.set_alpha(140) This seems to be redundant as translucency doesnt seems to work properly

        self.next_button = gui.Button(position = threades.resize_pos((500,650)), size = threades.resize_pos((200,30)), parent = self.win, text = "Next ",style = self.button_style)
        
        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 1
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = (0,200,0)
        labelStyleCopy['border-color'] = self.black_color
        
        self.close_button = gui.Button(position = threades.resize_pos((500,550),(900.0,600.0),self.win.size), size = threades.resize_pos((80,30),(900.0,600.0),self.win.size), parent = self.win, text = "  Close  ",style = self.button_style)
        
        self.close_button.onClick = self.close_win
        self.about_us_run = True
        logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
        
        #self.instructions_counter = 0
        label = gui.Label(position = threades.resize_pos((10.0,100.0),(900.0,600.0),self.win.size),size = threades.resize_pos((880.0,440.0),(900.0,600.0),self.win.size), parent = self.win, text = '', style = labelStyleCopy)

        while self.about_us_run:
            pygame.display.set_caption('FoodForce2')
            threades.screen.fill((0,0,0))
            threades.screen.blit(ff_logo,threades.resize_pos((40,50)))

            label.text = texts.about_us_text
            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.about_us_run = False
                        self.win.close()
                if e.type==mesh.CONNECT :
                    game_sharing.sharing_handler(e.type,None,'')
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
                elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                    game_sharing.sharing_handler(e.type,e.handle,'')
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
                elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                    game_sharing.sharing_handler(e.type,e.handle,e.content)
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()

         
            desktop2.update()
            desktop2.draw()
            pygame.display.update()
コード例 #4
0
    def startup_text(self,button = None):
        ''' Displays the startup text
        '''

        self.remove_buttons()
        threades.screen.fill((255,255,255))
        hunger_map = pygame.image.load(os.path.join('data', 'Wfpwork.png')).convert()
        hunger_map =  pygame.transform.scale(hunger_map,threades.new_screen_size)
        threades.screen.blit(hunger_map,threades.resize_pos((0,0)))

        color_brown = (255,214,150)
        # gui.Window custom style
        myfont = pygame.font.Font("font.ttf", threades.resize_pt(28))
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont
        win_style['font-color'] = color_brown
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = color_brown
        position_win =threades.resize_pos((200.0,50.0))
        size_win =threades.resize_pos((800.0,600.0))
        win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = " FOODFORCE II : ESCAPING POVERTY  " ,style = win_style,shadeable = False, closeable = False,moveable = False)
        self.startup_text_run = True
        win.surf.set_alpha(100)
        myfont2 = pygame.font.Font("font.ttf",threades.resize_pt(19))
        labelstyle1 = gui.defaultLabelStyle.copy()
        labelstyle1['border-width'] = 0
        labelstyle1['wordwrap'] = True
        labelstyle1['autosize'] = False
        labelstyle1['font'] = myfont2
        labelstyle1['font-color'] = color_brown

        counter = 0
        label = gui.Label(position = threades.resize_pos((10.0,130.0),(800.0,600.0),win.size),size = threades.resize_pos((780.0,460.0),(800.0,600.0),win.size), parent = win, text = '', style = labelstyle1)
        
        button_style = gui.defaultButtonStyle.copy()
        button_style['font'] = myfont2

        self.skip_button = gui.Button(position = threades.resize_pos((600,550),(800.0,600.0),win.size), size = threades.resize_pos((150,30),(800.0,600.0),win.size), parent = win, text = "  Skip  ",style = button_style)
        self.skip_button.onClick = self.turnoff_startup_run
        model.global_time = 0
        
        #One time show of the background image
        threades.screen.fill((255,255,255))
        threades.screen.blit(hunger_map,threades.resize_pos((0,0)))
        pygame.display.flip()
        #sleep(5)
        first_display = True
        model.global_time = 0
        while self.startup_text_run:

            label.text =  texts.trailer_text[counter]
            for e in gui.setEvents(pygame.event.get()):
                if e.type == pygame.QUIT:
                    safe_exit()
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.startup_text_run = False
                    if e.key == K_RETURN:
                        counter += 1
                if e.type==mesh.CONNECT :
                    game_sharing.sharing_handler(e.type,None,'')
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
                elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                    game_sharing.sharing_handler(e.type,e.handle,'')
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
                elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                    game_sharing.sharing_handler(e.type,e.handle,e.content)
                #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()

            
            if model.global_time >= 5000:
                first_display = False                
                model.global_time = 0
                counter += 1
            if not first_display:
                
                threades.screen.fill((255,255,255))
                threades.screen.blit(hunger_map,threades.resize_pos((0,0)))
                desktop2.update()
                desktop2.draw()
                pygame.display.flip()
                
            if counter == len(texts.trailer_text):
                self.startup_text_run = False
            
            
            
        
            model.iteration_time = clock.tick()
            model.global_time += model.iteration_time
        win.close()

        
        self.run = False
コード例 #5
0
def event_handling(e):
    
    if e.type == pygame.QUIT:
        safe_exit()
    if e.type == QUIT:
        safe_exit()
    if e.type == KEYDOWN:
        if e.key == 27:  # For escape key
            escape()
        if e.key == K_UP:
            threades.transform_obj.start_move('up')
        if e.key == K_DOWN:
            threades.transform_obj.start_move('down')
        if e.key == K_LEFT:
            threades.transform_obj.start_move('left')
        if e.key == K_RIGHT:
            threades.transform_obj.start_move('right')
        if e.key == K_f or e.key == 61:
            threades.transform_obj.focus()
        if e.key == K_d or e.key == 45:
            threades.transform_obj.defocus()
        if e.key == K_RETURN:
            gui_buttons.gui_obj.press_enter()
        
        win_flag = gui_buttons.gui_obj.get_win_flag()
        if not win_flag:
            if e.key == K_s:
                gui_buttons.gui_obj.setup_obj.setup()
            if e.key == K_u:
                gui_buttons.gui_obj.upgrade_obj.upgrade()
            if e.key == K_b:
                gui_buttons.gui_obj.buysell_obj.buysell()
            
            
    if e.type == KEYUP:
        if e.key == K_UP:
            threades.transform_obj.stop_move('up')
        if e.key == K_DOWN:
            threades.transform_obj.stop_move('down')
        if e.key == K_LEFT:
            threades.transform_obj.stop_move('left')
        if e.key == K_RIGHT:
            threades.transform_obj.stop_move('right')

    x,y = pygame.mouse.get_pos()
    r = pygame.Rect(threades.resize_rect((0,40,930,560)))
    if gui_buttons.gui_obj.buysell_obj.get_win_flag():
        gui_buttons.gui_obj.buysell_obj.drawPriceChart()
    if r.collidepoint(x,y):
        
        if e.type == MOUSEBUTTONDOWN:
            if e.button == 1 and gui_buttons.gui_obj.get_child_win_flag():
                gui_buttons.gui_obj.setup_obj.bardisplay.updateChart((x,y))
            if e.button == 1 and gui_buttons.gui_obj.buysell_obj.get_win_flag():
                gui_buttons.gui_obj.buysell_obj.barObject.updateChart((x,y))
            if e.button == 4:
                threades.transform_obj.focus()
            if e.button == 5:
                threades.transform_obj.defocus()
    
    if e.type==mesh.CONNECT :
        game_sharing.sharing_handler(e.type,None,'')
    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
    elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
        game_sharing.sharing_handler(e.type,e.handle,'')
    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
    elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
        game_sharing.sharing_handler(e.type,e.handle,e.content)
コード例 #6
0
    def controls(self,button = None):
        """"show controllers
        """
        self.remove_buttons()
        self.lightgreen_color = (0,100,0)
        self.green_color = (0,150,0)
        self.black_color = (0,0,0)
        myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40))

        # Custom gui.Window Style
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont1
        win_style['font-color'] = self.green_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = (0,150,0)
        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,270.0))
        size_win =threades.resize_pos((900.0,600.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = model.text_file.control_button_text[0], style = win_style, shadeable = False, closeable = False)
        self.win.onClose = lambda button: self.main_menu(self.pause_flag)
        self.win.surf.set_alpha(140)
	
    
        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(25))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 1
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.green_color
        labelStyleCopy['border-color'] = self.black_color
        
        #Creating labels for text to be written
        self.message_label = gui.Label(position = threades.resize_pos((80,80),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[0], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,130),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[1], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,180),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[2], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,230),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[3], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,280),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[4], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,330),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[5], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,380),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[6], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,430),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[7], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((80,480),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[8], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,80),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,130),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,180),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,230),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,280),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,330),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,380),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,430),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((330,480),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[9], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,80),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[10], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,130),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[11], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,180),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[12], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,230),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[13], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,280),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[14], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,330),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[15], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,380),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[16], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,430),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[17], style = labelStyleCopy)
        self.message_label = gui.Label(position = threades.resize_pos((350,480),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[18], style = labelStyleCopy)

        self.win.surf.set_alpha(255)
        self.ok_button = gui.Button(position = threades.resize_pos((480,550),(600.0,600.0),self.win.size), size = threades.resize_pos((80,30),(600.0,600.0),self.win.size), parent = self.win, text = model.text_file.controls_text[19],style = self.button_style)

        self.ok_button.onClick = self.close_win
        self.controls_run = True
        logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        ff_logo = pygame.transform.scale(logo,threades.resize_pos((1128,171)))
        
      #The loop which pauses the game unless an action is taken by the user 
        while self.controls_run:
            pygame.display.set_caption('FoodForce2')
            threades.screen.fill((0,0,0))
            threades.screen.blit(ff_logo,threades.resize_pos((40,90)))

            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.controls_run = False
                        self.win.close()
                if model.FLAG_XO:
                    if e.type==mesh.CONNECT :
                        game_sharing.sharing_handler(e.type,None,'')
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
                    elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                        game_sharing.sharing_handler(e.type,e.handle,'')
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
                    elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                        game_sharing.sharing_handler(e.type,e.handle,e.content)
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()

                
            desktop2.update()
            desktop2.draw()
            pygame.display.update()
コード例 #7
0
    def storyboardWindow(self,button = None):
        global select_flag
	self.remove_buttons()
        
        self.lightgreen_color = (0,80,0)
        self.green_color = (0,150,0)
        self.black_color = (0,0,0)
        myfont1 = pygame.font.Font('font.ttf',threades.resize_pt(50))
	
        myfont = pygame.font.Font("font.ttf", threades.resize_pt(20))
        buttonsurf = pygame.image.load(os.path.join('art','button_green.png')).convert_alpha()
        buttonsurf = pygame.transform.scale(buttonsurf, (38, threades.resize_pt_y(50)))
        self.button_style_2 = gui.createButtonStyle(myfont,(0,0,0), buttonsurf,4,1,4,4,1,4,4,1,4,4,1,4)
	
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont1
        win_style['font-color'] = self.green_color
        win_style['bg-color'] = self.black_color
        win_style['border-color'] =self.black_color
        
        position_win = threades.resize_pos((150.0,270.0))
        size_win = threades.resize_pos((900.0,650.0))
        
        myfont2 = pygame.font.Font('font.ttf',threades.resize_pt(20))
        labelstylecopy = gui.defaultLabelStyle.copy()
        labelstylecopy['font'] = myfont2
        labelstylecopy['font-color'] = self.green_color
        labelstylecopy['border-width'] = 1
        labelstylecopy['border-color'] = (0,0,0)
        labelstylecopy['autosize']=True
        labelstylecopy['wordwrap']=False
        
        op_image = pygame.image.load(os.path.join("art","optionbox_green.png")).convert_alpha()
        op_style = gui.createOptionBoxStyle(gui.defaultFont, op_image, 12, (255,255,255),(100,100,100), autosize = True)
       
        op_style['font'] = myfont2
        op_style['font-color'] = self.green_color
        op_style['normal'] = True
        op_style['autosize'] = True
        op_style['word wrap'] = False
        self.op_style = op_style
        
        
        
        self.win = gui.Window(position = position_win,size = size_win,parent = desktop2,style = win_style,text = model.text_file.storyboard_window_text[0], closeable = False,shadeable = False,moveable = False )
	self.win.onClose = self.main_menu
        vertical_dist = 150.0     #for the position of optionboxes
	vertical_dist_photo = 120.0
        storyboard_list_file = open('storyboard_list.pkl')
        
        for i in range(pickle.load(storyboard_list_file)):
            storyboard_name = pickle.load(storyboard_list_file)
            if select_flag == True or os.path.exists(os.path.join('storyboards',str(storyboard_name[1]),'save_game.pkl')):
		self.image = pygame.image.load(os.path.join('storyboards',str(storyboard_name[1]),'intro_image.png')).convert_alpha()
		self.image = pygame.transform.scale(self.image, threades.resize_pos((150,120)))
		finalSurface = pygame.surface.Surface(threades.resize_pos((150,150))).convert_alpha()
		finalSurface.blit(self.image,threades.resize_pos((10,10)))
		self.win.surf.blit(finalSurface,threades.resize_pos((160,vertical_dist_photo)))
                self.item = gui.Button(position = threades.resize_pos((450.0,vertical_dist),(900.0,600.0),self.win.size),size = threades.resize_pos((290,50)),parent = self.win,text = str(storyboard_name[1]),style = self.button_style_2)
                self.item.onClick = self.select_storyboard
                vertical_dist = vertical_dist + 180
		vertical_dist_photo = vertical_dist_photo  + 180
    
		
        self.skip_button = gui.Button(position = threades.resize_pos((180,490),(900.0,600.0),self.win.size), size = threades.resize_pos((110,30),(900.0,600.0),self.win.size), parent = self.win, text = model.text_file.skip_text[0],style = self.button_style)
        self.skip_button.onClick = self.close_win

        logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        ff_logo = pygame.transform.scale(logo,threades.resize_pos((1128,171)))
        self.storyboard_menu_run = True
        while self.storyboard_menu_run:
            pygame.display.set_caption('FoodForce2')
            threades.screen.fill((0,0,0))
            threades.screen.blit(ff_logo,threades.resize_pos((40,90)))
            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.storyboard_menu_run = False
                        self.win.close()
                    
                if model.FLAG_XO:
                    if e.type==mesh.CONNECT :
                        game_sharing.sharing_handler(e.type,None,'')
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
                    elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                        game_sharing.sharing_handler(e.type,e.handle,'')
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
                    elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                        game_sharing.sharing_handler(e.type,e.handle,e.content)
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()
            desktop2.update()
            desktop2.draw()
            pygame.display.update()
コード例 #8
0
def event_handling(e):    
    #For the safe exit of the game
    if e.type == pygame.QUIT:
        safe_exit()
    if e.type == QUIT:
        safe_exit()
        
         #Updates the region
    if e.type == KEYDOWN:
        if e.key == 27:  # For escape key
            escape()
        if e.key == K_UP:
            threades.transform_obj.start_move('up')
        if e.key == K_DOWN:
            threades.transform_obj.start_move('down')
        if e.key == K_LEFT:
            threades.transform_obj.start_move('left')
        if e.key == K_RIGHT:
            threades.transform_obj.start_move('right')
        if e.key == K_f or e.key == 61:
            threades.transform_obj.focus()
        if e.key == K_d or e.key == 45:
            threades.transform_obj.defocus()
        if e.key == K_RETURN:
            gui_buttons.gui_obj.press_enter()
        
            #Tackles the cases of setting up a facility,upgrading a facility,buying and selling of resources
        win_flag = gui_buttons.gui_obj.get_win_flag()
        if not win_flag:
            if e.key == K_s and gui_buttons.gui_obj.setup_button.enabled:
                gui_buttons.gui_obj.setup_obj.setup()
            if e.key == K_u and gui_buttons.gui_obj.upgrade_button.enabled:
                gui_buttons.gui_obj.upgrade_obj.upgrade()
            if e.key == K_b and gui_buttons.gui_obj.buysell_button.enabled:
                gui_buttons.gui_obj.buysell_obj.buysell()
            
                #Resetting the game
    if proceduralFlow.GAME_END_FLAG:
        threades.PLACING_LIST_TEMP = []
        proceduralFlow.GAME_END_FLAG = False
        proceduralFlow.closeStoryBoardFile()
        proceduralFlow.openStoryBoardFile()
        threades.delete_saved_game()
        proceduralFlow.storyboard_level = 1
	data_file = os.path.join('storyboards',str(model.storyboard_file),'data','data1.pkl')
        proceduralFlow.load_level_obj.new_level_stats(data_file,'graphics_layout.pkl')
        event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0)
        game_events.EventQueue.add(event)
        model.game_controller.reset_time()
        pause_screen()
        
    if e.type == KEYUP:
        if e.key == K_UP:
            threades.transform_obj.stop_move('up')
        if e.key == K_DOWN:
            threades.transform_obj.stop_move('down')
        if e.key == K_LEFT:
            threades.transform_obj.stop_move('left')
        if e.key == K_RIGHT:
            threades.transform_obj.stop_move('right')

    x,y = pygame.mouse.get_pos()
    r = pygame.Rect(threades.resize_rect((0,40,930,560)))
    if gui_buttons.gui_obj.buysell_obj.get_win_flag():
        gui_buttons.gui_obj.buysell_obj.drawPriceChart()
    if r.collidepoint(x,y):
        
        if e.type == MOUSEBUTTONDOWN:
            if e.button == 1 and gui_buttons.gui_obj.get_child_win_flag():
                gui_buttons.gui_obj.setup_obj.bardisplay.updateChart((x,y))
            if e.button == 1 and gui_buttons.gui_obj.buysell_obj.get_win_flag():
                gui_buttons.gui_obj.buysell_obj.barObject.updateChart((x,y))
            if e.button == 4:
                threades.transform_obj.focus()
            if e.button == 5:
                threades.transform_obj.defocus()
    if model.FLAG_XO:
        
        if e.type==mesh.CONNECT :
            game_sharing.sharing_handler(e.type,None,'')
        elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
            game_sharing.sharing_handler(e.type,e.handle,'')
        elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
            game_sharing.sharing_handler(e.type,e.handle,e.content)
コード例 #9
0
    def storyboardWindow(self,button=None):
        self.remove_buttons()
        self.lightgreen_color = (0,100,0)
        self.green_color = (0,150,0)
        self.black_color = (0,0,0)
        myfont1 = pygame.font.Font('font.ttf',threades.resize_pt(50))
        
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont1
        win_style['font-color'] = self.lightgreen_color
        win_style['bg-color'] = self.black_color
        win_style['border-color'] =self.black_color
        
        position_win = threades.resize_pos((150.0,270.0))
        size_win = threades.resize_pos((900.0,650.0))
        
        myfont2 = pygame.font.Font('font.ttf',threades.resize_pt(20))
        labelstylecopy = gui.defaultLabelStyle.copy()
        labelstylecopy['font'] = myfont2
        labelstylecopy['font-color'] = self.lightgreen_color
        labelstylecopy['border-width'] = 1
        labelstylecopy['border-color'] = (0,0,0)
        labelstylecopy['autosize']=True
        labelstylecopy['wordwrap']=False
        
        
        op_style = gui.defaultOptionBoxStyle
        op_style['font'] = myfont2
        op_style['font-color'] = self.lightgreen_color
        op_style['normal'] = True
        op_style['autosize'] = True
        op_style['word wrap'] = False
        self.op_style = op_style
        
        
        
        
        self.win = gui.Window(position = position_win,size = size_win,parent = desktop2,style = win_style,text = "    Choose Storyboard", closeable = False,shadeable = False,moveable = False )
        self.win.onClose = self.main_menu(self.pause_flag)
        
        q = 200.0     #for the position of optionboxes
        for item in os.listdir(os.path.join("storyboards")):
            self.item = gui.OptionBox(position = threades.resize_pos((150.0,q),(900.0,600.0),self.win.size),parent = self.win,style = op_style,text = str(item))
            self.item.onValueChanged = self.select_storyboard
            q=q+40
        
        self.skip_button = gui.Button(position = threades.resize_pos((100,490),(900.0,600.0),self.win.size), size = threades.resize_pos((110,30),(900.0,600.0),self.win.size), parent = self.win, text = "  Skip  ",style = self.button_style)
        self.skip_button.onClick = self.close_win
        self.play_button = gui.Button(position = threades.resize_pos((200,490),(900.0,600.0),self.win.size), size = threades.resize_pos((110,30),(900.0,600.0),self.win.size), parent = self.win, text = "  Play  ",style = self.button_style)
        self.play_button.onClick = self.startup_text
        
        
        logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
        self.storyboard_menu_run = True
        while self.storyboard_menu_run:
            pygame.display.set_caption('FoodForce2')
            threades.screen.fill((0,0,0))
            threades.screen.blit(ff_logo,threades.resize_pos((40,50)))
            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.storyboard_menu_run = False
                        self.win.close()
                    
                if model.FLAG_XO:
                    if e.type==mesh.CONNECT :
                        game_sharing.sharing_handler(e.type,None,'')
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start()
                    elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE :
                        game_sharing.sharing_handler(e.type,e.handle,'')
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start()
                    elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI :
                        game_sharing.sharing_handler(e.type,e.handle,e.content)
                    #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start()


            desktop2.update()
            desktop2.draw()
            pygame.display.update()