From 3d7e3d1eba26cc57b31337b0708fce3747f8a988 Mon Sep 17 00:00:00 2001 From: Moisis Date: Wed, 17 May 2023 14:04:38 +0300 Subject: Improved GUI Settings added (Debug , Sound) SoundSystem added (Become sometimes laggy) --- src/GUI.py | 126 ---------------------------------------- src/GUIbutton.py | 41 ++++++++++++- src/MacPan.py | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Testfunction.py | 5 ++ src/blinky.py | 5 +- src/clyde.py | 10 ++-- src/game.py | 42 +++++++++----- src/game_state.py | 22 +++---- src/ghost.py | 12 +++- src/inky.py | 6 +- src/macpan.py | 5 -- src/pinky.py | 6 +- src/player.py | 16 ++++- src/settings.py | 11 ++-- 14 files changed, 289 insertions(+), 182 deletions(-) delete mode 100644 src/GUI.py create mode 100644 src/MacPan.py create mode 100644 src/Testfunction.py delete mode 100644 src/macpan.py (limited to 'src') 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..2c75a9c 100644 --- a/src/GUIbutton.py +++ b/src/GUIbutton.py @@ -1,3 +1,5 @@ + + class Button(): def __init__(self, image, pos, text_input, font, base_color, hovering_color): self.image = image @@ -26,4 +28,41 @@ class Button(): 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 + self.text = self.font.render(self.text_input, True, self.base_color) + +class ToggleSwitch(): + 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) + + def changeimage(self, image): + self.image = image + + diff --git a/src/MacPan.py b/src/MacPan.py new file mode 100644 index 0000000..f23b752 --- /dev/null +++ b/src/MacPan.py @@ -0,0 +1,164 @@ +import pygame +import sys + +from GUIbutton import Button, ToggleSwitch +from src.game import Game +import ctypes + +from src.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 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("#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 = ToggleSwitch(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="cyan") + + Sound_Mode = ToggleSwitch(image=pygame.image.load('../assets/Quit Rect.png'), pos=(900, 300), + text_input="Sound ", font=get_font(20, 1), base_color="Black", + hovering_color="cyan") + + # Debug_Mode_RECT = Debug_Mode.get_rect(center=(640, 150)) + # SCREEN.blit(Debug_Mode_RECT,Debug_Mode) + + OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS) + OPTIONS_BACK.update(SCREEN) + Debug_Mode.changeColor(OPTIONS_MOUSE_POS) + Debug_Mode.update(SCREEN) + Sound_Mode.changeColor(OPTIONS_MOUSE_POS) + 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() + elif Debug_Mode.checkForInput(OPTIONS_MOUSE_POS): + if lolsettings.debug : + lolsettings.debug = False + Debug_Mode.image = (pygame.image.load('../assets/Quit Rect.png')) + Debug_Mode.update(SCREEN) + options() + + else: + lolsettings.debug = True + Debug_Mode.image = (pygame.image.load('../assets/greenboxz.png')) + Debug_Mode.update(SCREEN) + elif Sound_Mode.checkForInput(OPTIONS_MOUSE_POS): + if lolsettings.sound : + lolsettings.sound=False + else: + lolsettings.sound = True + + + 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="White") + 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="White") + 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="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(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/Testfunction.py b/src/Testfunction.py new file mode 100644 index 0000000..712fdde --- /dev/null +++ b/src/Testfunction.py @@ -0,0 +1,5 @@ +from game import Game + +if __name__ == "__main__": + game = Game() + game.run() 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..928b665 100644 --- a/src/game.py +++ b/src/game.py @@ -1,3 +1,6 @@ +import os +import sys + from direction import DIRECTION from game_state import GameState from mode import MODE @@ -7,8 +10,9 @@ 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) @@ -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,7 +48,9 @@ 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 @@ -59,16 +65,16 @@ class Game(): 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)) + # 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) @@ -95,7 +101,7 @@ class Game(): 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 +128,7 @@ 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) # Set the pacman velocity dx = 0 @@ -132,11 +138,12 @@ 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) @@ -246,11 +253,14 @@ 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') + pygame.mixer.music.play() self.show_gameover_screen( screen, game_state, sprites) game_state.is_pacman_alive = True + else: # Update the screen pygame.display.flip() diff --git a/src/game_state.py b/src/game_state.py index 5ed98c0..41e7985 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): + def reset(self, sprites ,settings): self.pacman = Player(sprites[0]) 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/macpan.py b/src/macpan.py deleted file mode 100644 index 712fdde..0000000 --- a/src/macpan.py +++ /dev/null @@ -1,5 +0,0 @@ -from game import Game - -if __name__ == "__main__": - game = Game() - game.run() 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..590405a 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,8 @@ 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 +58,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 +76,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() -- cgit v1.2.3