Merge remote-tracking branch 'origin/main' into feat/items
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 766 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 710 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 710 KiB |
@@ -0,0 +1,122 @@
|
|||||||
|
import pygame
|
||||||
|
from button import Button
|
||||||
|
from settings import (COLOR_ENDSCREEN_BACKGROUND,
|
||||||
|
COLOR_ENDSCREEN_TEXT,
|
||||||
|
COLOR_ENDSCREEN_WIN,
|
||||||
|
COLOR_ENDSCREEN_LOSE,
|
||||||
|
COLOR_BUTTON_HOVER,
|
||||||
|
COLOR_BUTTON,
|
||||||
|
FONT_ENDSCREEN)
|
||||||
|
|
||||||
|
class Endscreen:
|
||||||
|
def __init__(self, screen, player_name, score_ects, time_survived, won):
|
||||||
|
self.screen = screen
|
||||||
|
self.player_name = player_name
|
||||||
|
self.score_ects = score_ects
|
||||||
|
self.time_survived = time_survived
|
||||||
|
self.won = won
|
||||||
|
|
||||||
|
# setup fonts
|
||||||
|
self.font_title = pygame.font.SysFont(FONT_ENDSCREEN, 52, bold=True)
|
||||||
|
self.font_label = pygame.font.SysFont(FONT_ENDSCREEN, 28)
|
||||||
|
self.font_small = pygame.font.SysFont(FONT_ENDSCREEN, 22)
|
||||||
|
|
||||||
|
# setup colors
|
||||||
|
self.background_color = COLOR_ENDSCREEN_BACKGROUND
|
||||||
|
self.text_color = COLOR_ENDSCREEN_TEXT
|
||||||
|
|
||||||
|
self.win_color = COLOR_ENDSCREEN_WIN
|
||||||
|
self.lose_color = COLOR_ENDSCREEN_LOSE
|
||||||
|
|
||||||
|
self.button_color = COLOR_BUTTON
|
||||||
|
self. button_hover_color = COLOR_BUTTON_HOVER
|
||||||
|
|
||||||
|
# Buttons
|
||||||
|
self.button_restart = Button(
|
||||||
|
"[ENTER] Try Again",
|
||||||
|
500,
|
||||||
|
70,
|
||||||
|
230,
|
||||||
|
440,
|
||||||
|
self.button_color,
|
||||||
|
self.button_hover_color
|
||||||
|
)
|
||||||
|
|
||||||
|
self.button_menu = Button(
|
||||||
|
"[ESC] Back to Menu",
|
||||||
|
500,
|
||||||
|
70,
|
||||||
|
230,
|
||||||
|
530,
|
||||||
|
self.button_color,
|
||||||
|
self.button_hover_color
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# get events
|
||||||
|
events = pygame.event.get()
|
||||||
|
|
||||||
|
for event in events:
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
return "quit"
|
||||||
|
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_RETURN:
|
||||||
|
return "game"
|
||||||
|
|
||||||
|
if event.key == pygame.K_ESCAPE:
|
||||||
|
return "startscreen"
|
||||||
|
|
||||||
|
# draw background
|
||||||
|
self.screen.fill(self.background_color)
|
||||||
|
|
||||||
|
# create texts depending on win/lose
|
||||||
|
if self.won:
|
||||||
|
title_text = "EXAM PASSED!"
|
||||||
|
title_color = self.win_color
|
||||||
|
message_lines = [
|
||||||
|
"Congratulations, student.",
|
||||||
|
"You survived the night shift at FH Kapfenberg.",
|
||||||
|
"Your ECTS have ben successfully submitted."
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
title_text = "EXMATRICULATED!"
|
||||||
|
title_color = self.lose_color
|
||||||
|
message_lines = [
|
||||||
|
"The lecturers found you.",
|
||||||
|
"Your assignment was not submitted in time.",
|
||||||
|
"Please retake the semester."
|
||||||
|
]
|
||||||
|
|
||||||
|
# draw title/texts
|
||||||
|
title = self.font_title.render(title_text, True, title_color)
|
||||||
|
title_rect = title.get_rect(center=(480, 90))
|
||||||
|
self.screen.blit(title, title_rect)
|
||||||
|
|
||||||
|
y = 160
|
||||||
|
for line in message_lines:
|
||||||
|
message = self.font_small.render(line, True, self.text_color)
|
||||||
|
message_rect = message.get_rect(center=(480, y))
|
||||||
|
self.screen.blit(message, message_rect)
|
||||||
|
y += 32
|
||||||
|
|
||||||
|
# draw results
|
||||||
|
name_text = self.font_label.render(f"Student: {self.player_name}", True, self.text_color)
|
||||||
|
score_text = self.font_label.render(f"ECTS collected: {self.score_ects}", True, self.text_color)
|
||||||
|
time_text = self.font_label.render(f"Time survived: {self.time_survived}", True, self.text_color)
|
||||||
|
|
||||||
|
self.screen.blit(name_text, (280, 290))
|
||||||
|
self.screen.blit(score_text, (280, 330))
|
||||||
|
self.screen.blit(time_text, (280, 370))
|
||||||
|
|
||||||
|
# draw buttons
|
||||||
|
restart_pressed = self.button_restart.draw(self.screen)
|
||||||
|
menu_pressed = self.button_menu.draw(self.screen)
|
||||||
|
|
||||||
|
# check button click events
|
||||||
|
if restart_pressed:
|
||||||
|
return "game"
|
||||||
|
if menu_pressed:
|
||||||
|
return "startscreen"
|
||||||
|
|
||||||
|
return "endscreen"
|
||||||
@@ -54,6 +54,12 @@ COLOR_STARTSCREEN_BACKGROUND = ((0, 0, 0))
|
|||||||
COLOR_STARTSCREEN_FONT_TITLE = (0, 255, 0)
|
COLOR_STARTSCREEN_FONT_TITLE = (0, 255, 0)
|
||||||
COLOR_STARTSCREEN_FONT_LABEL = (0, 255, 255)
|
COLOR_STARTSCREEN_FONT_LABEL = (0, 255, 255)
|
||||||
|
|
||||||
|
# --- ENDSCREEN ---
|
||||||
|
COLOR_ENDSCREEN_BACKGROUND = ((0, 0, 0))
|
||||||
|
COLOR_ENDSCREEN_TEXT = (255, 255, 255)
|
||||||
|
COLOR_ENDSCREEN_WIN = (0, 255, 0)
|
||||||
|
COLOR_ENDSCREEN_LOSE = (255, 0, 0)
|
||||||
|
FONT_ENDSCREEN = "Arial"
|
||||||
|
|
||||||
# --- COFFEE ---
|
# --- COFFEE ---
|
||||||
COFFEE_COST = 30
|
COFFEE_COST = 30
|
||||||
|
|||||||
Reference in New Issue
Block a user