Beispiel #1
0
 def run(self):
     while not pygame.key.get_pressed()[pygame.K_ESCAPE] and not self.done:
         pygame.event.pump()
         gui.setEvents(pygame.event.get()) #This is needed otherwise the Gui
                                             #Breaks when using Text editing T.T
         self.update()
         self.render()
def pause_screen(pause_flag = True):
    """
       Pauses the screen until user takes any action
    """

    start = starting_intro()

    #Initialises and creates the starting screen
    start.main_menu(pause_flag,threades.game_save_flag)
    logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
    ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))

     #The loop which pauses main screen
    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()

        desktop2.update()
        desktop2.draw()
        pygame.display.update()
    threades.total_update_flag = True
Beispiel #3
0
    def gameLoop(self):
        while self.run: 
            #Just for exit        
            for e in gui.setEvents(pygame.event.get()):
                if e.type == pygame.QUIT:
                    self.run = False
            
            self.desktop.update()
            #Here begins rendering
            self.screen.fill((20,40,50))               

            self.screen.blit(self.background, (0,0))
            
            #Animacao dos bonecos:
            self.animation_players()
           
            self.screen.blit(self.p1[self.a][0],self.p1[self.a][1])    
            self.screen.blit(self.p2[self.a][0],self.p2[self.a][1])
            self.screen.blit(self.p3[self.a][0],self.p3[self.a][1])
            self.screen.blit(self.p4[self.a][0],self.p4[self.a][1])
            self.screen.blit(self.p5[self.a][0],self.p5[self.a][1])
            self.screen.blit(self.p6[self.a][0],self.p6[self.a][1])
            
            
            
                
            self.desktop.draw()
            #Flips!
            pygame.display.flip()  
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
def pause_screen(pause_flag = True):

    start = starting_intro()
    start.main_menu(pause_flag,threades.game_save_flag)
    logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
    ff_logo = pygame.transform.scale(logo,threades.resize_pos((1128,171)))
    
    threades.audio.play_music(False,'soundtrack')
    
    while start.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 == pygame.QUIT:
                safe_exit()
            if e.type == QUIT:
                safe_exit()
	#print 'in pause screen'
        desktop2.update()
        desktop2.draw()
        pygame.display.update()
    
    threades.audio.play_music(True,'soundtrack')
    threades.total_update_flag = True
Beispiel #6
0
 def AritMayaCiclo(self):
     while self.run:
         for e in gui.setEvents(pygame.event.get()):
             if e.type == pygame.QUIT:
                 self.run = False
             if self.txtResultado.enter == True:
                 self.evento_click(self.txtResultado)
                 self.txtResultado.enter = False
         self.desktop.update()
         self.desktop.draw()
         pygame.display.update()
Beispiel #7
0
 def AhorcadoCiclo(self):
     clock = pygame.time.Clock()
     while self.run:
         clock.tick(20)
         for e in gui.setEvents(pygame.event.get()):
             if e.type == pygame.QUIT:
                 self.run = False
             if self.txtLetra.enter == True:
                 self.evt_click()                        
             self.desktop.update()
             self.desktop.draw()
             pygame.display.update()
Beispiel #8
0
 def AhorcadoCiclo(self):
     clock = pygame.time.Clock()
     while self.run:
         clock.tick(20)
         for e in gui.setEvents(pygame.event.get()):
             self.MayCNucleo.MEventos(e)
             if (self.txtLetra.enter == True and self.PregJugar == False):
                 self.evtVerificar()       
                 self.txtLetra.CEnter(False)    
             if(self.PregJugar==False):                  
                 self.desktop.update()
                 self.desktop.draw()
             
         pygame.display.update()
    def new_level_stats(self,data_file,graphics_file,level_no=-1):
        #global total_update_flag 
        global animation_obj
        threades.pause_update_thread()           
        self.graphics()
        self.level_no=level_no
        self.data_file=data_file
        self.graphics_file=graphics_file
        self.run=True
        level_updater=threading.Thread(target=self.level_reinit,args=[]).start()
        
        pygame.display.set_caption('FoodForce2')
        threades.screen.fill((0,0,0))
        threades.screen.blit(self.ff_logo,threades.resize_pos((40,50)))
        
        desktop_level.update()
        desktop_level.draw()
        pygame.display.update()
            
        while 1 :
            
            for e in gui.setEvents(pygame.event.get()):
                if e.type == pygame.QUIT:
                    print 'in pygame.quit'                    
                    safe_exit()
                if e.type == QUIT:
                    print 'in quit'
                    safe_exit()

            #if level_updater.is_alive()==False:
               # self.run=False      GREAT THIS IS APPLICABLE ONLY WITH PYTHON 2.6, SO HAVE TO SEARCH SOME OTHER MEANS
            if self.run==False:
                break
           
        #print 'now reached here\n'
        
            
        self.ff_logo = 0
        threades.initialize_facilities(True)
        threades.set_build_facility_placement_flag()
        threades.facility_placement_data_obj.clear_placement_data()
        #threades.current_level = proceduralFlow.storyboard_level
                
        threades.total_update_flag = True
        threades.resume_update_thread()
Beispiel #10
0
    def remote_goOut(self):
	"""
	Called remotely by the server when the client's partner has asked to go out.
	Waits for user input.
	"""
	self.done = False

	def OKOnClick(button):
	    self.done = True
	    self.response = True
	def cancelOnClick(button):
	    self.done = True
	    self.response = False

	defaultStyle.init(gui)
	defaultStyle.init(gui)
	desktop_main = Desktop()
	desktop = Window(position = (300,220), size = (400,200), parent = desktop_main, text = "Go Out", closeable = False, shadeable = False)
	desktop.onClose = cancelOnClick

	labelStyleCopy = gui.defaultLabelStyle.copy()

	Label(position = (100,100),size = (200,0), parent = desktop, text = 'Your partner asked: "May I go out?"', style = labelStyleCopy)

	OK_button = Button(position = (100,140), size = (50,0), parent = desktop, text = "Yes")
	cancel_button = Button(position = (200,140), size = (50,0), parent = desktop, text = "No")

	OK_button.onClick = OKOnClick
	cancel_button.onClick = cancelOnClick

	while not self.done:

	    #Handle Input Events
	    for event in gui.setEvents():
		if event.type == QUIT:
		    return
		elif event.type == KEYDOWN and event.key == K_ESCAPE:
		    return

	    self.DrawGame(flip=False)
	    desktop_main.update()
	    desktop_main.draw()
	    pygame.display.flip()

	return self.response
