fixed walking

This commit is contained in:
Dawid Pylak 2022-04-20 18:58:43 +02:00
parent 28f590a164
commit 516aefc754
3 changed files with 16 additions and 10 deletions

20
main.py
View File

@ -20,17 +20,18 @@ def main():
pygame.display.set_caption('TRAKTOHOLIK')
paths = []
goals = [(6,2), (3,3), (4,0), (0,5), (1,1), (3,6)]
startCords = tuple(8, 1)
goals = [(6, 2), (3,3), (4,1), (6, 2), (3, 8), (1, 7), (8, 1)]
startCords = (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)
endCords = goal
startDir = tractor.curr_direction
run = True
while run:
clock.tick(settings.fps)
@ -42,10 +43,15 @@ def main():
if event.type == pygame.QUIT:
run = False
action = paths[0].pop(0)
tractor.update(action)
tractor.check_collision(obstacles)
pygame.time.wait(self.settings.freeze_time)
if len(paths) !=0 :
if len(paths[0]) != 0:
action = paths[0].pop(0)
tractor.update(action)
# tractor.check_collision(obstacles)
else:
paths.pop(0)
print(paths)
pygame.time.wait(settings.freeze_time)
pygame.display.update()
pygame.quit()

View File

@ -4,7 +4,7 @@ class Settings:
def __init__(self):
# Game settings
self.fps = 60
self.freeze_time = 500
self.freeze_time = 250
# Screen settings
self.screen_width = 700

View File

@ -40,7 +40,7 @@ class Tractor(Sprite):
pygame.image.load('assets/images/tractor/tractor-transparent-up.png'),
(self.settings.tile_size, self.settings.tile_size))
pygame.time.wait(500) # bez tego sie kreci jak hot-wheels
pygame.time.wait(self.settings.freeze_time) # bez tego sie kreci jak hot-wheels
def turn_left(self):
if self.curr_direction == [0, 1]:
@ -79,7 +79,7 @@ class Tractor(Sprite):
if self.rect.y >= self.settings.screen_height - self.settings.tile_size:
self.rect.y = self.settings.screen_height - self.settings.tile_size
pygame.time.wait(500) # bez tego sie kreci jak hot-wheels
pygame.time.wait(self.settings.freeze_time) # bez tego sie kreci jak hot-wheels
def check_collision(self, obstacles):
if pygame.sprite.spritecollideany(self, obstacles):