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/player.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/player.py')
| -rw-r--r-- | src/player.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/player.py b/src/player.py index 97d2ea5..92c4a84 100644 --- a/src/player.py +++ b/src/player.py @@ -17,22 +17,26 @@ class Player(): self.timer = None # checks if the current position of pacman is either a dot, big dot or free - def is_valid(self, maze, x, y): + def is_valid(self, game_state, x, y): if x >= 0 and x < 30: - is_dot = maze.maze[y][x] == Map.D - is_big_dot = maze.maze[y][x] == Map.BD - is_free = maze.maze[y][x] == 0 + is_dot = game_state.map.maze[y][x] == Map.D + is_big_dot = game_state.map.maze[y][x] == Map.BD + is_free = game_state.map.maze[y][x] == 0 if is_dot or is_big_dot: - maze.maze[y][x] = 0 + game_state.map.maze[y][x] = 0 + game_state.food += 1 + if is_dot: + game_state.score += 10 if is_big_dot: self.powerup = True self.timer = Timer(5 * 1000) + game_state.score += 50 return (is_dot or is_free or is_big_dot) return True # checks collision with pacman and obstacles returns false # if there is a collision and true otherwise - def check_collision(self, maze, dx, dy, tile_width, tile_height): + def check_collision(self, game_state, dx, dy, tile_width, tile_height): direct_x = [1, 0, -1, 0, 1, 1, -1, -1] direct_y = [0, 1, 0, -1, -1, 1, -1, 1] @@ -43,7 +47,7 @@ class Player(): ny = (self.y + ddy) + direct_y[i] * 14 x = nx // tile_width y = ny // tile_height - if not self.is_valid(maze, x, y): + if not self.is_valid(game_state, x, y): return False return True |
