Ejemplo n.º 1
0
        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)

# Quit
pygame.quit()
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
            # 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)