Skip to content

Commit 76649bc

Browse files
committedJul 14, 2020
correct obstacle display location
1 parent 5d490c3 commit 76649bc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
 

‎Obstacle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Obstacle(object):
44

55
def __init__(self,pos):
66
self.pos = pos
7-
self.radius = 20
7+
self.width = 20
88

99
def distance_from(self,other_agent):
1010
return sqrt((other_agent.pos[0] - self.pos[0])**2 + (other_agent.pos[1] - self.pos[1]) **2)

‎main.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#pygame variables
1212
TITLE = "FLOCKING"
1313
BACKGROUND = (0,0,0)
14-
AGENT_COLOR = [(116,175,173),(222,27,26)]
14+
AGENT_COLOR = [(116,175,173),(222,27,26)] # [agent 1, agent 2]
1515
OBSTACLE_COLOR = (250,250,250)
1616
TEXT_COLOR = (255,255,255)
17-
TRI_BASE = [12,10,]
18-
TRI_HEIGHT = [18,15]
17+
TRI_BASE = [12,10] # [agent 1, agent 2]
18+
TRI_HEIGHT = [18,15] # [agent 1, agent 2]
1919
MAX_AGENT_COUNT = 60
2020

2121
#Initialize Display
@@ -25,7 +25,6 @@
2525
screen = pyg.display.set_mode((shared.WIDTH, shared.HEIGHT))
2626
pyg.display.set_caption(TITLE)
2727

28-
2928
def make_agent_inbound():
3029
for agent in shared.agent_array:
3130
agent.pos = agent.pos[0] % shared.WIDTH, agent.pos[1] % shared.HEIGHT
@@ -65,7 +64,8 @@ def draw_agent():
6564

6665
def draw_obstacle():
6766
for obs in shared.obstacle_array:
68-
pyg.draw.rect(screen, OBSTACLE_COLOR, (obs.pos[0], obs.pos[1], obs.radius, obs.radius), 0)
67+
width = obs.width
68+
pyg.draw.rect(screen, OBSTACLE_COLOR, (obs.pos[0] - width/2, obs.pos[1] - width/2, width, width), 0)
6969

7070
def run():
7171
#game loop

0 commit comments

Comments
 (0)
Please sign in to comment.