Update Game_V2.py
parent
cb9ed69a60
commit
bae5f86774
41
Game_V2.py
41
Game_V2.py
|
@ -61,7 +61,6 @@ class Player(pygame.sprite.Sprite):
|
||||||
def get_health(self, amnount):
|
def get_health(self, amnount):
|
||||||
if self.target_health < self.maximum_health:
|
if self.target_health < self.maximum_health:
|
||||||
self.target_health += amnount
|
self.target_health += amnount
|
||||||
pygame.mixer.Sound("Sounds/health_plus.mp3")
|
|
||||||
if self.target_health >= self.maximum_health:
|
if self.target_health >= self.maximum_health:
|
||||||
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)
|
pygame.mouse.set_visible(True | False)
|
||||||
|
|
||||||
|
|
||||||
|
# Add a variable to track player's life status
|
||||||
|
player_alive = True
|
||||||
|
|
||||||
|
# Main game loop
|
||||||
while running:
|
while running:
|
||||||
for e in pygame.event.get():
|
for e in pygame.event.get():
|
||||||
if e.type == pygame.QUIT:
|
if e.type == pygame.QUIT:
|
||||||
|
@ -374,7 +377,6 @@ while running:
|
||||||
if e.type == spawn_enemy_event:
|
if e.type == spawn_enemy_event:
|
||||||
spawn_enemy()
|
spawn_enemy()
|
||||||
|
|
||||||
|
|
||||||
if e.type == spawn_enemy_event:
|
if e.type == spawn_enemy_event:
|
||||||
spawn_enemy2()
|
spawn_enemy2()
|
||||||
|
|
||||||
|
@ -384,21 +386,38 @@ while running:
|
||||||
player.time -= 1
|
player.time -= 1
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Check if the player's health reaches zero
|
||||||
if player.target_health <= 0:
|
if player.target_health <= 0:
|
||||||
running == False
|
player_alive = False
|
||||||
print("Your score was " + str(player.SCORE))
|
|
||||||
pygame.quit()
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
else: # If player is alive, continue the game
|
||||||
screen.fill("cyan")
|
screen.fill("cyan")
|
||||||
|
|
||||||
score(player.SCORE)
|
score(player.SCORE)
|
||||||
|
|
||||||
|
|
||||||
camera_group.update()
|
camera_group.update()
|
||||||
camera_group.custom_draw(player)
|
camera_group.custom_draw(player)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
|
Loading…
Reference in New Issue