trójkąt na strzałce

This commit is contained in:
s464859 2022-04-28 17:42:50 +02:00
parent 1913b12bcf
commit c1c76f96cb
3 changed files with 43 additions and 7 deletions

View File

@ -19,7 +19,7 @@ class BFS:
if current_position[2] == 180: # jesli patrzy na polnoc
if neighbours_list[0][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
if neighbours_list[0][1] == 'grass':
cost = 10
cost = 3
elif neighbours_list[0][1] == 'sand':
cost = 2
elif neighbours_list[0][1] == 'mine':
@ -48,7 +48,7 @@ class BFS:
if current_position[2] == 90: # jesli patrzy na wschod
if neighbours_list[1][2] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
if neighbours_list[1][2] == 'grass':
cost = 10
cost = 3
elif neighbours_list[1][2] == 'sand':
cost = 2
elif neighbours_list[1][2] == 'mine':
@ -77,7 +77,7 @@ class BFS:
if current_position[2] == 0: # jesli patczy na poludzie
if neighbours_list[2][1] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
if neighbours_list[2][1] == 'grass':
cost = 10
cost = 3
elif neighbours_list[2][1] == 'sand':
cost = 2
elif neighbours_list[2][1] == 'mine':
@ -106,7 +106,7 @@ class BFS:
if current_position[2] == 270: # jesli patczy na wschod
if neighbours_list[1][0] not in ['wall', 'cliff_south', 'cliff_east', 'cliff_north', 'cliff_west']:
if neighbours_list[1][0] == 'grass':
cost = 10
cost = 3
elif neighbours_list[1][0] == 'sand':
cost = 2
elif neighbours_list[1][0] == 'mine':
@ -229,7 +229,7 @@ class BFS:
tmp[0] = p
tmp[1] = x
fringe[index_of_node_in_fringe] = tuple(tmp)
#self.window.draw_search([self.agent.position_x, self.agent.position_y], [node_[1][0], node_[1][1]],self.agent.current_map.tile_size, self.agent.current_map, self.agent)
self.window.draw_search([self.agent.position_x, self.agent.position_y], [node_[1][0], node_[1][1]],self.agent.current_map.tile_size, self.agent.current_map, self.agent)

View File

@ -113,7 +113,7 @@ class Map:
if ok and rng==0 and not (i<2 and j<3):
matrix[i].append(10) #kamień
elif ok and rng>4 and not (i<2 and j<3):
elif ok and rng>6 and not (i<2 and j<3):
matrix[i].append(5) #trawa
elif ok and rng<2 and not (i<2 and j<3):
matrix[i].append(0) #piasek

View File

@ -55,6 +55,42 @@ class Window:
pos1 = [pos1[0]*tile_size+(tile_size/2), pos1[1]*tile_size+(tile_size/2)]
pos2 = [pos2[0]*tile_size+(tile_size/2), pos2[1]*tile_size+(tile_size/2)]
pygame.draw.line(self.search, pygame.Color(255,0,0), pos1, pos2, 5)
pygame.draw.circle(self.search, pygame.Color(255,0,0), pos2, 10)
n = 10
p1=0
p2=0
p3=0
if (pos2[0] - pos1[0])!=0:
a1 = (pos2[1] - pos1[1])/(pos2[0] - pos1[0])
b1 = (pos1[1] - a1*pos1[0])
if a1!=0:
a2 = -(1/a1)
b2 = pos2[1] - a2*pos2[0]
y = a2*(pos2[0]+n)+b2
p1 = (pos2[0]+n, y)
y = a2*(pos2[0]-n)+b2
p2 = (pos2[0]-n, y)
if pos1[0]>pos2[0]:
y = a1*(pos2[0]-n)+b1
p3 = (pos2[0]-n, y)
else:
y = a1*(pos2[0]+n)+b1
p3 = (pos2[0]+n, y)
else:
p1 = (pos2[0], pos2[1]+n)
p2 = (pos2[0], pos2[1]-n)
if pos1[0]>pos2[0]:
p3 = (pos2[0]-n, pos2[1])
else:
p3 = (pos2[0]+n, pos2[1])
else:
p1 = (pos2[0]-n, pos2[1])
p2 = (pos2[0]+n, pos2[1])
if pos1[1]>pos2[1]:
p3 = (pos2[0], pos2[1]-n)
else:
p3 = (pos2[0], pos2[1]+n)
pygame.draw.polygon(self.search, pygame.Color(255,0,0), (p1,p2,p3))
self.window.blit(self.search, (0,0))
pygame.display.update()