diff options
| author | Omar Magdy <99906646+omagdy7@users.noreply.github.com> | 2023-03-22 01:14:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-22 01:14:19 +0200 |
| commit | 4076674216ea9e3989adbf8d87df5a474ee81701 (patch) | |
| tree | 9b4c41fb94dd1411aae40ffcf71c664909f9f1e5 /src/Game.py | |
| parent | 87aa85cdbe3bb90705ba5919206f84d7d6bf9a3d (diff) | |
| parent | 86b685ec600ed0bffc5dd8ec94850e89a3e7137b (diff) | |
| download | Macpan-4076674216ea9e3989adbf8d87df5a474ee81701.tar.xz Macpan-4076674216ea9e3989adbf8d87df5a474ee81701.zip | |
Merge pull request #1 from omagdy7/Map
Map
Diffstat (limited to 'src/Game.py')
| -rw-r--r-- | src/Game.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Game.py b/src/Game.py index aedfa0c..9d93786 100644 --- a/src/Game.py +++ b/src/Game.py @@ -1,6 +1,7 @@ import Player from Direction import DIRECTION import settings as Settings +import map as Map import pygame class Game(): @@ -28,16 +29,27 @@ class Game(): clock = pygame.time.Clock() - # Sprite sheet for pacman - sprite_sheet = pygame.image.load('../assets/pacman_left_sprite.png').convert_alpha(); - sprite_width, sprite_height = 32, 32 + map = Map.Map() + + grid_x = Settings.settings.width // len(map.maze[0]) + grid_y = (Settings.settings.height - 50) // len(map.maze) + # Checks collision with walls def check_collision(dx, dy): - return player.y + sprite_height + dy > Settings.settings.height or player.y + dy < 0 or player.x + sprite_width + dx > Settings.settings.width or player.x + dx < 0 + print(grid_x, grid_y) + x = int((player.x + dx) / grid_x) + y = int((player.y + dy) / grid_y) + print(x, y) + print(map.maze[x][y]) + is_dot = map.maze[x][y] == Map.D + is_big_dot = map.maze[x][y] == Map.BD + is_free = map.maze[x][y] == 0 + return not (is_dot or is_free or is_big_dot) + # Main game loop running = True @@ -77,7 +89,6 @@ class Game(): dy = 0 # Necssarry to move only horizontal or vertical - # print(player.direction) # Update the circle's position and checking for collisions if not check_collision(dx, dy): player.x += dx @@ -85,6 +96,7 @@ class Game(): screen.fill((0, 0, 0)) # Clear the screen + map.draw_map(screen) player.draw(screen, counter) # Update the screen |
