aboutsummaryrefslogtreecommitdiff
path: root/src/game.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.py')
-rw-r--r--src/game.py47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/game.py b/src/game.py
index 928b665..192c356 100644
--- a/src/game.py
+++ b/src/game.py
@@ -1,5 +1,6 @@
import os
import sys
+import time
from direction import DIRECTION
from game_state import GameState
@@ -16,7 +17,7 @@ class Game():
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))
@@ -56,19 +57,41 @@ 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)
+
+ 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(
@@ -94,7 +117,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
@@ -152,12 +177,15 @@ 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
+
screen.fill((0, 0, 0)) # Clear the screen
# Temporary values for delta_x and delta_y in the position of pacman
@@ -256,15 +284,16 @@ class Game():
if not game_state.is_pacman_alive:
siren_sound.stop()
pygame.mixer.music.load('../assets/sfx/death_1.wav')
- pygame.mixer.music.play()
+ if self.settings.sound:
+ pygame.mixer.music.play()
self.show_gameover_screen(
screen, game_state, sprites)
game_state.is_pacman_alive = True
-
+ self.score( screen, game_state)
else:
# Update the screen
pygame.display.flip()
# Quit Pygame
- print(game_state.score)
+
pygame.quit()