Esempio n. 1
0
 def draw_map(self):
     """
     Create a map using mapGeneration and filling it to window_surface
     """
     map_data = dispUtils.mapGeneration(self.windowSurface,self.map_type)
     self.windowSurface.fill(map_data[1])
     dispUtils.drawObstacles(self.windowSurface, map_data[2], map_data[0])
startTime = datetime.now()

# set up pygame
pygame.init()
mainClock = pygame.time.Clock()

# set up the window
WINDOWWIDTH = 1200
WINDOWHEIGHT = 1200
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('2D Training')

#Generate Map
map_data = dispUtils.mapGeneration(windowSurface,map_type)
windowSurface.fill(map_data[1])
dispUtils.drawObstacles(windowSurface, map_data[2], map_data[0])

# movement Parameters
forawardSpeed = {'linearSpeed': 50/updatesPerSecond, 'angularSpeed': 0/updatesPerSecond}
leftSpeed = {'linearSpeed': 0/updatesPerSecond, 'angularSpeed': -0.6/updatesPerSecond}
rightSpeed = {'linearSpeed': 0/updatesPerSecond, 'angularSpeed': 0.6/updatesPerSecond}
stopSpeed = {'linearSpeed': 0, 'angularSpeed': 0}

# spawn walls and other obstacles
BOXSIZE = WINDOWWIDTH - 100
WALLWIDTH = 50
obstacles = dispUtils.createWalls(windowSurface,BOXSIZE,WALLWIDTH)
dispUtils.drawObstacles(windowSurface, [0,0,0], obstacles)

# box
boxX = int(random.uniform(200, 800))
Esempio n. 3
0
    dispUtils.noCollideSpawn(goals[-1], blacklist, 200)

done = False

# run the game loop

while (True):
    sim.doStep()

    #Fill Screen with white background
    windowSurface.fill([255, 255, 255])

    # check for the QUIT event
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    dispUtils.drawAgent(windowSurface, [255, 0, 0], robots[i])

    # Draw all the goals and obstacles
    for goal in goals:
        dispUtils.drawGoal(windowSurface, goal)
    dispUtils.drawObstacles(windowSurface, [0, 0, 0], obstacles)

    for i in range(numberOfAgents):
        dispUtils.drawAgent(windowSurface, [255, 0, 0], robots[i])

    if done == False:
        dispUtils.updateAgent(robots[i])