tagBack = False #pygame.time.set_timer(TAGEVENT, 1000) while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True #if event.type == TAGEVENT: #for enemy in enemyList: #enemy.calculateNeighbors() #tagBack = False #TAGEVENT = pygame.USEREVENT #pygame.time.set_timer(TAGEVENT, 1000) screen.fill((Constants.BACKGROUND_COLOR)) player.update(Vector(Constants.WORLD_WIDTH, Constants.WORLD_HEIGHT)) player.draw(screen) for sheep in enemyList: #enemy.update(player, Vector(Constants.WORLD_WIDTH, Constants.WORLD_HEIGHT)) #enemy.draw(screen, player) sheep.update(player, Vector(Constants.WORLD_WIDTH, Constants.WORLD_HEIGHT)) sheep.draw(screen, player) #if enemy.noTagBacks and not tagBack: # tagBack = True #pygame.time.set_timer(TAGEVENT, 1000) pygame.display.flip() clock.tick(Constants.FRAME_RATE)
Constants.BOUNDING_BOXES = not Constants.BOUNDING_BOXES # Force toggles elif event.key == pygame.K_6: Constants.DOG_FORCES = not Constants.DOG_FORCES elif event.key == pygame.K_7: Constants.ALIGNMENT_FORCES = not Constants.ALIGNMENT_FORCES elif event.key == pygame.K_8: Constants.SEPARATION_FORCES = not Constants.SEPARATION_FORCES elif event.key == pygame.K_9: Constants.COHESION_FORCES = not Constants.COHESION_FORCES elif event.key == pygame.K_0: Constants.BOUNDARY_FORCES = not Constants.BOUNDARY_FORCES # Update agents dog.update() for sheep in sheeps: sheep.update(dog, sheeps) # Draw background screen.fill(Constants.BACKGROUND_COLOR) # Draw agents dog.draw(screen) for sheep in sheeps: sheep.draw(screen, dog) # Flip buffer pygame.display.flip() # Tick clock at 60FPS clock.tick(Constants.FRAME_RATE)
hasQuit = True # Change graph search type elif event.type == pygame.KEYDOWN: if event.key == pygame.K_a: graph.searchType = SearchType.A_STAR elif event.key == pygame.K_s: graph.searchType = SearchType.BEST_FIRST elif event.key == pygame.K_d: graph.searchType = SearchType.DJIKSTRA elif event.key == pygame.K_f: graph.searchType = SearchType.BREADTH_FIRST # Update the agents onscreen # dog.update(bounds, graph, herd, Constants.GATES) dog.update(graph, sheep) for sheep in herd: # sheep.update(bounds, graph, dog, herd, Constants.GATES) sheep.update(dog, herd, graph.obstacles) # Draw the agents onscreen graph.draw(screen) dog.draw(screen) for sheep in herd: sheep.draw(screen, dog) # Double buffer pygame.display.flip() # Limit to 60 FPS clock.tick(Constants.FRAME_RATE)
if event.key == pygame.K_d: Constants.enable_djikstra = True Constants.enable_breadth_first = False Constants.enable_aStar = False Constants.enable_best = False if event.key == pygame.K_f: Constants.enable_breadth_first = True Constants.enable_aStar = False Constants.enable_djikstra = False Constants.enable_best = False if event.type == pygame.QUIT: done = True # Update agents #cant inherit on player without these parameters??? dog.update(dog, Constants.ENEMY_RANGE) for x in range(len(sheep_list)): sheep_list[x].update(dog, Constants.ENEMY_RANGE, sheep_list, Constants.GATES) #pathfinding less than every frame( ideally once every 1/6 of a second) patienceCounter += 1 if (patienceCounter >= 20): if (Constants.enable_aStar): graph.findPath_AStar(dog.pos, sheep.pos) elif (Constants.enable_breadth_first): graph.findPath_Breadth(dog.pos, sheep.pos) elif (Constants.enable_djikstra): graph.findPath_Djikstra(dog.pos, sheep.pos) elif (Constants.enable_best):