Beispiel #1
0
    def __init__(self):
        self.obstacles = []
        o1 = Obstacle(0, 0, 1, key=0)
        o2 = Obstacle(0, 2, 1, key=1)
        #o3 = Obstacle(-2, 4, 1, key=2)
        #o4 = Obstacle(-2, -4, 1, key=3)
        self.obstacles.append(o1)
        self.obstacles.append(o2)
        #self.obstacles.append(o3)
        #self.obstacles.append(o4)

        targetPoint = sympy.Point(-8, 0)

        self.r1 = Robot(2, 3, targetPoint, 'r', ("127.0.0.1", 8080))
        self.r1.initialize_obstacles(self.obstacles)
        self.r2 = Robot(5, 0, targetPoint, 'b', ("127.0.0.1", 8081))
        self.r2.initialize_obstacles(self.obstacles)
        #self.r3 = Robot(7, -2, targetPoint, 'g', ("127.0.0.1", 8082))
        #self.r3.initialize_obstacles(self.obstacles)

        self.fig = plt.figure()
        self.ax = plt.axes(xlim=(-10, 10), ylim=(-10, 10))

        self.pointRobot_r1, = self.ax.plot([self.r1.x], [self.r1.y],
                                           'ro',
                                           lw=1)
        self.pointRobot_r2, = self.ax.plot([self.r2.x], [self.r2.y],
                                           'bo',
                                           lw=1)
        #self.pointRobot_r3, = self.ax.plot([self.r2.x], [self.r2.y], 'go', lw=1)

        self.r1.start_actions(plt, self.ax, self.pointRobot_r1)
        self.r2.start_actions(plt, self.ax, self.pointRobot_r2)
        #self.r3.start_actions(plt, self.ax, self.pointRobot_r3)
        #self.r3.start_actions(plt, self.circles_r3, self.pointRobot_r3)
        #MyThread(self.fig, self.r1, self.ax, self.obstacles, targetPoint).start()
        #MyThread(self.fig, self.r2, self.ax, self.obstacles, targetPoint).start()
        #self.r1.Thread_Animation(plt, self.r1, self.ax, self.obstacles, targetPoint).start()
        #self.r2.Thread_Animation(plt, self.r2, self.ax, self.obstacles, targetPoint).start()

        self.pointTarget, = self.ax.plot([targetPoint.x], [targetPoint.y],
                                         'ko',
                                         lw=1)

        #self.circles_r1 = self.draw_obstacles(self.r1)
        #self.circles_r2 = self.draw_obstacles(self.r2)

        self.draw_obstacles()
        #self.draw()
        plt.show()
Beispiel #2
0
 def initialize_obstacles(self, obstacles):
     for obstacle in obstacles:
         estimateRadius = self.estimate_radius(obstacle)
         self.obstacles.append(
             Obstacle(obstacle.x,
                      obstacle.y,
                      obstacle.radius,
                      estimateRadius,
                      key=obstacle.key))
Beispiel #3
0
 def copy_obstacle(self):
     obstaclesCopy = []
     for obstacle in self.obstacles:
         obstaclesCopy.append(
             Obstacle(obstacle.x,
                      obstacle.y,
                      obstacle.radius,
                      obstacle.estimateRadius,
                      key=obstacle.key))
     return obstaclesCopy
Beispiel #4
0
 def add_obstacles(self, obstacle_dict):
     for obstacle in obstacle_dict:
         o_id = obstacle['id']
         p1 = float(obstacle['p1'])
         p2 = float(obstacle['p2'])
         p3 = float(obstacle['p3'])
         p4 = float(obstacle['p4'])
         o_type = obstacle['type'].title()
         self.obstacles.append(
             Obstacle(screen=self.screen,
                      oid=o_id,
                      otype=o_type,
                      params=(p1, p2, p3, p4)))
Beispiel #5
0
    def generate_obstacle(self, sprite_path: str) -> arcade.Sprite:
        """
        Used to generate an obstacle on the lane.
        """

        obstacle = Obstacle(sprite_path)
        obstacle.center_x = self.SCREEN_WIDTH
        obstacle.center_y = (self.SCREEN_HEIGHT -
                             (self.SCREEN_HEIGHT // 3) * self.tier + 40)
        obstacle.scale = 0.8
        obstacle.change_x = -self.difficulty
        return obstacle
Beispiel #6
0
ens = [
    [WIDTH / 4, (LAND_HEIGHT + WATER_HEIGHT) - WATER_HEIGHT / 2],
    [WIDTH / 6, 2 * (LAND_HEIGHT + WATER_HEIGHT) - WATER_HEIGHT / 2],
    [5 * WIDTH / 7, 3 * (LAND_HEIGHT + WATER_HEIGHT) - WATER_HEIGHT / 2],
    [5 * WIDTH / 9, 4 * (LAND_HEIGHT + WATER_HEIGHT) - WATER_HEIGHT / 2],
    [9 * WIDTH / 11, 5 * (LAND_HEIGHT + WATER_HEIGHT) - WATER_HEIGHT / 2],
]

# sprite groups
all_sprites = pygame.sprite.Group()
obstacles = pygame.sprite.Group()
enemies = pygame.sprite.Group()

# create obstacles
for pos in obs:
    o = Obstacle(pos)
    all_sprites.add(o)
    obstacles.add(o)

# create enemies
for pos in ens:
    e = Enemy(pos, ENEMY_SPEED)
    all_sprites.add(e)
    enemies.add(e)


def play(play_id, level):
    "Function for actual gameplay"

    global cont
    start_time = pygame.time.get_ticks()
Beispiel #7
0
from util.Search import *
from entities.Obstacle import *
import sympy

if __name__ == '__main__':
    #intersect_line_circle(0, 0, 0, 0, 0, 1)
    startPoint = sympy.Point(2, 0)
    endPoint = sympy.Point(-2, 0)
    obstacle1 = Obstacle(0, 0, 1)
    obstacle2 = Obstacle(0, 2, 1)
    obstacles = []
    obstacles.append(obstacle1)
    obstacles.append(obstacle2)
    #build_graph(startPoint, endPoint, obstacles)

    a = Node('A', 0, 0)
    b = Node('B', 10, 10)
    c = Node('C', 30, 30)
    d = Node('D', 50, 50)
    e = Node('E', 100, 100)

    example_graph = SimpleGraph()
    '''
    example_graph.edges = {
        a: {b: 5},
        b: {a: 2, c: 3, d: 4},
        c: {a: 3},
        d: {e: 2, a: 5},
        e: {b: 5}
    }
    '''