bfs first try, self movement added
This commit is contained in:
parent
10cca50e63
commit
6571733882
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
8
.idea/WALL-E.iml
Normal file
8
.idea/WALL-E.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/WALL-E.iml" filepath="$PROJECT_DIR$/.idea/WALL-E.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
27
SearchBfs.py
Normal file
27
SearchBfs.py
Normal file
@ -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
|
35
agent.py
35
agent.py
@ -1,30 +1,43 @@
|
|||||||
import pygame.image
|
import pygame.image
|
||||||
|
|
||||||
|
|
||||||
class trashmaster(pygame.sprite.Sprite):
|
class trashmaster(pygame.sprite.Sprite):
|
||||||
|
|
||||||
def __init__(self,x,y,img):
|
def __init__(self, x, y, img):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.width=x
|
self.width = x
|
||||||
self.height=y
|
self.height = y
|
||||||
|
|
||||||
self.x = 0
|
self.x = 0
|
||||||
self.y = 0
|
self.y = 0
|
||||||
|
|
||||||
self.image = pygame.image.load(img)
|
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()
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
def movement(self, key, vel):
|
def movement(self, key, vel):
|
||||||
if key == pygame.K_LEFT:
|
if key == pygame.K_LEFT:
|
||||||
self.x -= vel
|
self.x -= vel
|
||||||
|
|
||||||
if key == pygame.K_RIGHT:
|
if key == pygame.K_RIGHT:
|
||||||
self.x += vel
|
self.x += vel
|
||||||
|
|
||||||
if key == pygame.K_UP:
|
if key == pygame.K_UP:
|
||||||
self.y -= vel
|
self.y -= vel
|
||||||
|
|
||||||
if key == pygame.K_DOWN:
|
if key == pygame.K_DOWN:
|
||||||
self.y += vel
|
self.y += vel
|
||||||
return (self.x, self.y)
|
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
|
||||||
|
10
mapa.py
10
mapa.py
@ -2,7 +2,6 @@ import pygame as pg
|
|||||||
import pytmx
|
import pytmx
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# config
|
# config
|
||||||
# TILE_SIZE = 16
|
# TILE_SIZE = 16
|
||||||
|
|
||||||
@ -16,15 +15,14 @@ import pytmx
|
|||||||
# return surface
|
# return surface
|
||||||
|
|
||||||
class TiledMap:
|
class TiledMap:
|
||||||
#loading file
|
# loading file
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
tm = pytmx.load_pygame(filename, pixelalpha=True)
|
tm = pytmx.load_pygame(filename, pixelalpha=True)
|
||||||
self.width = tm.width * tm.tilewidth
|
self.width = tm.width * tm.tilewidth
|
||||||
self.height = tm.height * tm.tileheight
|
self.height = tm.height * tm.tileheight
|
||||||
self.tmxdata = tm
|
self.tmxdata = tm
|
||||||
|
|
||||||
|
# rendering map
|
||||||
#rendering map
|
|
||||||
def render(self, surface):
|
def render(self, surface):
|
||||||
ti = self.tmxdata.get_tile_image_by_gid
|
ti = self.tmxdata.get_tile_image_by_gid
|
||||||
for layer in self.tmxdata.visible_layers:
|
for layer in self.tmxdata.visible_layers:
|
||||||
@ -33,8 +31,8 @@ class TiledMap:
|
|||||||
tile = ti(gid)
|
tile = ti(gid)
|
||||||
if tile:
|
if tile:
|
||||||
surface.blit(tile, (x * self.tmxdata.tilewidth, y * self.tmxdata.tilewidth))
|
surface.blit(tile, (x * self.tmxdata.tilewidth, y * self.tmxdata.tilewidth))
|
||||||
|
|
||||||
def make_map(self):
|
def make_map(self):
|
||||||
temp_surface = pg.Surface((self.width, self.height))
|
temp_surface = pg.Surface((self.width, self.height))
|
||||||
self.render(temp_surface)
|
self.render(temp_surface)
|
||||||
return temp_surface
|
return temp_surface
|
||||||
|
Loading…
Reference in New Issue
Block a user