-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.py
54 lines (45 loc) · 1.53 KB
/
environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pygame
class Environment():
"""
A class of the map where the robot will be moving around.
Attributes
----------
map_dimensions : tuple
The X and Y window dimensions.
"""
def __init__(self, map_dimensions):
# Colors
self.WHITE = (255, 255, 255)
self.BLACK = (0, 0, 0)
self.RED = (255, 0, 0)
self.GREEN = (0, 255, 0)
self.BLUE = (0, 0, 255)
self.BROWN = (189, 154, 122)
self.YELLOW = (255, 255, 0)
self.GRAY = (105, 105, 105)
# Map dimensions
self.WIDTH, self.HEIGHT = map_dimensions
# Window settings
self.FPS = 120
pygame.display.set_caption('Visibility Polygon')
self.map = pygame.display.set_mode(size=(self.WIDTH, self.HEIGHT))
self.map.fill(self.WHITE)
self.obstacles = []
self.vertices = [(0, 0), (200, 0), (200, 70), (70, 70), (70, 200),
(570, 200), (570, 70), (390, 70), (390, 100), (320, 100), (320, 0),
(640, 0), (640, 480), (320, 480), (320, 410), (570, 410), (570, 300),
(70, 300), (70, 410), (150, 410), (150, 380), (220, 380), (220, 480),
(0, 480), (0, 0)]
def get_position_color(self, position):
return self.map.get_at(position)[:3]
def make_map(self):
"""Makes the walls of the map."""
self.map.fill(self.WHITE)
pygame.draw.polygon(surface=self.map, color=self.GRAY, points=self.vertices)
self.draw_walls()
return self.vertices
def draw_walls(self):
"""Draws the contiguous set of lines."""
# Draw the obstacles on top of everything
for i in range(len(self.vertices)-1):
pygame.draw.line(self.map, self.BLACK, self.vertices[i], self.vertices[i+1], width=4)