Beispiel #11
0
    def new_level_stats(self, data_file, graphics_file, level_no=-1):
        #global total_update_flag
        global animation_obj
        threades.pause_update_thread()
        self.graphics()
        self.level_no = level_no
        self.data_file = data_file
        self.graphics_file = graphics_file
        self.run = True
        level_updater = threading.Thread(target=self.level_reinit,
                                         args=[]).start()

        pygame.display.set_caption('FoodForce2')
        threades.screen.fill((0, 0, 0))
        threades.screen.blit(self.ff_logo, threades.resize_pos((40, 90)))

        desktop_level.update()
        desktop_level.draw()
        pygame.display.update()

        while 1:

            for e in gui.setEvents(pygame.event.get()):
                if e.type == pygame.QUIT:
                    print 'in pygame.quit'
                    #safe_exit()
                if e.type == QUIT:
                    print 'in quit'
                    #safe_exit()

            #if level_updater.is_alive()==False:
            # self.run=False      GREAT THIS IS APPLICABLE ONLY WITH PYTHON 2.6, SO HAVE TO SEARCH SOME OTHER MEANS
            if self.run == False:
                break

        self.ff_logo = 0
        threades.initialize_facilities(True)
        threades.set_build_facility_placement_flag()
        #threades.current_level = proceduralFlow.storyboard_level

        threades.total_update_flag = True
        model.POPULATION_FACTOR = 0.5
        threades.resume_update_thread()
Beispiel #12
0
def view_loop(view):
    
    run = True

    while run:
        view.clock.tick()    
        events = gui.setEvents(pygame.event.get())
        
        for e in events:
            if e.type == pygame.QUIT:
                run = False
                    
        view.update()
        view.desktop.events = events
        view.draw()        
        
        pygame.display.flip()

    pygame.quit()
    def new_level_stats(self, data_file, graphics_file, level_no=-1):
        #global total_update_flag
        global animation_obj
        threades.pause_update_thread()
        self.graphics()
        self.level_no = level_no
        self.data_file = data_file
        self.graphics_file = graphics_file
        self.run = True
        level_updater = threading.Thread(target=self.level_reinit,
                                         args=[]).start()

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

        desktop_level.update()
        desktop_level.draw()
        pygame.display.update()

        while 1:

            for e in gui.setEvents(pygame.event.get()):
                if e.type == pygame.QUIT:
                    print 'in pygame.quit'
                    safe_exit()
                if e.type == QUIT:
                    print 'in quit'
                    safe_exit()

            #if level_updater.is_alive()==False:
            # self.run=False      GREAT THIS IS APPLICABLE ONLY WITH PYTHON 2.6, SO HAVE TO SEARCH SOME OTHER MEANS
            if self.run == False:
                break

        print 'now reached here\n'

        self.ff_logo = 0
        threades.initialize_facilities()

        threades.total_update_flag = True
        threades.resume_update_thread()
Beispiel #14
0
def start_loop():
    while settings.game_stage == 'start':
        for event in gui.setEvents(pygame.event.get()):
            if event.type == QUIT:
                pygame.quit()
                exit()
            if event.type == MOUSEBUTTONUP:
                settings.mouse.click = True
                settings.mouse.button = event.button

        settings.screen.fill(WHITE)
        if settings.start_stage == 'start':
            start()
        elif settings.start_stage == 'select_p':
            select_p()
        elif settings.start_stage == 'thanks':
            thanks()
        elif settings.start_stage == 'login':
            login()
        draw.message_draw_surf()
        settings.mouse.fresh()
        settings.clock.tick(settings.FPS)
        pygame.display.update()
