Update game2
parent
b3b5c6e7dc
commit
5dcdc5faf1
46
game2
46
game2
|
@ -112,6 +112,14 @@ def handle_character_selection():
|
||||||
elif event.key == pygame.K_RETURN:
|
elif event.key == pygame.K_RETURN:
|
||||||
return CHARACTER_OPTIONS[selected_character_index]["image"]
|
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
|
# Main loop for character selection screen
|
||||||
while True:
|
while True:
|
||||||
screen.fill(BLACK)
|
screen.fill(BLACK)
|
||||||
|
@ -201,7 +209,8 @@ class FallingObject:
|
||||||
surface.blit(self.image, (self.x, self.y))
|
surface.blit(self.image, (self.x, self.y))
|
||||||
|
|
||||||
# Main game loop
|
# 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():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
@ -347,22 +356,35 @@ while not game_over and not winning:
|
||||||
# Cap the frame rate
|
# Cap the frame rate
|
||||||
pygame.time.Clock().tick(60)
|
pygame.time.Clock().tick(60)
|
||||||
|
|
||||||
# Play appropriate sound and display text
|
# Play appropriate sound and display text
|
||||||
if game_over:
|
if game_over:
|
||||||
if death_sound:
|
if death_sound:
|
||||||
death_sound.play()
|
death_sound.play()
|
||||||
screen.blit(game_over_text, game_over_rect)
|
screen.blit(game_over_text, game_over_rect)
|
||||||
elif winning:
|
elif winning:
|
||||||
if win_sound:
|
if win_sound:
|
||||||
win_sound.play()
|
win_sound.play()
|
||||||
screen.blit(winning_text, winning_rect)
|
screen.blit(winning_text, winning_rect)
|
||||||
|
|
||||||
# Update the display
|
# Draw play again button
|
||||||
pygame.display.flip()
|
play_again_rect = draw_button()
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
# Wait for a few seconds before quitting
|
# Check for button click
|
||||||
pygame.time.wait(5000)
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
||||||
# Quit Pygame
|
if play_again_rect.collidepoint(event.pos):
|
||||||
pygame.quit()
|
# Reset the game state
|
||||||
sys.exit()
|
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