added more goals
This commit is contained in:
parent
7df7885cbf
commit
28f590a164
16
main.py
16
main.py
@ -19,7 +19,17 @@ def main():
|
||||
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
|
||||
pygame.display.set_caption('TRAKTOHOLIK')
|
||||
|
||||
path = BFSSearcher().search((8, 1), (6, 2), Constants.UP)
|
||||
paths = []
|
||||
goals = [(6,2), (3,3), (4,0), (0,5), (1,1), (3,6)]
|
||||
startCords = tuple(8, 1)
|
||||
endCords = goals.pop(0)
|
||||
startDir = Constants.UP
|
||||
for goal in goals:
|
||||
path = BFSSearcher().search(startCords, endCords, startDir)
|
||||
paths.append(path)
|
||||
startCords = endCords
|
||||
endCords = goals.pop(0)
|
||||
startDir = tractor.curr_direction
|
||||
|
||||
run = True
|
||||
while run:
|
||||
@ -32,8 +42,10 @@ def main():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
tractor.update(path)
|
||||
action = paths[0].pop(0)
|
||||
tractor.update(action)
|
||||
tractor.check_collision(obstacles)
|
||||
pygame.time.wait(self.settings.freeze_time)
|
||||
pygame.display.update()
|
||||
pygame.quit()
|
||||
|
||||
|
@ -88,17 +88,15 @@ class Tractor(Sprite):
|
||||
self.rect.y += self.curr_direction[1] * self.settings.tile_size # jak wejdzie na kolizje to cofamy ruch
|
||||
# w przyszlosci mozna zmienic
|
||||
|
||||
def update(self, path):
|
||||
def update(self, action):
|
||||
|
||||
while(path):
|
||||
action = path.pop(0)
|
||||
if action == C.ROTATE_RIGHT and self.rect.x:
|
||||
self.turn_right()
|
||||
elif action == C.ROTATE_LEFT:
|
||||
self.turn_left()
|
||||
elif action == C.MOVE:
|
||||
self.move()
|
||||
# print(self.rect)
|
||||
if action == C.ROTATE_RIGHT and self.rect.x:
|
||||
self.turn_right()
|
||||
elif action == C.ROTATE_LEFT:
|
||||
self.turn_left()
|
||||
elif action == C.MOVE:
|
||||
self.move()
|
||||
# print(self.rect)
|
||||
|
||||
def draw(self, screen):
|
||||
screen.blit(self.image, self.rect)
|
||||
|
Loading…
Reference in New Issue
Block a user