Update Game_V2.py

master
Romāns Šaduncs 2024-03-04 07:16:46 +00:00
parent cb9ed69a60
commit bae5f86774
1 changed files with 34 additions and 15 deletions

View File

@ -61,7 +61,6 @@ class Player(pygame.sprite.Sprite):
def get_health(self, amnount):
if self.target_health < self.maximum_health:
self.target_health += amnount
pygame.mixer.Sound("Sounds/health_plus.mp3")
if self.target_health >= self.maximum_health:
self.target_health = self.maximum_health
@ -365,6 +364,10 @@ pygame.mouse.set_cursor(cursor)
pygame.mouse.set_visible(True | False)
# Add a variable to track player's life status
player_alive = True
# Main game loop
while running:
for e in pygame.event.get():
if e.type == pygame.QUIT:
@ -373,7 +376,6 @@ while running:
if e.type == spawn_enemy_event:
spawn_enemy()
if e.type == spawn_enemy_event:
spawn_enemy2()
@ -384,23 +386,40 @@ while running:
player.time -= 1
else:
pass
# Check if the player's health reaches zero
if player.target_health <= 0:
running == False
print("Your score was " + str(player.SCORE))
pygame.quit()
player_alive = False
screen.fill("cyan")
if not player_alive: # Display death screen
screen.fill((0, 0, 0)) # Fill screen with black color
death_font = pygame.font.Font(None, 50)
death_text = smallfont.render("You Died! Your score was " + str(player.SCORE), True, (255, 255, 255))
screen.blit(death_text, (SCREEN_X // 2 - death_text.get_width() // 2, SCREEN_Y // 2 - death_text.get_height() // 2))
restart_text = smallfont.render("Press SPACE to restart", True, (255, 255, 255))
screen.blit(restart_text, (SCREEN_X // 2 - restart_text.get_width() // 2, SCREEN_Y // 2 + 50))
quit_text = smallfont.render("Press Q to quit", True, (255, 255, 255))
screen.blit(quit_text, (SCREEN_X // 2 - quit_text.get_width() // 2, SCREEN_Y // 2 + 100))
pygame.display.flip()
score(player.SCORE)
# Check for restart or quit input
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
# Reset player's health, score, and other relevant variables
player_alive = True
player.current_health = player.maximum_health
player.target_health = player.maximum_health
player.SCORE = 0
if keys[pygame.K_q]:
running = False
camera_group.update()
camera_group.custom_draw(player)
pygame.display.flip()
else: # If player is alive, continue the game
screen.fill("cyan")
score(player.SCORE)
camera_group.update()
camera_group.custom_draw(player)
pygame.display.flip()
clock.tick(60)
player.time += 0.016
player.time_2 += 0.005
player.time_2 += 0.005