From 657173388219c823edf1031b9c205a0a98f2cfea Mon Sep 17 00:00:00 2001 From: trzmielewskiR Date: Thu, 7 Apr 2022 19:40:39 +0200 Subject: [PATCH] bfs first try, self movement added --- .idea/.gitignore | 3 ++ .idea/WALL-E.iml | 8 +++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ SearchBfs.py | 27 ++++++++++++++ agent.py | 35 +++++++++++++------ mapa.py | 10 +++--- 9 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/WALL-E.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 SearchBfs.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/WALL-E.iml b/.idea/WALL-E.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/WALL-E.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..33d9c1a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SearchBfs.py b/SearchBfs.py new file mode 100644 index 0000000..dacecea --- /dev/null +++ b/SearchBfs.py @@ -0,0 +1,27 @@ +class BreadthSearchAlgorithm: + def __init__(self, graph, start, target): + self.graph = graph + self.start = start + self.target = target + + def bfs(self): + queue = [[self.start]] + visited = [] + + if self.start == self.target: + return + + while queue: + path = queue.pop(0) + node = path[-1] + if node not in visited: + neighbours = self.graph + for neighbour in neighbours: + next_path = list(path) + next_path.append(neighbour) + queue.append(next_path) + if neighbour == self.target: + return next_path + visited.append(node) + + return diff --git a/agent.py b/agent.py index 4adc04f..1aa106f 100644 --- a/agent.py +++ b/agent.py @@ -1,30 +1,43 @@ import pygame.image + class trashmaster(pygame.sprite.Sprite): - - def __init__(self,x,y,img): + + def __init__(self, x, y, img): super().__init__() - - self.width=x - self.height=y + + self.width = x + self.height = y self.x = 0 self.y = 0 - + self.image = pygame.image.load(img) - self.image = pygame.transform.scale(self.image, (self.width,self.height)) + self.image = pygame.transform.scale(self.image, (self.width, self.height)) self.rect = self.image.get_rect() def movement(self, key, vel): if key == pygame.K_LEFT: self.x -= vel - + if key == pygame.K_RIGHT: self.x += vel - + if key == pygame.K_UP: self.y -= vel - + if key == pygame.K_DOWN: self.y += vel - return (self.x, self.y) \ No newline at end of file + return (self.x, self.y) + + def move_up(self): + self.y -= 64 + + def move_down(self): + self.y += 64 + + def move_right(self): + self.x += 64 + + def move_left(self): + self.x -= 64 diff --git a/mapa.py b/mapa.py index ef58fb7..07581b1 100644 --- a/mapa.py +++ b/mapa.py @@ -2,7 +2,6 @@ import pygame as pg import pytmx - # config # TILE_SIZE = 16 @@ -16,15 +15,14 @@ import pytmx # return surface class TiledMap: - #loading file + # loading file def __init__(self, filename): tm = pytmx.load_pygame(filename, pixelalpha=True) self.width = tm.width * tm.tilewidth self.height = tm.height * tm.tileheight self.tmxdata = tm - - #rendering map + # rendering map def render(self, surface): ti = self.tmxdata.get_tile_image_by_gid for layer in self.tmxdata.visible_layers: @@ -33,8 +31,8 @@ class TiledMap: tile = ti(gid) if tile: surface.blit(tile, (x * self.tmxdata.tilewidth, y * self.tmxdata.tilewidth)) - + def make_map(self): temp_surface = pg.Surface((self.width, self.height)) self.render(temp_surface) - return temp_surface \ No newline at end of file + return temp_surface