Beispiel #15
0
    def showCredits(self):
    
        global GAME_END_FLAG
        self.brown_color = (255,214,150)
        self.green_color = (0,250,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.brown_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = self.brown_color
        win_style['border-width'] = 2

        st_desktop = gui.Desktop()
        clock = pygame.time.Clock()
        clock.tick(30)

        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,100.0))
        size_win =threades.resize_pos((900.0,500.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = "                               Credits" , 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

        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 0
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.brown_color
        labelStyleCopy['border-color'] = self.black_color

        update_rect = pygame.Rect(threades.resize_rect((150,100,900,500)))

        self.storyboardwin_run = True
        #logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        #ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
        text = model.text_file.credits_text
        #self.instructions_counter = 0
        label = gui.Label(position = threades.resize_pos((100.0,100.0),(900.0,500.0),self.win.size),size = threades.resize_pos((700.0,380.0),(900.0,500.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy)

        gl_time = 0

        st_desktop.update()
        st_desktop.draw()
        pygame.display.update([update_rect])

        while self.storyboardwin_run:
            pygame.display.set_caption('FoodForce2')

            for e in gui.setEvents(pygame.event.get()):
                if e.type == MOUSEBUTTONDOWN:
                    if e.button == 1:
                        self.storyboardwin_run = False
                    
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.storyboardwin_run = False

            gl_time += clock.tick(30)
            if gl_time >= 17000:
                self.storyboardwin_run = False



        self.win.close()
        
        GAME_END_FLAG = True
    def showCredits(self):
    
        global GAME_END_FLAG
        self.brown_color = (255,214,150)
        self.green_color = (0,250,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.brown_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = self.brown_color
        win_style['border-width'] = 2

        st_desktop = gui.Desktop()
        clock = pygame.time.Clock()
        clock.tick(30)

        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,100.0))
        size_win =threades.resize_pos((900.0,500.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = "                               Credits" , 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

        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 0
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.brown_color
        labelStyleCopy['border-color'] = self.black_color

        update_rect = pygame.Rect(threades.resize_rect((150,100,900,500)))

        self.storyboardwin_run = True
        #logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        #ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
        text = model.text_file.credits_text
        #self.instructions_counter = 0
        label = gui.Label(position = threades.resize_pos((100.0,100.0),(900.0,500.0),self.win.size),size = threades.resize_pos((700.0,380.0),(900.0,500.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy)

        gl_time = 0

        st_desktop.update()
        st_desktop.draw()
        pygame.display.update([update_rect])

        while self.storyboardwin_run:
            pygame.display.set_caption('FoodForce2')

            for e in gui.setEvents(pygame.event.get()):
                if e.type == MOUSEBUTTONDOWN:
                    if e.button == 1:
                        self.storyboardwin_run = False
                    
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.storyboardwin_run = False

            gl_time += clock.tick(30)
            if gl_time >= 17000:
                self.storyboardwin_run = False



        self.win.close()
        
        GAME_END_FLAG = True
def main():
    for arg in sys.argv[1:]:
	process(arg)
    select_lang()
    global panel
    global chat_screen
    global level_setting
    global message_thread
    cursor = pygame.cursors.load_xbm(os.path.join('art', 'ff2_cursor.xbm'),os.path.join('art', 'ff2_cursor-mask.xbm'))
    #print cursor
    pygame.mouse.set_cursor(cursor[0],cursor[1],cursor[2],cursor[3])
    # Displaying the WFP logo
    intro_thread = threading.Thread(target = load_images.load_images, args=[])
    intro_thread.start()
    # Loading and starting the sound play
    threades.audio.play_music(False,'soundtrack')
    
    threades.check_saved_game_level()
    model.game_controller.reset_time()
    gui_buttons.initialize_gui()
    pause_screen()
    intro_thread.join()
    
    proceduralFlow.storyboard_level = threades.current_level
    if threades.current_level != 1:
        load_resume_game()
    else:
	threades.load_initial_facilities()
        data_file = os.path.join('storyboards',str(model.storyboard_file),'data','data1.pkl')
        model.init_cons(data_file)
        model.init_obj()
        threades.initialize_facilities(True)
        proceduralFlow.openStoryBoardFile() 

     
    # loading the correct data file

    #gui_buttons.initialize_gui()

    threades.screen.fill((0,0,0))
    #panel = display_panel.display_panel()
    panel.change_labels()
    animation_obj = threades.Animation()
    animation_obj.update()
    # Starting of the threads
    #print update_thread
    message_thread = threading.Thread(target = message_window, args=[])
    message_thread.start()
    mouse_flag = False
    chat_screen=chat.chat()
    #print 'i was here'
    clock = pygame.time.Clock()
    threades.total_update_flag = True
    # The main infinite loop
    while True:
        time_passed = clock.tick()
        model.game_controller.update_level_time(threades.update_thread_pause)
        threades.update_turn(time_passed)
        animation_obj.update()

        mouse_flag = False
            
        (x,y) = (0,0)
        x,y = pygame.mouse.get_pos()
        
        if not gui_buttons.gui_obj.get_win_flag():
            if len(threades.buildFacilityPlacementFlag):
                facility_placement()               
            if (x > (threades.resize_pt_x(890)) and x < threades.resize_pt_x(930)) and y< threades.resize_pt_y(600):
                threades.transform_obj.move_free((-10,0))
                
            if x < threades.resize_pt_x(60) and y< threades.resize_pt_y(600):
                threades.transform_obj.move_free((10,0))
                
            if  y > threades.resize_pt_y(560) and y< threades.resize_pt_y(600) and x < threades.resize_pt_x(930):
                threades.transform_obj.move_free((0,-10))
                
            if y < threades.resize_pt_y(60) and x < threades.resize_pt_x(930) and x < threades.resize_pt_x(930):
                threades.transform_obj.move_free((0,10))
                
            if (x > threades.resize_pt_x(0)) and (x < threades.resize_pt_x(600)) and (y > threades.resize_pt_y(845)) and (y < threades.resize_pt_y(900)):
                mouse_flag = True
                
        pygame.display.set_caption('FoodForce2')

        for e in gui.setEvents(pygame.event.get()):
            event_handling(e)

        
        

        # Calculate the values of the indicators
        threades.calculate_indicators_starting()
        
               

        
        rects_list = get_update_region()
        panel.update()
        
        if (threades.total_update_flag or threades.map_update_flag or threades.facilities_update_flag or threades.panel_update_flag or panel.res.money_flag):
            threades.desktop.update()
            threades.desktop.draw()
        
        pygame.display.update(rects_list)

        model.iteration_time = time_passed
        model.global_time += model.iteration_time
        storyboardObj.flow()
        gui_buttons.instruction_off_flag = False
Beispiel #18
0
    def showWFPWindow(self,text):


        self.brown_color = (255,214,150)
        self.green_color = (0,250,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.brown_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = self.brown_color
        win_style['border-width'] = 2

        st_desktop = gui.Desktop()
        clock = pygame.time.Clock()
        clock.tick(30)

        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,100.0))
        size_win =threades.resize_pos((700.0,600.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = "    Reward" , 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

        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 0
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.brown_color
        labelStyleCopy['border-color'] = self.black_color

        self.storyboardwin_run = True
        logo =  pygame.image.load(os.path.join('data', 'WFPLOGO.png')).convert()
        ff_logo = pygame.transform.scale(logo,threades.resize_pos((500,500)))
        position_blit = threades.resize_pos((100,100))
        self.win.surf.blit(ff_logo,position_blit)
        update_rect = pygame.Rect(threades.resize_rect((150,100,700,600)))

        #self.instructions_counter = 0
        label = gui.Label(position = threades.resize_pos((50.0,100.0),(700.0,600.0),self.win.size),size = threades.resize_pos((600.0,440.0),(700.0,600.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy)

        gl_time = 0

        while self.storyboardwin_run:
            pygame.display.set_caption('FoodForce2')

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

            gl_time += clock.tick(30)
            if gl_time >= 17000:
                self.storyboardwin_run = False

            st_desktop.update()
            st_desktop.draw()
            pygame.display.update([update_rect])
        self.win.close()

        event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0)
        game_events.EventQueue.add(event)
    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()
    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()
Beispiel #21
0
def showChat(chatText, back_image=None):
    ''' Chat text should be a list with first the name
        of the character and then his dialogue,
    '''
    global run
    global chatObject
    global show_whole_chat_flag
    global move_to_next_chatwin_flag
    global clock
    global background_image
    global surf_bckgnd

    background_image = back_image

    if back_image:
        surf_bckgnd = pygame.image.load(os.path.join('storyboards',
                                                     back_image)).convert()
        surf_bckgnd = pygame.transform.scale(surf_bckgnd,
                                             threades.resize_pos((1200, 900)))

    chatObject = chat()
    chatObject.chatWindow()
    clock = pygame.time.Clock()
    show_whole_chat_flag = False
    move_to_next_chatwin_flag = False
    i = 0
    i_incrementor = False
    run = True
    allowed = True
    global desktop2
    while run:
        if len(chatText) == 0:
            break

        for e in gui.setEvents(pygame.event.get()):
            chat_event_handle(e)

        if back_image:
            threades.screen.blit(surf_bckgnd, (0, 0))

        desktopChat.update()

        desktopChat.draw()

        pygame.display.update()
        #print chatObject.button_skip.enabled

        if (model.global_time >= 10000) or (i == 0 and allowed == True) or (
                show_whole_chat_flag == True):
            if i == 0:
                allowed = False
            if i_incrementor == True:
                i += 2
            model.global_time = 0

            #pygame.display.update()

            chatObject.addChat(chatText[i], chatText[i + 1])
            if run == False:
                print 'reaching here also finely'
            i_incrementor = True

        max_iterations = (len(chatText) - 2)
        if i == max_iterations:
            while (model.global_time < 10000 and show_whole_chat_flag
                   == False) or (show_whole_chat_flag == True
                                 and move_to_next_chatwin_flag == False):
                model.iteration_time = clock.tick()
                model.global_time += model.iteration_time
                for e in gui.setEvents(pygame.event.get()):
                    chat_event_handle(e)
                if back_image:
                    threades.screen.blit(surf_bckgnd, (0, 0))

                desktopChat.update()
                desktopChat.draw()
                pygame.display.flip()
                if run == False:
                    break
            run = False

        model.iteration_time = clock.tick()
        model.global_time += model.iteration_time

    surf_bckgnd = None
    chatObject.closeChatWindow()
Beispiel #22
0
    def DrawGame(self,flip=True):

	screen = self.screen
	g = self.g
	p = self.p
	playernames = self.g.playernames

	# DRAWING           
	screen.fill((0x00, 0xb0, 0x00))
	#Stage area
	pygame.draw.rect(screen,(0,0,0),(g.curstagexy[0]-5,g.curstagexy[1]-5,g.curstagexy[2]+10,g.curstagexy[3]+10))
	pygame.draw.rect(screen,(0,255,0),g.curstagexy)

	sr = screen.get_rect()
	centerx = sr.centerx
	centery = sr.centery

	#Turn arrows
	arrow_length = 30
	headw = 10
	headl = 15
	if g.turn==0:
	    fl = [[(centerx,centery+20),(centerx,centery+20+arrow_length)],
		  [(centerx-headw,centery+20+arrow_length-headl),(centerx,centery+20+arrow_length)],
		  [(centerx+headw,centery+20+arrow_length-headl),(centerx,centery+20+arrow_length)]]
	elif g.turn==1:
	    fl = [[(centerx-90,centery-50),(centerx-90-arrow_length,centery-50)],
		  [(centerx-90-arrow_length+headl,centery-50-headw),(centerx-90-arrow_length,centery-50)],
		  [(centerx-90-arrow_length+headl,centery-50+headw),(centerx-90-arrow_length,centery-50)]]
	elif g.turn==2:
	    fl = [[(centerx,centery-90),(centerx,centery-90-arrow_length)],
		  [(centerx-headw,centery-90-arrow_length+headl),(centerx,centery-90-arrow_length)],
		  [(centerx+headw,centery-90-arrow_length+headl),(centerx,centery-90-arrow_length)]]
	elif g.turn==3:
	    fl = [[(centerx+100,centery-50),(centerx+100+arrow_length,centery-50)],
		  [(centerx+100+arrow_length-headl,centery-headw-50),(centerx+100+arrow_length,centery-50)],
		  [(centerx+100+arrow_length-headl,centery+headw-50),(centerx+100+arrow_length,centery-50)]]
	for points in fl:
	    pygame.draw.aaline(screen,(200,0,0), points[0], points[1])

	if g.roundOver:
	    for c in g.cardGroup.cards:
		if (c.side==0) & c.location in range(3,401):
		    c.flip()

	pygame.draw.rect(screen,(0,0,0),(g.curlocxy[1][0]+2,g.curlocxy[1][1]+2,70,90),2)

	g.cardGroup.draw(screen)

	if g.selectionRect.width > 0 and g.selectionRect.height > 0:
	    pygame.draw.rect(screen,(0xff,0xff,0x00),g.selectionRect,3)

	if g.curState().turnState == PRE_DRAW:
	    state_text = "Draw or pick up"
	else:
	    state_text = "Meld or discard"
	    
	#Score area
	pygame.draw.rect(screen,(0,0,0),(g.curscorex-5,5,280,60))
	pygame.draw.rect(screen,(0,0,255),(g.curscorex,10,270,50))

	font = pygame.font.Font("freesansbold.ttf", 14)
	font2 = pygame.font.Font("FreeSans.ttf", 14)
	roundtext = font.render("%s%s" % ("ROUND ",g.round),1,(255,255,255))
	team1text = font.render("%s%s" % ("Team 1: ",g.team1score),1,(255,255,255))
	team2text = font.render("%s%s" % ("Team 2: ",g.team2score),1,(255,255,255))
	curteamtext = font2.render("%s%s%s" % (playernames[g.turn],": ",state_text),1,(255,255,255))	
	
	roundpos = roundtext.get_rect()
	roundpos.centerx = g.curscorex + 40
	roundpos.centery = 23
	team1pos = roundtext.get_rect()
	team1pos.centerx = g.curscorex + 110
	team1pos.centery = 23
	team2pos = roundtext.get_rect()
	team2pos.centerx = g.curscorex + 210
	team2pos.centery = 23
	curteampos = roundtext.get_rect()
	curteampos.centerx = g.curscorex + 40
	curteampos.centery = 43
	screen.blit(roundtext,roundpos)
	screen.blit(team1text,team1pos)
	screen.blit(team2text,team2pos)
	screen.blit(curteamtext,curteampos)

        #Chat window

	self.chatwin.chatdisplay.text = ""

	if not self.chatwin.shaded:
	    for i in range(-1,-8,-1):
		try:
		    text = self.g.chatlist[i]
		    count = 0
		    rendered = gui.wrapText(text + "\n" + self.chatwin.chatdisplay.text,self.chatwin.chatdisplay.style['font'],self.chatwin.chatdisplay.size[0])
		    for char in rendered: 
			if char=="\n": count += 1
		    if count<9:
			self.chatwin.chatdisplay.text = self.g.chatlist[i] + "\n" +self.chatwin.chatdisplay.text
		except: pass

	gui.setEvents()
	try:
	    self.desktop.update()
	except: pass
	self.desktop.draw()

	if flip: pygame.display.flip()
    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
def main():
    pygame.init()
    screen = pygame.display.set_mode((X,Y), RESIZABLE)
    fullscreen = False
    clock = pygame.time.Clock()
    initStyle()
    desktop = ControlCenterDesktop()
    try:
        while desktop.running:
            clock.tick()
            # Update FPS display
            desktop.fps_label.text = str(int(clock.get_fps()))
            # Handle Events
            events = [pygame.event.wait(),]+pygame.event.get()
            for event in events:
                if event.type == QUIT:
                    desktop.running = False
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    desktop.running = False
                elif event.type == KEYDOWN and event.key == K_f:
                    if not fullscreen:
                        screen = pygame.display.set_mode((X,Y), FULLSCREEN)
                        fullscreen = True
                    else:
                        screen = pygame.display.set_mode((X,Y), RESIZABLE)
                        fullscreen = False
                elif event.type == VIDEORESIZE:
                    screen = pygame.display.set_mode(event.size, RESIZABLE)
                elif desktop.joy == None:
                    continue
                elif event.type == JOYAXISMOTION:
                    desktop.joy.axis[event.axis] = event.value
                elif event.type == JOYBALLMOTION:
                    desktop.joy.ball[event.ball] = event.rel
                elif event.type == JOYHATMOTION:
                    desktop.joy.hat[event.hat] = event.value
                elif event.type == JOYBUTTONUP:
                    desktop.joy.button[event.button] = 0
                elif event.type == JOYBUTTONDOWN:
                    desktop.joy.button[event.button] = 1
            # End For loop
            # Update the excavator
            desktop.excavator.update(desktop.joy)
            # try:
            #     desktop.logerr(desktop.excavator.comm_port.read_some())
            # except:
            #     pass
            # Pass along the events
            gui.setEvents(events)
            # Update the Desktop
            desktop.update()
            # Begin Rendering
            screen.fill((20,40,50))
            screen.blit(desktop.bg_image, (0,0))
            desktop.draw()
            pygame.display.flip()
    except:
        logError(sys.exc_info(), log, "Exception in main Loop: ")
    finally:
        desktop.close()
    # After exiting the while loop quit
    pygame.quit()
Beispiel #25
0
def showChat(chatText, back_image=None):

    """ Chat text should be a list with first the name
        of the character and then his dialogue,
    """
    global run
    global chatObject
    global show_whole_chat_flag
    global move_to_next_chatwin_flag
    global clock
    global background_image
    global surf_bckgnd

    background_image = back_image

    if back_image:
        surf_bckgnd = pygame.image.load(os.path.join("storyboards", back_image)).convert()
        surf_bckgnd = pygame.transform.scale(surf_bckgnd, threades.resize_pos((1200, 900)))

    chatObject = chat()
    chatObject.chatWindow()
    clock = pygame.time.Clock()
    show_whole_chat_flag = False
    move_to_next_chatwin_flag = False
    i = 0
    i_incrementor = False
    run = True
    allowed = True
    global desktop2
    while run:
        if len(chatText) == 0:
            break

        for e in gui.setEvents(pygame.event.get()):
            chat_event_handle(e)

        if back_image:
            threades.screen.blit(surf_bckgnd, (0, 0))

        desktopChat.update()

        desktopChat.draw()

        pygame.display.update()
        # print chatObject.button_skip.enabled

        if (model.global_time >= 10000) or (i == 0 and allowed == True) or (show_whole_chat_flag == True):
            if i == 0:
                allowed = False
            if i_incrementor == True:
                i += 2
            model.global_time = 0

            # pygame.display.update()

            chatObject.addChat(chatText[i], chatText[i + 1])
            if run == False:
                print "reaching here also finely"
            i_incrementor = True

        max_iterations = len(chatText) - 2
        if i == max_iterations:
            while (model.global_time < 10000 and show_whole_chat_flag == False) or (
                show_whole_chat_flag == True and move_to_next_chatwin_flag == False
            ):
                model.iteration_time = clock.tick()
                model.global_time += model.iteration_time
                for e in gui.setEvents(pygame.event.get()):
                    chat_event_handle(e)
                if back_image:
                    threades.screen.blit(surf_bckgnd, (0, 0))

                desktopChat.update()
                desktopChat.draw()
                pygame.display.flip()
                if run == False:
                    break
            run = False

        model.iteration_time = clock.tick()
        model.global_time += model.iteration_time

    surf_bckgnd = None
    chatObject.closeChatWindow()
    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()
def main():

    global panel
    global chat_screen
    global level_setting
    global update_thread
    global message_thread
    
    cursor = pygame.cursors.load_xbm(os.path.join('art', 'ff2_cursor.xbm'),os.path.join('art', 'ff2_cursor-mask.xbm'))
    #print cursor
    pygame.mouse.set_cursor(cursor[0],cursor[1],cursor[2],cursor[3])
    # Displaying the WFP logo
    intro_thread = threading.Thread(target = load_images.load_images, args=[])
    intro_thread.start()
    # Loading and starting the sound play
    #level_setting=level_change.change_level()
    
    #Checks the level on which 	he user is
    threades.current_level = threades.check_saved_game_level()
    
    
    #Resets the time
    model.game_controller.reset_time()
    
    #Initialises and creates the starting screen and pauses the game until the user gives an input
    pause_screen()
    #Lets the initial thread started to get completed
    intro_thread.join()
    
    
        
    
    proceduralFlow.storyboard_level = threades.current_level
    
     #Takes action according to the level
    if threades.current_level != 1:
        load_resume_game()
    else:
        threades.initialize_facilities(True)
        proceduralFlow.openStoryBoardFile()

     
    # Processing regarding the storyboard
    
    storyboardObj = proceduralFlow.storyboardFlow()
    
    gui_buttons.initialize_gui()

    threades.screen.fill((0,0,0))
    panel = display_panel.display_panel()
    animation_obj = threades.Animation()
    animation_obj.update()
    # Starting of the threads
    update_thread = threading.Thread(target = threades.update_turn, args=[])
    update_thread.start()
    #print update_thread
    message_thread = threading.Thread(target = message_window, args=[])
    message_thread.start()
    mouse_flag = False
    chat_screen=chat.chat()
        
    
    # The main infinite loop
    while True:
        #clock.tick()
        model.game_controller.update_level_time(threades.update_thread_pause)
        
        animation_obj.update()


        mouse_flag = False
            
        (x,y) = (0,0)
        x,y = pygame.mouse.get_pos()
        
        if len(threades.buildFacilityPlacementFlag):
            facility_placement()               
        if (x > (threades.resize_pt_x(890)) and x < threades.resize_pt_x(930)):
            threades.transform_obj.move_free((-10,0))
            
        if x < threades.resize_pt_x(60) :
            threades.transform_obj.move_free((10,0))
            
        if  y > threades.resize_pt_y(560) and y< threades.resize_pt_y(600):
            threades.transform_obj.move_free((0,-10))
            
        if y < threades.resize_pt_y(60):
            threades.transform_obj.move_free((0,10))
            
        if (x > threades.resize_pt_x(0)) and (x < threades.resize_pt_x(600)) and (y > threades.resize_pt_y(845)) and (y < threades.resize_pt_y(900)):
            mouse_flag = True
            
        pygame.display.set_caption('FoodForce2')

        for e in gui.setEvents(pygame.event.get()):
            event_handling(e)

        
        

        # Calculate the values of the indicators
        threades.calculate_indicators_starting()
        
               

        #updating the region
        rects_list = get_update_region()
        panel.update()
        
        if (threades.total_update_flag or threades.map_update_flag or threades.facilities_update_flag or threades.panel_update_flag or panel.res.money_flag):
            threades.desktop.update()
            threades.desktop.draw()
        
        pygame.display.update(rects_list)

        #updates the time
        model.iteration_time = clock.tick()
        model.global_time += model.iteration_time
        
        #Calls the function which decides which action to be taken
        storyboardObj.flow()
Beispiel #28
0
    def addChat(self, playerName=None, message=''):
        ''' Adds Chat to the chat window
            playerName tells the name of the character whose image to be used
            and message sends his mesage.
        '''

        #TODO: Make a list of all the characters and make their pics
        # and load them in a dictionary with their names as keys
        # Assuming the dictionary to be playerCharactersImages
        global clock
        global desktopChat
        global move_to_next_chatwin_flag
        global run
        self.myfont = pygame.font.Font("font.ttf", 20)
        textColor = (0, 0, 0)

        #textsurface-the surface on which the text appears
        textSurface = gui.renderText(
            message, self.myfont, True, textColor, (635, 500), False, True
        )  #here 500(y-coordinate) doesn't make any difference , not used in gui.renderText

        #my_rect=pygame.Rect((0,0,500,500))
        #textSurface=render_textrect(message,self.myfont, my_rect, textColor, None, justification=0)
        tempsize = textSurface.get_size()

        #print tempsize[0],tempsize[1]

        #tempsize2 - Variable that holds the dimensions of the textsurface that would be required to show the chat text
        tempsize2 = tempsize[1] + 50

        #Checks that the size of the text is greater than the size of the textbox or not
        #it adjusts the size of the surface created according to the text length
        if tempsize2 > 120:
            tempSurface = pygame.transform.scale(self.chatBox,
                                                 (720, tempsize[1] + 50))
        else:
            tempSurface = pygame.transform.scale(self.chatBox, (720, 120))

        #print 'color key is ',tempSurface.get_colorkey()
        tempSurface.blit(textSurface, (50, 25))
        tempsize2 = tempSurface.get_size()
        #print (tempSurface.get_size())[0],(tempSurface.get_size())[1]

        dim_y = 0  ##height of the chatbox

        #It adjusts the size of the chat box accroding to the text length
        if tempsize2[1] > 120:
            dim_y = tempsize2[1]
        else:
            dim_y = 120

        finalSurface = pygame.surface.Surface(
            (870, dim_y + 30)).convert_alpha()
        finalSurface.fill((0, 0, 0, 0))
        #pos_of_image_on_finalsurface=(((dim_y)/2)-60)+15
        finalSurface.blit(self.imageBox, (15, 15))
        finalSurface.blit(tempSurface, (135, 15))
        #finalSurface.blit(playerCharactersImages[playerName],(24,24))
        finalSurface.blit(self.characterImage[str.upper(playerName)],
                          (24, 15 + 9))

        finalSurface = pygame.transform.scale(
            finalSurface, threades.resize_pos(finalSurface.get_size()))
        tempsize = finalSurface.get_size()
        dim_y = tempsize[1]
        #print 'self.position is',self.position[1]
        #print 'dim_y is',dim_y
        #print 'final position is',self.final_position[1]

        #Checks if the next chat needs to be blitted to next window or not
        if (self.position[1] + dim_y) > self.final_position[1]:
            #self.chatWin.size = threades.resize_pos((900,20))

            #print 'its in this time'
            #print 'self.position is',self.position[1]
            #print 'dim_y is',dim_y
            #print 'final position is',self.final_position[1]

            #code to ensure that a new window is not opened until the user presses enter/next again
            if show_whole_chat_flag == True:
                while move_to_next_chatwin_flag == False:
                    for e in gui.setEvents(pygame.event.get()):
                        chat_event_handle(e)

                    if background_image:
                        threades.screen.blit(surf_bckgnd, (0, 0))

                    desktopChat.update()
                    desktopChat.draw()
                    pygame.display.update()
                    model.iteration_time = clock.tick()
                    model.global_time += model.iteration_time
                    if run == False:

                        return

            self.closeChatWindow()
            self.chatWindow()
            self.position = self.initial_position
            self.chatWin.surf.blit(finalSurface, self.position)
            self.position = (self.position[0], self.position[1] + dim_y)
        else:
            #x_coordinate=threades.resize_pt_x(900)
            #y_coordinate=self.chatWin.size[1]+dim_y
            #self.chatWin.size=(x_coordinate,y_coordinate)
            self.chatWin.surf.blit(finalSurface, self.position)
            # self.position[1] += dim_y
            self.position = (self.position[0], self.position[1] + dim_y)
    def showFailureWindow(self,text):
        
        self.brown_color = (255,214,150) 
        self.green_color = (0,250,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.brown_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = self.brown_color
        win_style['border-width'] = 2
        
        st_desktop = gui.Desktop()
        clock = pygame.time.Clock()
        clock.tick()
        
        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,100.0))
        size_win =threades.resize_pos((900.0,500.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = " FoodForce2" , 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

        myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 0
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.brown_color
        labelStyleCopy['border-color'] = self.black_color
        
        self.storyboardwin_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((100.0,100.0),(900.0,500.0),self.win.size),size = threades.resize_pos((700.0,340.0),(900.0,500.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy)

        gl_time = 0
        
        st_desktop.update()
        st_desktop.draw()
        pygame.display.update()
        
        while self.storyboardwin_run:
            pygame.display.set_caption('FoodForce2')
            
            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.storyboardwin_run = False
                        
            gl_time += clock.tick()
            if gl_time >= 17000:
                self.storyboardwin_run = False
                
            
            
            
        event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0)
        game_events.EventQueue.add(event)
    def instructionsWindow(self,button = None):
        ''' Opens a window for Instructions
        '''
        
        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 = "     Guide" , 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

        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.skip_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 = "  Skip  ",style = self.button_style)
        self.next_button = gui.Button(position = threades.resize_pos((380,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 = "  Next > ",style = self.button_style)
        self.prev_button = gui.Button(position = threades.resize_pos((260,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 = "  < Prev  ",style = self.button_style)

        self.next_button.onClick = self.increaseInstructionsCounter
        self.prev_button.onClick = self.decreaseInstructionsCounter
        self.skip_button.onClick = self.close_win
        self.instructions_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.instructions_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.instruction_text[self.instructions_counter]
            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.instructions_run = False
                        self.win.close()
                    if e.key == K_RIGHT:
                        if self.instructions_counter < len(texts.instruction_text)-1:
                            self.instructions_counter += 1
                    if e.key == K_LEFT:
                        if self.instructions_counter > 0 :
                            self.instructions_counter -= 1

            desktop2.update()
            desktop2.draw()
            pygame.display.update()
    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()
    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 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()
        

        # Creating gui to select which storyboard to start
        
        self.sbWin = gui.Window(position = position_win, size = size_win, parent = desktop2, text = " FOODFORCE II : Choose Storyboard  " ,style = win_style,shadeable = False, closeable = False,moveable = False)

        self.sbWin.surf.fill((0,0,0,170))
        
        # creating custom style for option box
        op_style = gui.defaultOptionBoxStyle.copy()
        op_style['font'] = myfont2
        op_style['font-color'] = color_brown
        op_style['autosize'] = True
        op_style['word wrap'] = False
        position_optionbox = threades.resize_pos((200.0,150.0),(800.0,600.0),size_win)        
        self.storyboard1 = gui.OptionBox(position = position_optionbox, parent = self.sbWin, style = op_style, text = 'Storyboard1')
        self.storyboard2 = gui.OptionBox(position = self.sbWin.nextPosition(threades.resize_pt_y(10)), parent = self.sbWin, style = op_style, text = 'Storyboard2')
        
        # Creating a button style
        button_style = gui.defaultButtonStyle.copy()
        button_style['font'] = myfont2
        
        self.select_button = gui.Button(position = threades.resize_pos((600,550),(800.0,600.0),size_win), size = threades.resize_pos((150,30),(800.0,600.0),size_win), parent = self.sbWin, text = "  Select  ",style = button_style)
        self.select_button.onClick = self.set_selected_storyboard
    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()
Beispiel #34
0
    def addChat(self,playerName = None,message = ''):
        
        ''' Adds Chat to the chat window
            playerName tells the name of the character whose image to be used
            and message sends his mesage.
        '''
        
        #TODO: Make a list of all the characters and make their pics
        # and load them in a dictionary with their names as keys
        # Assuming the dictionary to be playerCharactersImages
        global clock
        global desktopChat
        global move_to_next_chatwin_flag
        global run
        self.myfont = pygame.font.Font("font.ttf",20)
        textColor = (0,0,0)
        
        #textsurface-the surface on which the text appears
        textSurface = gui.renderText(message,self.myfont,True,textColor,(635,500),False,True)    #here 500(y-coordinate) doesn't make any difference , not used in gui.renderText
        
        #my_rect=pygame.Rect((0,0,500,500))
        #textSurface=render_textrect(message,self.myfont, my_rect, textColor, None, justification=0)
        tempsize = textSurface.get_size()
        
        
        #print tempsize[0],tempsize[1]
       
        #tempsize2 - Variable that holds the dimensions of the textsurface that would be required to show the chat text
        tempsize2=tempsize[1]+50
        
        #Checks that the size of the text is greater than the size of the textbox or not
        #it adjusts the size of the surface created according to the text length
        if tempsize2>120:
            tempSurface = pygame.transform.scale(self.chatBox,(720,tempsize[1]+50))
        else:
            tempSurface = pygame.transform.scale(self.chatBox,(720,120))
            
        #print 'color key is ',tempSurface.get_colorkey()
        tempSurface.blit(textSurface,(50,25))
        tempsize2=tempSurface.get_size()
        #print (tempSurface.get_size())[0],(tempSurface.get_size())[1]
        
        
        dim_y = 0                                                ##height of the chatbox
        
        #It adjusts the size of the chat box accroding to the text length 
        if tempsize2[1]>120 :
            dim_y = tempsize2[1]
        else:
            dim_y = 120
            
        finalSurface = pygame.surface.Surface((870,dim_y+30)).convert_alpha()
        finalSurface.fill((0,0,0,0))
        #pos_of_image_on_finalsurface=(((dim_y)/2)-60)+15
        finalSurface.blit(self.imageBox,(15,15))
        finalSurface.blit(tempSurface,(135,15))
        #finalSurface.blit(playerCharactersImages[playerName],(24,24))
        finalSurface.blit(self.characterImage[str.upper(playerName)],(24,15+9))
        
        finalSurface = pygame.transform.scale(finalSurface,threades.resize_pos(finalSurface.get_size()))
        tempsize = finalSurface.get_size()
        dim_y = tempsize[1]
        #print 'self.position is',self.position[1]
        #print 'dim_y is',dim_y
        #print 'final position is',self.final_position[1]
        
        #Checks if the next chat needs to be blitted to next window or not
        if (self.position[1]+ dim_y) > self.final_position[1]:
            #self.chatWin.size = threades.resize_pos((900,20))

            #print 'its in this time'
            #print 'self.position is',self.position[1]
            #print 'dim_y is',dim_y
            #print 'final position is',self.final_position[1]
            
            #code to ensure that a new window is not opened until the user presses enter/next again
            if show_whole_chat_flag==True:
                while move_to_next_chatwin_flag==False:
                    for e in gui.setEvents(pygame.event.get()):
                        chat_event_handle(e)
                        
                    
                    if background_image:
                        threades.screen.blit(surf_bckgnd,(0,0))
                        
                    desktopChat.update()
                    desktopChat.draw()
                    pygame.display.update() 
                    model.iteration_time = clock.tick()
                    model.global_time += model.iteration_time
                    if run==False:
                        
                        return
            
            self.closeChatWindow()
            self.chatWindow()
            self.position = self.initial_position
            self.chatWin.surf.blit(finalSurface,self.position)
            self.position=(self.position[0],self.position[1]+dim_y)
        else:
            #x_coordinate=threades.resize_pt_x(900)
            #y_coordinate=self.chatWin.size[1]+dim_y
            #self.chatWin.size=(x_coordinate,y_coordinate)
            self.chatWin.surf.blit(finalSurface,self.position)
           # self.position[1] += dim_y
            self.position=(self.position[0],self.position[1]+dim_y)
def main():

    global panel
    global chat_screen
    global level_setting
    
    # Displaying the WFP logo
    intro_thread = threading.Thread(target = load_images.load_images, args=[])
    intro_thread.start()
    # Loading and starting the sound play
    GameSounds.objMusic.start_music()
    
    level_setting=level_change.change_level()
    pause_screen()

    intro_thread.join()
    threades.initialize_facilities()

    #surface_middle = pygame.transform.scale(surface3,threades.resize_pos((1200,560)))
    
    # Processing regarding the storyboard
    proceduralFlow.openStoryBoardFile()
    storyboardObj = proceduralFlow.storyboardFlow()
    proceduralFlow.openStoryBoardFile()

    gui_buttons.initialize_gui()

    threades.screen.fill((0,0,0))
    panel = display_panel.display_panel()
    animation_obj = threades.Animation()
    animation_obj.update()
    # Starting of the threads
    update_thread = threading.Thread(target = threades.update_turn, args=[]).start()
    message_thread = threading.Thread(target = message_window, args=[]).start()
    mouse_flag = False
    chat_screen=chat.chat()
        
    model.game_controller.reset_time()
    # The main infinite loop
    while True:
        #clock.tick()
        model.game_controller.update_level_time()
        

        mouse_flag = False
            
        (x,y) = (0,0)
        x,y = pygame.mouse.get_pos()
        
        if ((x < threades.new_screen_size[0]) and (x > (threades.new_screen_size[0]-60))):
            threades.transform_obj.move_free((0,0))
            
        if (x < 60 and x > 0):
            threades.transform_obj.move_free((0,0))
            
        if (y < threades.resize_pt_y(900)) and (y > threades.resize_pt_y(840)):
            threades.transform_obj.move_free((0,0))
            
        if ((y < threades.resize_pt_y(60)) and (y > threades.resize_pt_y(0))):
            threades.transform_obj.move_free((0,0))
            
        if (x > threades.resize_pt_x(0)) and (x < threades.resize_pt_x(600)) and (y > threades.resize_pt_y(845)) and (y < threades.resize_pt_y(900)):
            mouse_flag = True
            
        pygame.display.set_caption('FoodForce2')

        for e in gui.setEvents(pygame.event.get()):
            event_handling(e)

        
        #pygame.draw.rect(threades.screen,(209,169,106),threades.resize_rect((0,40,1200,560)))
        animation_obj.update()


        # Claculate indicators again
        threades.calculate_indicators_starting()
        
        #For middle surface
        #surface_middle = pygame.transform.scale(surface3,threades.resize_pos((1200,560)))
        #threades.screen.blit(surface_middle,threades.resize_pos((0,40)))

        

        
        rects_list = get_update_region()
        panel.update()
        
        if (threades.total_update_flag or threades.map_update_flag or threades.facilities_update_flag or threades.panel_update_flag or panel.res.money_flag):
            threades.desktop.update()
            threades.desktop.draw()
        
        pygame.display.update(rects_list)

        model.iteration_time = clock.tick()
        model.global_time += model.iteration_time
        storyboardObj.flow()
Beispiel #36
0
def showChat(chatText,back_image=None):
    
    ''' Chat text should be a list with first the name
        of the character and then his dialogue,
    '''
    global run
    global chatObject
    global show_whole_chat_flag
    global move_to_next_chatwin_flag
    global clock
    global background_image
    global surf_bckgnd    
    
    background_image= back_image

    if back_image:
        surf_bckgnd = pygame.image.load(os.path.join('storyboards',back_image)).convert()
        surf_bckgnd = pygame.transform.scale(surf_bckgnd,threades.resize_pos((1200,900)))
         
    chatObject = chat()
    chatObject.chatWindow()
    clock = pygame.time.Clock()
    show_whole_chat_flag=False
    move_to_next_chatwin_flag=False
    i = 0                                                  #Used as an index of the list(chatText)  
    i_incrementor =False
    run = True
    allowed=True                          #used to skip the checking of time for the first chat
    global desktop2
    while run:
        if len(chatText)==0:
            break
        
        for e in gui.setEvents(pygame.event.get()):
            chat_event_handle(e)
        
        if back_image:
            threades.screen.blit(surf_bckgnd,(0,0))
            
        desktopChat.update()
        
        
        desktopChat.draw()
       
        pygame.display.update() 
        #print chatObject.button_skip.enabled
                
          #Checks the conditions for which we have to show the next chat        
        if (model.global_time >= 10000) or (i==0 and allowed==True) or (show_whole_chat_flag==True):
                if i==0:
                    allowed=False
                if  i_incrementor==True:
                    i+=2                           #Increased by 2 so as to move on to next dialogue(Check the structure of chatText)
                model.global_time = 0
                
        #pygame.display.update()
                
                
                chatObject.addChat(chatText[i],chatText[i+1])
                if run==False:
                    print 'reaching here also finely'
                i_incrementor=True
            
        
       
        max_iterations=(len(chatText)-2)                     #No of dialogues 
        if i == max_iterations:
            
            #Checks the conditions for which we dont have to show the next chat
            while (model.global_time<10000 and show_whole_chat_flag==False) or (show_whole_chat_flag==True and move_to_next_chatwin_flag==False) :
                model.iteration_time = clock.tick()
                model.global_time += model.iteration_time
                for e in gui.setEvents(pygame.event.get()):
                    chat_event_handle(e)
                if back_image:
                    threades.screen.blit(surf_bckgnd,(0,0))
                    
                desktopChat.update()
                desktopChat.draw()
                pygame.display.flip()
                if run==False:
                    break
            run = False
                     
        
        model.iteration_time = clock.tick()
        model.global_time += model.iteration_time  
       
        
    surf_bckgnd = None
    chatObject.closeChatWindow()