diff --git a/.gitignore b/.gitignore index 82195aa..c25c502 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ venv -.idea \ No newline at end of file +.idea +__pycache__/ diff --git a/src/__pycache__/config.cpython-38.pyc b/src/__pycache__/config.cpython-38.pyc index 8ff18ce..1b5b8d8 100644 Binary files a/src/__pycache__/config.cpython-38.pyc and b/src/__pycache__/config.cpython-38.pyc differ diff --git a/src/config.py b/src/config.py index e445471..aaf5fb0 100644 --- a/src/config.py +++ b/src/config.py @@ -21,4 +21,6 @@ R_RIGHT = "R_RIGHT" R_LEFT = "R_LEFT" R_UP = "R_UP" R_DOWN = "R_DOWN" +MOVE="MOVE" +NOTHING="NOTHING" diff --git a/src/entitie/Truck.py b/src/entitie/Truck.py index aa8e3be..3137b67 100644 --- a/src/entitie/Truck.py +++ b/src/entitie/Truck.py @@ -11,7 +11,7 @@ class Truck: def __init__(self, x=0, y=0): self.abstractX = x self.abstractY = y - self.direction = R_RIGHT + self.direction = 90 asset_path = os.path.join(os.path.dirname(__file__), '..', '..', 'assets', 'garbage-truck.png') self.backAsset = pygame.transform.scale(pygame.image.load(asset_path), (DEFAULT_ASSET_SIZE, DEFAULT_ASSET_SIZE)) self.asset = pygame.transform.scale(pygame.image.load(asset_path), (DEFAULT_ASSET_SIZE, DEFAULT_ASSET_SIZE)) @@ -20,33 +20,22 @@ class Truck: self.velocity = DEFAULT_ASSET_SIZE def rotate_up(self): - self.asset = self.backAsset self.asset = pygame.transform.rotate(self.asset, 90) - self.direction = R_UP + self.direction = (self.direction + 90) % 360 def rotate_down(self): - self.asset = self.backAsset self.asset = pygame.transform.rotate(self.asset, -90) - self.direction = R_DOWN - - def rotate_right(self): - self.asset = self.backAsset - self.direction = R_RIGHT - - def rotate_left(self): - self.asset = self.backAsset - self.asset = pygame.transform.rotate(self.asset, 180) - self.asset = pygame.transform.flip(self.asset, False, True) - self.direction = R_LEFT + self.direction = (self.direction - 90) % 360 def move(self, map): - if self.direction == R_UP: + print(self.direction) + if self.direction == 180: self.move_up(map) - if self.direction == R_DOWN: + if self.direction == 0: self.move_down(map) - if self.direction == R_RIGHT: + if self.direction == 90: self.move_right(map) - if self.direction == R_LEFT: + if self.direction == 270: self.move_left(map) def replace(self, map, oldX, oldY): diff --git a/src/entitie/__pycache__/Truck.cpython-38.pyc b/src/entitie/__pycache__/Truck.cpython-38.pyc index 2f213cb..7a20e18 100644 Binary files a/src/entitie/__pycache__/Truck.cpython-38.pyc and b/src/entitie/__pycache__/Truck.cpython-38.pyc differ diff --git a/src/main.py b/src/main.py index e585be1..e8a0a4e 100644 --- a/src/main.py +++ b/src/main.py @@ -44,6 +44,7 @@ class EnvMap: no = None if o.__class__.__name__ == 'Truck': no = Truck(x, y) + no.direction = o.direction newEnvMap.truck = no if o.__class__.__name__ == 'Trash': @@ -125,18 +126,11 @@ class PathFinder(): altState3 = state.get_map_copy() t3 = altState3.map[truck.abstractX][truck.abstractY] - t3.rotate_right() t3.move(altState3.map) - altState4 = state.get_map_copy() - t4 = altState4.map[truck.abstractX][truck.abstractY] - t4.rotate_left() - t4.move(altState4.map) - pack.append([R_UP, altState1]) pack.append([R_DOWN, altState2]) - pack.append([R_RIGHT, altState3]) - pack.append([R_LEFT, altState4]) + pack.append([NOTHING, altState3]) return pack @@ -145,6 +139,9 @@ class PathFinder(): for y in range(DEFAULT_MAP_SIZE): a = s1.map[x][y] b = s2.map[x][y] + if a.__class__.__name__ == 'Truck' and b.__class__.__name__ == 'Truck': + if a.direction != b.direction: + return False if a.__class__.__name__ != b.__class__.__name__: return False return True @@ -202,10 +199,6 @@ class Environment: self.envMap.truck.rotate_up() if key == pygame.K_s: self.envMap.truck.rotate_down() - if key == pygame.K_d: - self.envMap.truck.rotate_right() - if key == pygame.K_a: - self.envMap.truck.rotate_left() if key == pygame.K_o: actions = self.pathFinder.graphsearch(self.envMap.get_map_copy()) self.navigate(actions) @@ -217,18 +210,14 @@ class Environment: action = actions.pop() next = pygame.time.get_ticks() + 300 self.update() + ev=None if action == R_UP: ev = pygame.event.Event(pygame.KEYDOWN, {"key": pygame.K_w}) if action == R_DOWN: ev = pygame.event.Event(pygame.KEYDOWN, {"key": pygame.K_s}) - if action == R_RIGHT: - ev = pygame.event.Event(pygame.KEYDOWN, {"key": pygame.K_d}) - - if action == R_LEFT: - ev = pygame.event.Event(pygame.KEYDOWN, {"key": pygame.K_a}) - - pygame.event.post(ev) + if ev: + pygame.event.post(ev) ev = pygame.event.Event(pygame.KEYDOWN, {"key": pygame.K_SPACE}) pygame.event.post(ev)