def facility_placement(): """ Checks the collision and if the place is free builds the facility at that particular position """ (x,y) = (0,0) x,y = pygame.mouse.get_pos() gui_buttons.gui_obj.setup_button.enabled = False facility_name = threades.buildFacilityPlacementFlag #Sets the variable to the facility which is to be build for i in range(len(model.Facility_Size)): if model.Facility_Size[i][0] == facility_name: height = model.Facility_Size[i][1] width = model.Facility_Size[i][2] height_temp = threades.resize_pt_y((model.Facility_Size[i][1])*threades.transform_obj.ratio) width_temp = threades.resize_pt_x((model.Facility_Size[i][2])*threades.transform_obj.ratio) #Checking the bounds if x > threades.resize_pt_x(930): pygame.mouse.set_pos(threades.resize_pt_x(930),y) if y > threades.resize_pt_y(600): pygame.mouse.set_pos(x,threades.resize_pt_y(600)) #Creating the rectangle in which the facility is built rect = (x,y,width,height) rect_temp = (x,y,width_temp,height_temp) rect_obj = pygame.Rect(rect) rect_obj_temp = pygame.Rect(rect_temp) #Checks the collision collide_check = threades.place_facility_collide_check(rect_obj) if collide_check: color = (205,0,0) else: color = (205,200,100) pygame.draw.rect(threades.screen,color,rect_obj_temp,5) #Takes action of the user and performs the action l,m,r = pygame.mouse.get_pressed() if l == 1 and collide_check == False: (a,b) = threades.transform_obj.inverse_trans_cordinate((x,y)) rect_obj_send = pygame.Rect((a,b,width_temp,height_temp)) PLACING_DATA_LIST = [threades.buildFacilityPlacementFlag,rect_obj_send] threades.build_placed_facility(threades.buildFacilityPlacementFlag,False,PLACING_DATA_LIST) threades.set_build_facility_placement_flag() gui_buttons.gui_obj.setup_button.enabled = True if r == 1: threades.set_build_facility_placement_flag() gui_buttons.gui_obj.setup_button.enabled = True
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()
def facility_placement(): (x,y) = (0,0) x,y = pygame.mouse.get_pos() gui_buttons.gui_obj.setup_button.enabled = False facility_name = threades.buildFacilityPlacementFlag for i in range(len(model.Facility_Size)): if model.Facility_Size[i][0] == facility_name: height = model.Facility_Size[i][1] width = model.Facility_Size[i][2] height_temp = threades.resize_pt_y((model.Facility_Size[i][1])*threades.transform_obj.ratio) width_temp = threades.resize_pt_x((model.Facility_Size[i][2])*threades.transform_obj.ratio) if x > threades.resize_pt_x(930): pygame.mouse.set_pos(threades.resize_pt_x(930),y) if y > threades.resize_pt_y(600): pygame.mouse.set_pos(x,threades.resize_pt_y(600)) x -= width_temp/2 y -= height_temp/2 rect = (x,y,width,height) rect_temp = (x,y,width_temp,height_temp) rect_obj = pygame.Rect(rect) rect_obj_temp = pygame.Rect(rect_temp) collide_check = threades.place_facility_collide_check(rect_obj) if collide_check: color = (205,0,0) else: color = (205,200,100) pygame.draw.rect(threades.screen,color,rect_obj_temp,5) l,m,r = pygame.mouse.get_pressed() if l == 1 and collide_check == False: (a,b) = threades.transform_obj.inverse_trans_cordinate((x,y)) rect_obj_send = pygame.Rect((a,b,width_temp,height_temp)) PLACING_DATA_LIST = [threades.buildFacilityPlacementFlag,rect_obj_send] threades.build_placed_facility(threades.buildFacilityPlacementFlag,False,PLACING_DATA_LIST) threades.set_build_facility_placement_flag() gui_buttons.gui_obj.setup_button.enabled = True if r == 1: threades.set_build_facility_placement_flag() gui_buttons.gui_obj.setup_button.enabled = True
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()