Update game2
parent
b3b5c6e7dc
commit
5dcdc5faf1
46
game2
46
game2
|
@ -112,6 +112,14 @@ def handle_character_selection():
|
|||
elif event.key == pygame.K_RETURN:
|
||||
return CHARACTER_OPTIONS[selected_character_index]["image"]
|
||||
|
||||
# Function to create a button
|
||||
def draw_button():
|
||||
play_again_text = font.render("Play Again", True, WHITE)
|
||||
play_again_rect = play_again_text.get_rect(center=(WIDTH // 2, HEIGHT // 2 + 50))
|
||||
pygame.draw.rect(screen, GREEN, play_again_rect, border_radius=5)
|
||||
screen.blit(play_again_text, play_again_rect)
|
||||
return play_again_rect
|
||||
|
||||
# Main loop for character selection screen
|
||||
while True:
|
||||
screen.fill(BLACK)
|
||||
|
@ -201,7 +209,8 @@ class FallingObject:
|
|||
surface.blit(self.image, (self.x, self.y))
|
||||
|
||||
# Main game loop
|
||||
while not game_over and not winning:
|
||||
while True:
|
||||
while not game_over and not winning:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
|
@ -347,22 +356,35 @@ while not game_over and not winning:
|
|||
# Cap the frame rate
|
||||
pygame.time.Clock().tick(60)
|
||||
|
||||
# Play appropriate sound and display text
|
||||
if game_over:
|
||||
# Play appropriate sound and display text
|
||||
if game_over:
|
||||
if death_sound:
|
||||
death_sound.play()
|
||||
screen.blit(game_over_text, game_over_rect)
|
||||
elif winning:
|
||||
elif winning:
|
||||
if win_sound:
|
||||
win_sound.play()
|
||||
screen.blit(winning_text, winning_rect)
|
||||
|
||||
# Update the display
|
||||
pygame.display.flip()
|
||||
# Draw play again button
|
||||
play_again_rect = draw_button()
|
||||
pygame.display.flip()
|
||||
|
||||
# Wait for a few seconds before quitting
|
||||
pygame.time.wait(5000)
|
||||
|
||||
# Quit Pygame
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
# Check for button click
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||
if play_again_rect.collidepoint(event.pos):
|
||||
# Reset the game state
|
||||
game_over = False
|
||||
winning = False
|
||||
score = 0
|
||||
lives = 9
|
||||
cat_rect.center = (WIDTH // 2, HEIGHT // 2)
|
||||
bricks.clear()
|
||||
for row in range(BRICK_ROWS):
|
||||
for col in range(BRICK_COLS):
|
||||
brick = pygame.Rect(col * (BRICK_WIDTH + 5), row * (BRICK_HEIGHT + 5), BRICK_WIDTH, BRICK_HEIGHT)
|
||||
bricks.append(brick)
|
||||
falling_cupcakes.clear()
|
||||
falling_footballs.clear()
|
||||
falling_trollfaces.clear()
|
Loading…
Reference in New Issue