Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from inputs import InputManager, PLAYER_KEYMAPS
from player import Player
from npc import NPC
from ui import show_end_message


from config import GAME_FPS
Expand Down Expand Up @@ -44,6 +45,8 @@ def __init__(self, **kwargs):
self.last_spawn_time = pygame.time.get_ticks()
self.spawn_interval_range = (3000, 5000)

self.game_result = None


def spawn_random_npc(self):
npc_type = random.choices(
Expand Down Expand Up @@ -76,7 +79,7 @@ def try_npc_shoot(self, npc):
npc.rect.centerx, npc.rect.centery,
target.rect.centerx, target.rect.centery,
color=(255, 0, 0),
shooter=npc # tady přidáš referenci na střílejícího NPC
shooter=npc
)
self.npc_bullets.append(bullet)
self.npc_last_shot_times[npc_id] = now
Expand Down Expand Up @@ -193,21 +196,11 @@ def update_bullets(self):
def check_game_end(self):
alive_players = [p for p in self.players.values() if p.health > 0]
if not alive_players:
self.running = False
if self.score >= 200:
self.display_end_message("You win!")
if self.score >= 100:
self.game_result = "win"
else:
self.display_end_message("You lost.")

def display_end_message(self, message):
font = pygame.font.SysFont(None, 60)
text = font.render(message, True, (255, 255, 255))
rect = text.get_rect(center=(self.screen.get_width() // 2, self.screen.get_height() // 2))
self.screen.fill((0, 0, 0))
self.screen.blit(text, rect)
pygame.display.flip()
pygame.time.wait(3000)

self.game_result = "lost"
self.running = False

def run(self):
"""Running loop"""
Expand All @@ -233,6 +226,7 @@ def run(self):


print("Closing game ....")
return self.game_result



Expand Down
16 changes: 13 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from enums import GameType
from game import SingleGame, CoopGame
from ui import show_menu, show_splash
from ui import show_menu, show_splash, show_end_message
from config import SCREEN_WIDTH, SCREEN_HEIGHT

pygame.init()
Expand All @@ -24,11 +24,21 @@ def main():

if choice == GameType.SINGLE:
game = SingleGame(screen=screen)
game.run()
result = game.run()
if result == "win":
show_end_message(screen, "You win!")
elif result == "lost":
show_end_message(screen, "You lost.")

if choice == GameType.COOP:
game = CoopGame(screen=screen)
game.run()
result = game.run()
if result == "win":
show_end_message(screen, "You win!")
elif result == "lost":
show_end_message(screen, "You lost.")
else:
show_end_message(screen, "Game ended.")

elif choice == "quit":
break
Expand Down
9 changes: 9 additions & 0 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ def show_splash(screen):

if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
return

def show_end_message(screen, message):
font = pygame.font.SysFont(None, 60)
text = font.render(message, True, (255, 255, 255))
rect = text.get_rect(center=(screen.get_width() // 2, screen.get_height() // 2))
screen.fill((0, 0, 0))
screen.blit(text, rect)
pygame.display.flip()
pygame.time.wait(3000)
Loading