diff options
| author | Omar Magdy <99906646+omagdy7@users.noreply.github.com> | 2023-05-08 23:25:14 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-08 23:25:14 +0300 |
| commit | 439ae67f933ee85bd425566cabac64815db4096e (patch) | |
| tree | 19077318fda033952677f84a7107ecb079db3c43 /src/pinky.py | |
| parent | d610718c10e310c75126593624ecaaaa2233b371 (diff) | |
| parent | 0164fb61ccc79e677c711b158359060a7d3a2873 (diff) | |
| download | Macpan-439ae67f933ee85bd425566cabac64815db4096e.tar.xz Macpan-439ae67f933ee85bd425566cabac64815db4096e.zip | |
Merge pull request #5 from omagdy7/Refactoring
Refactoring
Diffstat (limited to 'src/pinky.py')
| -rw-r--r-- | src/pinky.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/pinky.py b/src/pinky.py index 29949a7..bb50c5b 100644 --- a/src/pinky.py +++ b/src/pinky.py @@ -43,7 +43,11 @@ class Pinky(Ghost): return (27 * 30 + 15, 30 * 30 + 15) @override - def get_next_move(self, pacman, maze, screen, blinky): + def get_intial_tile(self): + return (11 * 30 + 15, 12 * 30 + 15) + + @override + def get_next_move(self, game_state, screen): default_tile = self.get_default_tile() dx = [1, 0, -1, 0] @@ -64,25 +68,20 @@ class Pinky(Ghost): rand_pos = (0, 0) - new_target = self.get_four_tiles_ahead_of_pacman(pacman) - if settings.debug: - pygame.draw.circle(screen, self.color, - (new_target[0], new_target[1]), 15) - pygame.draw.circle(screen, self.color, - default_tile, 15) + new_target = self.get_four_tiles_ahead_of_pacman(game_state.pacman) - if pacman.powerup: + if game_state.pacman.powerup and self.mode != MODE.EATEN: self.mode = MODE.FRIGHETENED rand_pos = random.randint(0, 900), random.randint(0, 990) - if pacman.powerup is False and self.mode == MODE.FRIGHETENED: + if game_state.pacman.powerup is False and self.mode == MODE.FRIGHETENED: self.mode = MODE.CHASING for i in range(len(dx)): if i != forbidden: nx = self.x + dx[i] * self.speed ny = self.y + dy[i] * self.speed - if self.check_collision(nx, ny, 30, 30, maze): + if self.check_collision(nx, ny, 30, 30, game_state.map.maze): if self.mode == MODE.SCATTERED: ret[i] = self.heuristic( (nx, ny), default_tile[0], default_tile[1]) @@ -92,6 +91,10 @@ class Pinky(Ghost): elif self.mode == MODE.CHASING: ret[i] = self.heuristic( (nx, ny), new_target[0], new_target[1]) + elif self.mode == MODE.EATEN: + pos = self.get_intial_tile() + self.x = pos[0] + self.y = pos[1] if settings.debug: pygame.draw.line(screen, self.color, (new_target), (self.x, self.y), 1) |
