diff options
| author | Moisis <moisis.george@yahoo.com> | 2023-05-19 23:40:23 +0300 |
|---|---|---|
| committer | Moisis <moisis.george@yahoo.com> | 2023-05-19 23:40:23 +0300 |
| commit | 6a351ed2d6a554ed6d338abba234527705d1040f (patch) | |
| tree | a0475e1d88be01716e76f2e75c495a4284290bb9 | |
| parent | 0889aaf69cc0d4ca32ce66e000e827bddf6bd162 (diff) | |
| download | Macpan-6a351ed2d6a554ed6d338abba234527705d1040f.tar.xz Macpan-6a351ed2d6a554ed6d338abba234527705d1040f.zip | |
Final Touches #2
| -rw-r--r-- | assets/Options Rect.png | bin | 1569 -> 2962 bytes | |||
| -rw-r--r-- | assets/Play Rect.png | bin | 1023 -> 2403 bytes | |||
| -rw-r--r-- | assets/PressStart2P-Regular.ttf | bin | 0 -> 116008 bytes | |||
| -rw-r--r-- | assets/Quit Rect.png | bin | 1003 -> 2364 bytes | |||
| -rw-r--r-- | src/GUIbutton.py | 52 | ||||
| -rw-r--r-- | src/MacPan.py | 50 | ||||
| -rw-r--r-- | src/game.py | 24 |
7 files changed, 35 insertions, 91 deletions
diff --git a/assets/Options Rect.png b/assets/Options Rect.png Binary files differindex 2e8642b..3b603fa 100644 --- a/assets/Options Rect.png +++ b/assets/Options Rect.png diff --git a/assets/Play Rect.png b/assets/Play Rect.png Binary files differindex 6d144eb..2ae690d 100644 --- a/assets/Play Rect.png +++ b/assets/Play Rect.png diff --git a/assets/PressStart2P-Regular.ttf b/assets/PressStart2P-Regular.ttf Binary files differnew file mode 100644 index 0000000..e9b029c --- /dev/null +++ b/assets/PressStart2P-Regular.ttf diff --git a/assets/Quit Rect.png b/assets/Quit Rect.png Binary files differindex 0481ec0..99fa37b 100644 --- a/assets/Quit Rect.png +++ b/assets/Quit Rect.png diff --git a/src/GUIbutton.py b/src/GUIbutton.py index 32303a2..eebcf77 100644 --- a/src/GUIbutton.py +++ b/src/GUIbutton.py @@ -1,7 +1,6 @@ -import pygame.display -class Button(): +class Button: def __init__(self, image, pos, text_input, font, base_color, hovering_color): self.image = image self.x_pos = pos[0] @@ -26,55 +25,12 @@ class Button(): return True return False - def changeColor(self, position): + 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(self.text_input, True, self.hovering_color) + self.text = self.font.render(text, True, self.hovering_color) else: - 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): - super(ToggleSwitch, self).__init__() - 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 changetext1(self): - # 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("Debug Mode is ON", True, self.hovering_color) - # else: - def changetext2(self): - self.text = self.font.render("Debug Mode is OFF", True, self.base_color) - + self.text = self.font.render(text2, True, self.base_color) diff --git a/src/MacPan.py b/src/MacPan.py index d6297c6..e06e577 100644 --- a/src/MacPan.py +++ b/src/MacPan.py @@ -1,7 +1,7 @@ import pygame import sys -from GUIbutton import Button, ToggleSwitch +from GUIbutton import Button from game import Game import ctypes @@ -45,23 +45,17 @@ def options(): 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 is OFF", font=get_font(20, 1), base_color="Black", - hovering_color="cyan") + 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 = ToggleSwitch(image=pygame.image.load('../assets/Quit Rect.png'), pos=(900, 300), + 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="cyan") + hovering_color="yellow") - # Debug_Mode_RECT = Debug_Mode.text.get_rect(center=(640, 150)) - - OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS) + OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS, 'BACK', 'BACK') OPTIONS_BACK.update(SCREEN) - # Debug_Mode.changetext(OPTIONS_MOUSE_POS) - # 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(): @@ -75,28 +69,21 @@ def options(): elif Debug_Mode.checkForInput(OPTIONS_MOUSE_POS): if lolsettings.debug: lolsettings.debug = False - # Debug_Mode.update_image2(pygame.image.load('../assets/Quit Rect.png')) - # pygame.display.update() - Debug_Mode.changetext1() - Debug_Mode.update(SCREEN) - print(Debug_Mode.text_input) print("Debug State :") print(lolsettings.debug) - else: lolsettings.debug = True - Debug_Mode.changetext2() - Debug_Mode.update(SCREEN) - pygame.display.update() 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() @@ -113,18 +100,23 @@ def main_menu(): 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") + 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="White") + 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="White") + text_input="qUIT", font=get_font(75, 2), base_color="#d7fcd4", hovering_color="#b68f40") SCREEN.blit(MENU_TEXT, MENU_RECT) - for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]: - button.changeColor(MENU_MOUSE_POS) - button.update(SCREEN) + 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: diff --git a/src/game.py b/src/game.py index e211da7..8872c0c 100644 --- a/src/game.py +++ b/src/game.py @@ -14,10 +14,9 @@ class Game(): 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) + 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)) @@ -57,12 +56,11 @@ class Game(): 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.SysFont(None, 21) + 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)) + "Score", True, (255, 255, 255)) # Render the "Game Over" text to a surface wining_text_12 = font.render( @@ -73,8 +71,7 @@ class Game(): center=(POS1 / 2, POS2 / 2)) text_rect_123 = wining_text_123.get_rect( - center=(POS1 / 2,( (POS2 / 2)-50) )) - + center=(POS1 / 2, ((POS2 / 2) - 50))) screen.blit(wining_text_12, text_rect_12) screen.blit(wining_text_123, text_rect_123) @@ -92,7 +89,6 @@ class Game(): wining_text_2 = font.render( "Press R to play again or Q to quit", True, (255, 255, 255)) - # Blit the "Game Over" text onto the screen text_rect_1 = wining_text_1.get_rect( center=(WIDTH / 2, HEIGHT / 2)) @@ -126,7 +122,7 @@ class Game(): break def reset_game(self, game_state, sprites): - game_state.reset(sprites,self.settings) + game_state.reset(sprites, self.settings) def run(self): # Initialize Pygame @@ -154,7 +150,7 @@ class Game(): pygame.time.set_timer(timer_event, 1000 * 10, 1) game_state = GameState(sprites, self.settings) - self.score(screen,game_state.score,WIDTH,HEIGHT) + # self.score(screen,game_state.score,WIDTH,HEIGHT) # Set the pacman velocity dx = 0 @@ -168,7 +164,6 @@ class Game(): pygame.mixer.music.load('../assets/sfx/game_start.wav') siren_sound = pygame.mixer.Sound('../assets/sfx/siren_1.wav') - if self.settings.sound: pygame.mixer.music.play() siren_sound.play(-1) @@ -178,7 +173,8 @@ class Game(): # setting game fps clock.tick(settings.fps) - self.score(screen, game_state.score,WIDTH,HEIGHT) + # self.score(screen, game_state.score,WIDTH,HEIGHT) + # counter logic for cycling between pacman different sprites if counter < 19: counter += 1 @@ -186,7 +182,6 @@ class Game(): else: counter = 0 - screen.fill((0, 0, 0)) # Clear the screen # Temporary values for delta_x and delta_y in the position of pacman @@ -292,6 +287,7 @@ class Game(): game_state.is_pacman_alive = True else: + self.score(screen, game_state.score, WIDTH, HEIGHT) # Update the screen pygame.display.flip() |
