Example #1
0
    #barrierX = 780
    #barrierY = 600

    if not barrierExists(barrierList, barrierX, barrierY):
        barrier = Barrier(screen, barrierX, barrierY, 10, 10)
        #barrier = Barrier(screen, barrierX, barrierY, 10, 40)
        #barrier = pygame.draw.rect(screen, (255, 255, 255), (780, 600, 40, 10),0)
        barrierList.append(barrier)

    for b in barrierList:
        b.draw()

        direction = robot.getDirection(barrier)
        if direction != None:
            distance = robot.getDistance(barrier, direction)
            if distance < 100:
                if direction == 'up':
                    robot.displayWarningUp(distance)
                if direction == 'down':
                    robot.displayWarningDown(distance)
                if direction == 'right':
                    robot.displayWarningRight(distance)
                if direction == 'left':
                    robot.displayWarningLeft(distance)
        #if d < 100:
        #robot.getDirection(barrier, d)
        #if isCollision(robot.x, robot.y, barrier.x, barrier.y):
        #    displayWarningUp(robot.x, robot.y)

    pygame.display.update()
Example #2
0
                if event.key == pygame.K_LEFT:
                    angle_change = 0
                if event.key == pygame.K_RIGHT:
                    angle_change = 0

        screen.fill(white)
        sim_surface.fill(black)

        impossible_moves = []

        for b in barrierList:
            b.draw()
            direction = robot.getDirection(b)
            if direction:
                #print(robot.getDistance(b, direction), direction)
                if abs(robot.getDistance(b, direction)) < foot + 1:
                    if direction not in impossible_moves:
                        impossible_moves.append(direction)

        #robot_angle += angle_change
        #scanner_angle += angle_change

        # Convert angle output to radians

        if simulation == 'active':

            angle = robot.angle / 180 * math.pi
            x_change = drive_speed * math.sin(angle)
            y_change = drive_speed * math.cos(angle)

            robot.y += y_change