aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoisis <moisis.george@yahoo.com>2023-05-19 23:41:23 +0300
committerGitHub <noreply@github.com>2023-05-19 23:41:23 +0300
commit271af3b2b85ac05aa8061cef0f35e7540f90b778 (patch)
treea0475e1d88be01716e76f2e75c495a4284290bb9
parent8eeb31dba61e8c9b29704c5988f95dcba4338fca (diff)
parent6a351ed2d6a554ed6d338abba234527705d1040f (diff)
downloadMacpan-271af3b2b85ac05aa8061cef0f35e7540f90b778.tar.xz
Macpan-271af3b2b85ac05aa8061cef0f35e7540f90b778.zip
Merge pull request #7 from omagdy7/FinalMISOHEADmaster
Final Touches
-rw-r--r--README.md2
-rw-r--r--assets/Options Rect.pngbin1569 -> 2962 bytes
-rw-r--r--assets/Play Rect.pngbin1023 -> 2403 bytes
-rw-r--r--assets/PressStart2P-Regular.ttfbin0 -> 116008 bytes
-rw-r--r--assets/Quit Rect.pngbin1003 -> 2364 bytes
-rw-r--r--assets/greenboxz.pngbin0 -> 1004 bytes
-rw-r--r--src/GUI.py126
-rw-r--r--src/GUIbutton.py67
-rw-r--r--src/MacPan.py138
-rw-r--r--src/Testfunction.py (renamed from src/macpan.py)0
-rw-r--r--src/blinky.py5
-rw-r--r--src/clyde.py10
-rw-r--r--src/game.py76
-rw-r--r--src/game_state.py24
-rw-r--r--src/ghost.py12
-rw-r--r--src/inky.py6
-rw-r--r--src/pinky.py6
-rw-r--r--src/player.py15
-rw-r--r--src/settings.py11
19 files changed, 287 insertions, 211 deletions
diff --git a/README.md b/README.md
index 3c627a9..5e2eed4 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
```bash
cd src
-python3 macpan.py
+python3 Testfunction.py
```
# TODO
diff --git a/assets/Options Rect.png b/assets/Options Rect.png
index 2e8642b..3b603fa 100644
--- a/assets/Options Rect.png
+++ b/assets/Options Rect.png
Binary files differ
diff --git a/assets/Play Rect.png b/assets/Play Rect.png
index 6d144eb..2ae690d 100644
--- a/assets/Play Rect.png
+++ b/assets/Play Rect.png
Binary files differ
diff --git a/assets/PressStart2P-Regular.ttf b/assets/PressStart2P-Regular.ttf
new file mode 100644
index 0000000..e9b029c
--- /dev/null
+++ b/assets/PressStart2P-Regular.ttf
Binary files differ
diff --git a/assets/Quit Rect.png b/assets/Quit Rect.png
index 0481ec0..99fa37b 100644
--- a/assets/Quit Rect.png
+++ b/assets/Quit Rect.png
Binary files differ
diff --git a/assets/greenboxz.png b/assets/greenboxz.png
new file mode 100644
index 0000000..1c8ec89
--- /dev/null
+++ b/assets/greenboxz.png
Binary files differ
diff --git a/src/GUI.py b/src/GUI.py
deleted file mode 100644
index 21cec17..0000000
--- a/src/GUI.py
+++ /dev/null
@@ -1,126 +0,0 @@
-import pygame
-import sys
-from GUIbutton import Button
-from src.game import Game
-import ctypes
-
-# icon on taskbar
-
-myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
-ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
-
-
-pygame.init()
-
-SCREEN = pygame.display.set_mode((1280, 720))
-pygame.display.set_caption("Mac-Pan")
-
-BG = pygame.image.load("../assets/Background.png")
-
-icon = pygame.image.load("../assets/icon.png")
-pygame.display.set_icon(icon)
-
-
-
-def get_font(size): # Returns Press-Start-2P in the desired size
- return pygame.font.Font("../assets/PAC-FONT.TTF", size)
-
-
-# def play():
-# while True:
-# PLAY_MOUSE_POS = pygame.mouse.get_pos()
-#
-# SCREEN.fill("black")
-#
-# PLAY_TEXT = get_font(45).render("This is the PLAY screen.", True, "White")
-# PLAY_RECT = PLAY_TEXT.get_rect(center=(640, 260))
-# SCREEN.blit(PLAY_TEXT, PLAY_RECT)
-#
-# PLAY_BACK = Button(image=None, pos=(640, 460),
-# text_input="BACK", font=get_font(75), base_color="White", hovering_color="Green")
-#
-# PLAY_BACK.changeColor(PLAY_MOUSE_POS)
-# PLAY_BACK.update(SCREEN)
-#
-# for event in pygame.event.get():
-# if event.type == pygame.QUIT:
-# pygame.quit()
-# sys.exit()
-# if event.type == pygame.MOUSEBUTTONDOWN:
-# if PLAY_BACK.checkForInput(PLAY_MOUSE_POS):
-# main_menu()
-#
-# pygame.display.update()
-
-## Todo options sound options here ??
-def options():
- while True:
- OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
-
- SCREEN.fill("white")
-
- OPTIONS_TEXT = get_font(45).render("This is the OPTIONS screen.", True, "Black")
- OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
- SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
-
- OPTIONS_BACK = Button(image=None, pos=(640, 460),
- text_input="BACK", font=get_font(75), base_color="Black", hovering_color="Green")
-
- OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
- OPTIONS_BACK.update(SCREEN)
-
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- if event.type == pygame.MOUSEBUTTONDOWN:
- if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
- main_menu()
-
- pygame.display.update()
-
-
-def main_menu():
- while True:
- SCREEN.blit(BG, (0, 0))
-
- MENU_MOUSE_POS = pygame.mouse.get_pos()
-
- MENU_TEXT = get_font(100).render("Mac-Pan", True, "#b68f40")
- MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
-
- PLAY_BUTTON = Button(image=pygame.image.load("../assets/Play Rect.png"), pos=(640, 250),
- text_input="PLAY", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
- OPTIONS_BUTTON = Button(image=pygame.image.load("../assets/Options Rect.png"), pos=(640, 400),
- text_input="OPTIONS", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
- QUIT_BUTTON = Button(image=pygame.image.load("../assets/Quit Rect.png"), pos=(640, 550),
- text_input="QUIT", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
-
- SCREEN.blit(MENU_TEXT, MENU_RECT)
-
- for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
- button.changeColor(MENU_MOUSE_POS)
- button.update(SCREEN)
-
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- if event.type == pygame.MOUSEBUTTONDOWN:
- if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
- #play()
- game = Game()
- game.run()
-
- if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
- options()
- if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
- pygame.quit()
- sys.exit()
-
- pygame.display.update()
-
-
-
-
-main_menu()
diff --git a/src/GUIbutton.py b/src/GUIbutton.py
index 794f693..eebcf77 100644
--- a/src/GUIbutton.py
+++ b/src/GUIbutton.py
@@ -1,29 +1,38 @@
-class Button():
- def __init__(self, image, pos, text_input, font, base_color, hovering_color):
- self.image = image
- self.x_pos = pos[0]
- self.y_pos = pos[1]
- self.font = font
- self.base_color, self.hovering_color = base_color, hovering_color
- self.text_input = text_input
- self.text = self.font.render(self.text_input, True, self.base_color)
- if self.image is None:
- self.image = self.text
- self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
- self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
-
- def update(self, screen):
- if self.image is not None:
- screen.blit(self.image, self.rect)
- screen.blit(self.text, self.text_rect)
-
- def checkForInput(self, position):
- if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
- return True
- return False
-
- def changeColor(self, position):
- if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
- self.text = self.font.render(self.text_input, True, self.hovering_color)
- else:
- self.text = self.font.render(self.text_input, True, self.base_color) \ No newline at end of file
+
+
+class Button:
+ def __init__(self, image, pos, text_input, font, base_color, hovering_color):
+ self.image = image
+ self.x_pos = pos[0]
+ self.y_pos = pos[1]
+ self.font = font
+ self.base_color, self.hovering_color = base_color, hovering_color
+ self.text_input = text_input
+ self.text = self.font.render(self.text_input, True, self.base_color)
+ if self.image is None:
+ self.image = self.text
+ self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
+ self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
+
+ def update(self, screen):
+ if self.image is not None:
+ screen.blit(self.image, self.rect)
+ screen.blit(self.text, self.text_rect)
+
+ def checkForInput(self, position):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
+ self.rect.bottom):
+ return True
+ return False
+
+ def changeColor(self, position , text , text2 ):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
+ self.rect.bottom):
+ self.text = self.font.render(text, True, self.hovering_color)
+ else:
+ self.text = self.font.render(text2, True, self.base_color)
+
+
+
+
+
diff --git a/src/MacPan.py b/src/MacPan.py
new file mode 100644
index 0000000..e06e577
--- /dev/null
+++ b/src/MacPan.py
@@ -0,0 +1,138 @@
+import pygame
+import sys
+
+from GUIbutton import Button
+from game import Game
+import ctypes
+
+from settings import Settings, settings
+
+# icon on taskbar
+
+ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('Pacman')
+
+pygame.init()
+
+SCREEN = pygame.display.set_mode((1280, 720))
+pygame.display.set_caption("Mac-Pan")
+
+BG = pygame.image.load("../assets/Background.png")
+
+icon = pygame.image.load("../assets/icon.png")
+pygame.display.set_icon(icon)
+
+lolsettings = settings
+lolsettings.debug = False
+
+
+def get_font(size, number): # Returns Press-Start-2P in the desired size
+ if number == 1:
+ return pygame.font.Font("../assets/PressStart2P-Regular.ttf", size)
+ else:
+ return pygame.font.Font("../assets/PAC-FONT.TTF", size)
+
+
+def options():
+ while True:
+ OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
+
+ SCREEN.fill("#1e1f22")
+
+ OPTIONS_TEXT = get_font(45, 1).render("OPTIONS SCREEN", True, "white")
+ OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(630, 150))
+ SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
+
+ OPTIONS_BACK = Button(image=None, pos=(640, 520),
+ text_input="BACK", font=get_font(75, 1), base_color="white", hovering_color="yellow")
+
+ Debug_Mode = Button(image=pygame.image.load('../assets/Quit Rect.png'), pos=(300, 300),
+ text_input="Debug Mode", font=get_font(20, 1), base_color="Black",
+ hovering_color="yellow")
+
+ Sound_Mode = Button(image=pygame.image.load('../assets/Quit Rect.png'), pos=(900, 300),
+ text_input="Sound ", font=get_font(20, 1), base_color="Black",
+ hovering_color="yellow")
+
+ OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS, 'BACK', 'BACK')
+ OPTIONS_BACK.update(SCREEN)
+ Debug_Mode.update(SCREEN)
+ Sound_Mode.update(SCREEN)
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ pygame.quit()
+ sys.exit()
+ if event.type == pygame.MOUSEBUTTONDOWN:
+ if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
+ main_menu()
+ pygame.display.update()
+ elif Debug_Mode.checkForInput(OPTIONS_MOUSE_POS):
+ if lolsettings.debug:
+ lolsettings.debug = False
+ print("Debug State :")
+ print(lolsettings.debug)
+ else:
+ lolsettings.debug = True
+ print("Debug State :")
+ print(lolsettings.debug)
+
+ elif Sound_Mode.checkForInput(OPTIONS_MOUSE_POS):
+ if lolsettings.sound:
+ lolsettings.sound = False
+ print("Sound State :")
+ print(lolsettings.sound)
+ else:
+ lolsettings.sound = True
+ print("Sound State :")
+ print(lolsettings.sound)
+ pygame.display.update()
+
+
+def main_menu():
+ # Initialize Pygame
+ pygame.init()
+ while True:
+ SCREEN.blit(BG, (0, 0))
+
+ MENU_MOUSE_POS = pygame.mouse.get_pos()
+
+ MENU_TEXT = get_font(100, 2).render("Mac-Pan", True, "#b68f40")
+ MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
+
+ PLAY_BUTTON = Button(image=pygame.image.load("../assets/Play Rect.png"), pos=(640, 250),
+ text_input="PLaY", font=get_font(75, 2), base_color="#d7fcd4", hovering_color="#b68f40")
+ OPTIONS_BUTTON = Button(image=pygame.image.load("../assets/Options Rect.png"), pos=(640, 400),
+ text_input="OPTIoNS", font=get_font(75, 2), base_color="#d7fcd4",
+ hovering_color="#b68f40")
+ QUIT_BUTTON = Button(image=pygame.image.load("../assets/Quit Rect.png"), pos=(640, 550),
+ text_input="qUIT", font=get_font(75, 2), base_color="#d7fcd4", hovering_color="#b68f40")
+
+ SCREEN.blit(MENU_TEXT, MENU_RECT)
+
+ PLAY_BUTTON.changeColor(MENU_MOUSE_POS, "PLay", "PLAY")
+ PLAY_BUTTON.update(SCREEN)
+
+ OPTIONS_BUTTON.changeColor(MENU_MOUSE_POS, "oPTIoNs", "OPTIONS")
+ OPTIONS_BUTTON.update(SCREEN)
+
+ QUIT_BUTTON.changeColor(MENU_MOUSE_POS, "qUIT", "QUIT")
+ QUIT_BUTTON.update(SCREEN)
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ pygame.quit()
+ sys.exit()
+ if event.type == pygame.MOUSEBUTTONDOWN:
+ if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
+ game = Game(lolsettings)
+ game.run()
+ if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
+ options()
+ if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
+ pygame.quit()
+ sys.exit()
+
+ pygame.display.update()
+
+
+main_menu()
diff --git a/src/macpan.py b/src/Testfunction.py
index 712fdde..712fdde 100644
--- a/src/macpan.py
+++ b/src/Testfunction.py
diff --git a/src/blinky.py b/src/blinky.py
index 4c45644..b1bdcb4 100644
--- a/src/blinky.py
+++ b/src/blinky.py
@@ -2,5 +2,6 @@ from ghost import Ghost
class Blinky(Ghost):
- def __init__(self, sprite_sheet, x, y):
- super().__init__(sprite_sheet, "red", x, y)
+ def __init__(self, sprite_sheet, x, y,settings):
+ super().__init__(sprite_sheet, "red", x, y, settings)
+
diff --git a/src/clyde.py b/src/clyde.py
index 2fd4aee..acb9f42 100644
--- a/src/clyde.py
+++ b/src/clyde.py
@@ -8,8 +8,8 @@ import math
class Clyde(Ghost):
- def __init__(self, sprite_sheet, x, y):
- super().__init__(sprite_sheet, "cyan", x, y)
+ def __init__(self, sprite_sheet, x, y,settings):
+ super().__init__(sprite_sheet, "cyan", x, y,settings)
def is_eight_tiles_away(self, pacman):
tile_width = 30
@@ -49,7 +49,7 @@ class Clyde(Ghost):
if game_state.pacman.powerup is False and self.mode == MODE.FRIGHETENED:
self.mode = MODE.CHASING
- if settings.debug:
+ if self.settings.debug:
pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
(self.x, self.y), 1)
@@ -68,13 +68,13 @@ class Clyde(Ghost):
if self.is_eight_tiles_away(game_state.pacman):
ret[i] = self.heuristic(
(nx, ny), bottom_left_corner[0], bottom_left_corner[1])
- if settings.debug:
+ if self.settings.debug:
pygame.draw.line(screen, self.color, (bottom_left_corner),
(self.x, self.y), 1)
else:
ret[i] = self.heuristic(
(nx, ny), game_state.pacman.x, game_state.pacman.y)
- if settings.debug:
+ if self.settings.debug:
pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
(self.x, self.y), 1)
elif self.mode == MODE.EATEN:
diff --git a/src/game.py b/src/game.py
index a7efb67..8872c0c 100644
--- a/src/game.py
+++ b/src/game.py
@@ -1,3 +1,7 @@
+import os
+import sys
+import time
+
from direction import DIRECTION
from game_state import GameState
from mode import MODE
@@ -7,12 +11,12 @@ import pygame
class Game():
- def __init__(self):
- self.settings = settings
+ def __init__(self, lolsettings):
+ self.settings = lolsettings
def show_gameover_screen(self, screen, game_state, sprites):
font = pygame.font.SysFont(None, 64)
-
+ self.score(screen, game_state.score, 200, 800)
# Render the "Game Over" text to a surface
game_over_text_1 = font.render(
"Game Over", True, (255, 255, 255))
@@ -21,9 +25,9 @@ class Game():
# Blit the "Game Over" text onto the screen
text_rect_1 = game_over_text_1.get_rect(
- center=(WIDTH/2, HEIGHT/2 - 75))
+ center=(WIDTH / 2, HEIGHT / 2 - 75))
text_rect_2 = game_over_text_2.get_rect(
- center=(WIDTH/2, HEIGHT/2))
+ center=(WIDTH / 2, HEIGHT / 2))
screen.blit(game_over_text_1, text_rect_1)
screen.blit(game_over_text_2, text_rect_2)
@@ -44,31 +48,52 @@ class Game():
elif event.type == pygame.KEYDOWN and event.key == pygame.K_q:
game_state.game_over = True
quit_game = True
- break
+ pygame.quit()
+ os.system("python MacPan.py 1")
+ exit()
elif event.type == pygame.QUIT:
game_state.game_over = True
quit_game = True # Set the flag to True to break out of both loops
break
+ def score(self, screen, text, POS1, POS2):
+ font = pygame.font.Font('../assets/PressStart2P-Regular.ttf', 21)
+
+ wining_text_123 = font.render(
+ "Score", True, (255, 255, 255))
+
+ # Render the "Game Over" text to a surface
+ wining_text_12 = font.render(
+ str(text), True, (255, 255, 255))
+
+ # Blit the "Game Over" text onto the screen
+ text_rect_12 = wining_text_12.get_rect(
+ center=(POS1 / 2, POS2 / 2))
+
+ text_rect_123 = wining_text_123.get_rect(
+ center=(POS1 / 2, ((POS2 / 2) - 50)))
+
+ screen.blit(wining_text_12, text_rect_12)
+ screen.blit(wining_text_123, text_rect_123)
+
+ # Update the display
+ pygame.display.flip()
+
def show_wining_screen(self, screen, game_state, sprites):
font = pygame.font.SysFont(None, 64)
+ self.score(screen, game_state.score, 200, 800)
# Render the "Game Over" text to a surface
wining_text_1 = font.render(
"Congratulation You Won!!", True, (255, 255, 255))
wining_text_2 = font.render(
"Press R to play again or Q to quit", True, (255, 255, 255))
- text_rect_1 = wining_text_1.get_rect(
- center=(WIDTH/2, HEIGHT/2 - 75))
- text_rect_2 = wining_text_2.get_rect(
- center=(WIDTH/2, HEIGHT/2))
-
# Blit the "Game Over" text onto the screen
text_rect_1 = wining_text_1.get_rect(
- center=(WIDTH/2, HEIGHT/2))
+ center=(WIDTH / 2, HEIGHT / 2))
text_rect_2 = wining_text_2.get_rect(
- center=(WIDTH/2, HEIGHT/2 + 100))
+ center=(WIDTH / 2, HEIGHT / 2 + 100))
screen.blit(wining_text_1, text_rect_1)
screen.blit(wining_text_2, text_rect_2)
@@ -88,14 +113,16 @@ class Game():
elif event.type == pygame.KEYDOWN and event.key == pygame.K_q:
game_state.game_over = True
quit_game = True
- break
+ pygame.quit()
+ os.system("python MacPan.py 1")
+ exit()
elif event.type == pygame.QUIT:
game_state.game_over = True
quit_game = True # Set the flag to True to break out of both loops
break
def reset_game(self, game_state, sprites):
- game_state.reset(sprites)
+ game_state.reset(sprites, self.settings)
def run(self):
# Initialize Pygame
@@ -122,7 +149,8 @@ class Game():
timer_event = pygame.USEREVENT + 1
pygame.time.set_timer(timer_event, 1000 * 10, 1)
- game_state = GameState(sprites)
+ game_state = GameState(sprites, self.settings)
+ # self.score(screen,game_state.score,WIDTH,HEIGHT)
# Set the pacman velocity
dx = 0
@@ -132,11 +160,11 @@ class Game():
counter = 0
clock = pygame.time.Clock()
-
+ pygame.mixer.set_num_channels(5)
pygame.mixer.music.load('../assets/sfx/game_start.wav')
siren_sound = pygame.mixer.Sound('../assets/sfx/siren_1.wav')
- if settings.sound:
+ if self.settings.sound:
pygame.mixer.music.play()
siren_sound.play(-1)
@@ -145,9 +173,12 @@ class Game():
# setting game fps
clock.tick(settings.fps)
+ # self.score(screen, game_state.score,WIDTH,HEIGHT)
+
# counter logic for cycling between pacman different sprites
if counter < 19:
counter += 1
+
else:
counter = 0
@@ -246,15 +277,20 @@ class Game():
if game_state.food == 246:
self.show_wining_screen(screen, game_state, sprites)
-
if not game_state.is_pacman_alive:
+ siren_sound.stop()
+ pygame.mixer.music.load('../assets/sfx/death_1.wav')
+ if self.settings.sound:
+ pygame.mixer.music.play()
self.show_gameover_screen(
screen, game_state, sprites)
game_state.is_pacman_alive = True
+
else:
+ self.score(screen, game_state.score, WIDTH, HEIGHT)
# Update the screen
pygame.display.flip()
# Quit Pygame
- print(game_state.score)
+
pygame.quit()
diff --git a/src/game_state.py b/src/game_state.py
index 5ed98c0..d942ae1 100644
--- a/src/game_state.py
+++ b/src/game_state.py
@@ -15,32 +15,32 @@ TILE_HEIGHT = HEIGHT // len(maze.maze)
class GameState():
- def __init__(self, sprites):
- self.pacman = Player(sprites[0])
+ def __init__(self, sprites, settings):
+ self.pacman = Player(sprites[0],settings)
self.blinky = Blinky(sprites[1], 12 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.pinky = Pinky(sprites[2], 11 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.inky = Inky(sprites[3], 13 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.clyde = Clyde(sprites[4], 14 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.map = Map.Map()
self.food = 0
self.game_over = False
self.score = 0
self.is_pacman_alive = True
- def reset(self, sprites):
- self.pacman = Player(sprites[0])
+ def reset(self, sprites ,settings):
+ self.pacman = Player(sprites[0],settings)
self.blinky = Blinky(sprites[1], 12 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.pinky = Pinky(sprites[2], 11 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.inky = Inky(sprites[3], 13 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.clyde = Clyde(sprites[4], 14 * TILE_WIDTH +
- 15, 12 * TILE_HEIGHT + 15)
+ 15, 12 * TILE_HEIGHT + 15,settings)
self.map = Map.Map()
self.food = 0
self.game_over = False
diff --git a/src/ghost.py b/src/ghost.py
index 8568ff4..37c3d37 100644
--- a/src/ghost.py
+++ b/src/ghost.py
@@ -17,7 +17,7 @@ sprite_sheet = [2, 0, 3, 1]
class Ghost():
- def __init__(self, sprite_sheet, color, x, y):
+ def __init__(self, sprite_sheet, color, x, y ,lol):
self.x = x
self.y = y
self.sprite_sheet = sprite_sheet
@@ -28,6 +28,7 @@ class Ghost():
self.speed = 3
self.timer = None
self.mode = MODE.SCATTERED
+ self.settings = lol
def in_bounds(self, pos):
(x, y) = pos
@@ -69,14 +70,19 @@ class Ghost():
return True
def check_pacman_collision(self, game_state):
+ voiceofdot2 = pygame.mixer.Channel(4)
+ dotpickup = pygame.mixer.Sound('../assets/sfx/eat_ghost.wav')
+
if game_state.pacman.powerup and abs(game_state.pacman.x - self.x) <= 30 and abs(game_state.pacman.y - self.y) <= 30:
initial_position = self.get_intial_tile()
self.mode = MODE.EATEN
self.timer = Timer(2 * 1000)
- time.sleep(1)
+ time.sleep(0.3)
game_state.score += 200
self.x = initial_position[0]
self.y = initial_position[1]
+ if self.settings.sound:
+ voiceofdot2.play(dotpickup)
elif not game_state.pacman.powerup and abs(game_state.pacman.x - self.x) <= 30 and abs(game_state.pacman.y - self.y) <= 30:
if abs(game_state.pacman.x - self.x) <= 30 and abs(game_state.pacman.y - self.y) <= 30:
game_state.is_pacman_alive = False
@@ -116,7 +122,7 @@ class Ghost():
pos = self.get_intial_tile()
self.x = pos[0]
self.y = pos[1]
- if settings.debug:
+ if self.settings.debug:
pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
(self.x, self.y), 1)
diff --git a/src/inky.py b/src/inky.py
index be2e62c..e75b379 100644
--- a/src/inky.py
+++ b/src/inky.py
@@ -9,8 +9,8 @@ from ghost import Ghost
class Inky(Ghost):
- def __init__(self, sprite_sheet, x, y):
- super().__init__(sprite_sheet, "orange", x, y)
+ def __init__(self, sprite_sheet, x, y,settings):
+ super().__init__(sprite_sheet, "orange", x, y,settings)
def get_intermediate_tile(self, pacman):
if pacman.direction == DIRECTION.UP:
@@ -83,7 +83,7 @@ class Inky(Ghost):
if game_state.pacman.powerup is False and self.mode == MODE.FRIGHETENED:
self.mode = MODE.CHASING
- if settings.debug:
+ if self.settings.debug:
pygame.draw.line(screen, self.color, (target),
(self.x, self.y), 1)
diff --git a/src/pinky.py b/src/pinky.py
index bb50c5b..e02fbaa 100644
--- a/src/pinky.py
+++ b/src/pinky.py
@@ -9,8 +9,8 @@ from ghost import Ghost
class Pinky(Ghost):
- def __init__(self, sprite_sheet, x, y):
- super().__init__(sprite_sheet, "pink", x, y)
+ def __init__(self, sprite_sheet, x, y,settings):
+ super().__init__(sprite_sheet, "pink", x, y,settings)
def get_four_tiles_ahead_of_pacman(self, pacman):
if pacman.direction == DIRECTION.UP:
@@ -95,7 +95,7 @@ class Pinky(Ghost):
pos = self.get_intial_tile()
self.x = pos[0]
self.y = pos[1]
- if settings.debug:
+ if self.settings.debug:
pygame.draw.line(screen, self.color, (new_target),
(self.x, self.y), 1)
diff --git a/src/player.py b/src/player.py
index 92c4a84..1e880a1 100644
--- a/src/player.py
+++ b/src/player.py
@@ -6,7 +6,9 @@ import pygame
class Player():
- def __init__(self, sprite_sheet):
+
+ def __init__(self, sprite_sheet, settings):
+ self.settings = settings
self.x = 30 * 17 - 15
self.y = 30 * 25 - 15
self.sprite_sheet = sprite_sheet
@@ -18,6 +20,7 @@ class Player():
# checks if the current position of pacman is either a dot, big dot or free
def is_valid(self, game_state, x, y):
+
if x >= 0 and x < 30:
is_dot = game_state.map.maze[y][x] == Map.D
is_big_dot = game_state.map.maze[y][x] == Map.BD
@@ -27,6 +30,7 @@ class Player():
game_state.food += 1
if is_dot:
game_state.score += 10
+
if is_big_dot:
self.powerup = True
self.timer = Timer(5 * 1000)
@@ -53,11 +57,15 @@ class Player():
return True
def draw(self, screen, counter):
+ voice = pygame.mixer.Channel(2)
+ Soundpowerup = pygame.mixer.Sound('../assets/sfx/power_pellet.wav')
if self.timer is not None:
elapsed_time = pygame.time.get_ticks() - self.timer.start
if elapsed_time > self.timer.duration:
self.powerup = False
+
+
radius = 30 // 2
pos = (self.x - radius, self.y - radius)
sprite_sheet = [2, 0, 3, 1]
@@ -67,7 +75,12 @@ class Player():
image = pygame.transform.scale(
self.sprite[sprite_sheet[self.direction.value]], (40, 40))
screen.blit(image, pos)
+ if self.settings.sound:
+ if not (voice.get_busy()):
+ voice.play(Soundpowerup)
+
else:
+ voice.stop()
self.sprite = get_sprites(self.sprite_sheet)
image = pygame.transform.scale(self.sprite[counter // 5], (35, 35))
if self.direction == DIRECTION.UP:
diff --git a/src/settings.py b/src/settings.py
index a8dfa24..cb4ec0d 100644
--- a/src/settings.py
+++ b/src/settings.py
@@ -1,10 +1,9 @@
class Settings():
- def __init__(self):
- self.width = 900
- self.height = 990
- self.fps = 60
- self.debug = False
- self.sound = False
+ width = 900
+ height = 990
+ fps = 60
+ debug = False
+ sound = False
settings = Settings()