aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Game.py22
-rw-r--r--src/Player.py7
-rw-r--r--src/map.py122
-rw-r--r--src/settings.py4
4 files changed, 144 insertions, 11 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
diff --git a/src/Player.py b/src/Player.py
index f8ebc06..e0128d9 100644
--- a/src/Player.py
+++ b/src/Player.py
@@ -28,15 +28,14 @@ def get_sprites(sprite_sheet) -> List:
class Player():
def __init__(self, sprite_sheet):
- self.x = Settings.settings.width // 2;
- self.y = Settings.settings.height // 2;
+ self.x = 450
+ self.y = 663
self.sprite = get_sprites(sprite_sheet)
- self.speed = 5
+ self.speed = 10
self.direction = DIRECTION.LEFT
def draw(self, screen, counter):
pos = (self.x, self.y)
- print(self.direction, DIRECTION.UP)
if self.direction == DIRECTION.UP:
screen.blit(pygame.transform.rotate(self.sprite[counter // 5], 270), pos)
elif self.direction == DIRECTION.DOWN:
diff --git a/src/map.py b/src/map.py
index e69de29..e05fc2f 100644
--- a/src/map.py
+++ b/src/map.py
@@ -0,0 +1,122 @@
+import pygame
+import math
+import settings as Settings
+
+
+
+H = 1
+V = 2
+D = 4
+BD = 8
+TR = 16
+TL = 32
+BL = 64
+BR = 128
+G = 256
+
+PI = math.pi
+
+
+class Map():
+ def __init__(self):
+ self.maze = [
+ [TL, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, TR],
+ [V, TL, H, H, H, H, H, H, H, H, H, H, H, H, TR, TL, H, H, H, H, H, H, H, H, H, H, H, H, TR, V],
+ [V, V, D, D, D, D, D, D, D, D, D, D, D, D, V, V, D, D, D, D, D, D, D, D, D, D, D, D, V, V],
+ [V, V, D, TL, H, H, TR, D, TL, H, H, H, TR, D, V, V, D, TL, H, H, H, TR, D, TL, H, H, TR, D, V, V],
+ [V, V, BD, V, 0, 0, V, D, V, 0, 0, 0, V, D, V, V, D, V, 0, 0, 0, V, D, V, 0, 0, V, BD, V, V],
+ [V, V, D, BL, H, H, BR, D, BL, H, H, H, BR, D, BL, BR, D, BL, H, H, H, BR, D, BL, H, H, BR, D, V, V],
+ [V, V, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, V, V],
+ [V, V, D, TL, H, H, TR, D, TL, TR, D, TL, H, H, H, H, H, H, TR, D, TL, TR, D, TL, H, H, TR, D, V, V],
+ [V, V, D, BL, H, H, BR, D, V, V, D, BL, H, H, TR, TL, H, H, BR, D, V, V, D, BL, H, H, BR, D, V, V],
+ [V, V, D, D, D, D, D, D, V, V, D, D, D, D, V, V, D, D, D, D, V, V, D, D, D, D, D, D, V, V],
+ [V, BL, H, H, H, H, TR, D, V, BL, H, H, TR, 0, V, V, 0, TL, H, H, BR, V, D, TL, H, H, H, H, BR, V],
+ [V, 0, 0, 0, 0, 0, V, D, V, TL, H, H, BR, 0, BL, BR, 0, BL, H, H, TR, V, D, V, 0, 0, 0, 0, 0, V],
+ [V, 0, 0, 0, 0, 0, V, D, V, V, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V, V, D, V, 0, 0, 0, 0, 0, V],
+ [BR, 0, 0, 0, 0, 0, V, D, V, V, 0, TL, H, H, G, G, H, H, TR, 0, V, V, D, V, 0, 0, 0, 0, 0, BL],
+ [H, H, H, H, H, H, BR, D, BL, BR, 0, V, 0, 0, 0, 0, 0, 0, V, 0, BL, BR, D, BL, H, H, H, H, H, H],
+ [0, 0, 0, 0, 0, 0, 0, D, 0, 0, 0, V, 0, 0, 0, 0, 0, 0, V, 0, 0, 0, D, 0, 0, 0, 0, 0, 0, 0],
+ [H, H, H, H, H, H, TR, D, TL, TR, 0, V, 0, 0, 0, 0, 0, 0, V, 0, TL, TR, D, TL, H, H, H, H, H, H],
+ [TR, 0, 0, 0, 0, 0, V, D, V, V, 0, BL, H, H, H, H, H, H, BR, 0, V, V, D, V, 0, 0, 0, 0, 0, TL],
+ [V, 0, 0, 0, 0, 0, V, D, V, V, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V, V, D, V, 0, 0, 0, 0, 0, V],
+ [V, 0, 0, 0, 0, 0, V, D, V, V, 0, TL, H, H, H, H, H, H, TR, 0, V, V, D, V, 0, 0, 0, 0, 0, V],
+ [V, TL, H, H, H, H, BR, D, BL, BR, 0, BL, H, H, TR, TL, H, H, BR, 0, BL, BR, D, BL, H, H, H, H, TR, V],
+ [V, V, D, D, D, D, D, D, D, D, D, D, D, D, V, V, D, D, D, D, D, D, D, D, D, D, D, D, V, V],
+ [V, V, D, TL, H, H, TR, D, TL, H, H, H, TR, D, V, V, D, TL, H, H, H, TR, D, TL, H, H, TR, D, V, V],
+ [V, V, D, BL, H, TR, V, D, BL, H, H, H, BR, D, BL, BR, D, BL, H, H, H, BR, D, V, TL, H, BR, D, V, V],
+ [V, V, BD, D, D, V, V, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, V, V, D, D, BD, V, V],
+ [V, BL, H, TR, D, V, V, D, TL, TR, D, TL, H, H, H, H, H, H, TR, D, TL, TR, D, V, V, D, TL, H, BR, V],
+ [V, TL, H, BR, D, BL, BR, D, V, V, D, BL, H, H, TR, TL, H, H, BR, D, V, V, D, BL, BR, D, BL, H, TR, V],
+ [V, V, D, D, D, D, D, D, V, V, D, D, D, D, V, V, D, D, D, D, V, V, D, D, D, D, D, D, V, V],
+ [V, V, D, TL, H, H, H, H, BR, BL, H, H, TR, D, V, V, D, TL, H, H, BR, BL, H, H, H, H, TR, D, V, V],
+ [V, V, D, BL, H, H, H, H, H, H, H, H, BR, D, BL, BR, D, BL, H, H, H, H, H, H, H, H, BR, D, V, V],
+ [V, V, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, D, V, V],
+ [V, BL, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, BR, V],
+ [BL, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, BR]
+ ]
+ self.dot_color = (255, 255, 255) # white
+ self.small_dot_radius = 4
+ self.big_dot_radius = 8
+ self.line_color = (0, 0, 255) # Blue
+ self.line_vertical = Settings.settings.height // len(self.maze)
+ self.line_horizontal = Settings.settings.width // len(self.maze[0])
+ self.line_stroke = 3
+
+ def consturct_map(self):
+ pass
+
+
+ def draw_wall(self, screen, flag , pos):
+ if flag & V:
+ pos1 = (pos[0] + self.line_vertical * 0.5, pos[1])
+ pos2 = (pos1[0], pos1[1] + self.line_horizontal)
+ pygame.draw.line(screen, self.line_color, pos1, pos2, self.line_stroke)
+ if flag & H:
+ pos1 = (pos[0], pos[1] + self.line_vertical * 0.5)
+ pos2 = (pos1[0] + self.line_horizontal, pos1[1])
+ pygame.draw.line(screen, self.line_color, pos1, pos2, self.line_stroke)
+ if flag & D:
+ pos1 = (pos[0] + self.line_vertical * 0.5, pos[1] + self.line_horizontal * 0.5)
+ pygame.draw.circle(screen, self.dot_color, pos1, self.small_dot_radius)
+ if flag & BD:
+ pos1 = (pos[0] + self.line_vertical * 0.5, pos[1] + self.line_horizontal * 0.5)
+ pygame.draw.circle(screen, self.dot_color, pos1, self.big_dot_radius)
+ if flag & TR:
+ pos1 = (pos[0] - self.line_vertical * 0.5, pos[1] + self.line_horizontal * 0.5)
+ arc_rect = pygame.Rect(pos1[0], pos1[1], self.line_vertical, self.line_horizontal)
+ pygame.draw.arc(screen, self.line_color, arc_rect, 0, PI / 2, self.line_stroke)
+ if flag & TL:
+ pos1 = (pos[0] + self.line_vertical * 0.5, pos[1] + self.line_horizontal * 0.5)
+ arc_rect = pygame.Rect(pos1[0], pos1[1], self.line_vertical, self.line_horizontal)
+ pygame.draw.arc(screen, self.line_color, arc_rect, PI / 2, PI, self.line_stroke)
+ if flag & BL:
+ pos1 = (pos[0] + self.line_vertical * 0.5, pos[1] - self.line_horizontal * 0.5)
+ arc_rect = pygame.Rect(pos1[0], pos1[1], self.line_vertical, self.line_horizontal)
+ pygame.draw.arc(screen, self.line_color, arc_rect, PI, 3*PI / 2, self.line_stroke)
+ if flag & BR:
+ pos1 = (pos[0] - self.line_vertical * 0.5, pos[1] - self.line_horizontal * 0.5)
+ arc_rect = pygame.Rect(pos1[0], pos1[1], self.line_vertical, self.line_horizontal)
+ pygame.draw.arc(screen, self.line_color, arc_rect, 3*PI / 2, PI * 2, self.line_stroke)
+
+
+
+
+
+ def draw_map(self, screen):
+ rows = len(self.maze)
+ cols = len(self.maze[0])
+ for i in range(0, rows):
+ for j in range(cols):
+ pos = (j * self.line_horizontal, i * self.line_vertical)
+ self.draw_wall(screen, self.maze[i][j], pos)
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/settings.py b/src/settings.py
index ba62736..cdda2a4 100644
--- a/src/settings.py
+++ b/src/settings.py
@@ -1,7 +1,7 @@
class Settings():
def __init__(self):
- self.width = 640
- self.height = 480
+ self.width = 900
+ self.height = 950
self.fps = 60
settings = Settings()