Win screen

main
Skyball2000 2023-03-29 18:07:52 +02:00
parent bce183062c
commit 4009e784cb
7 changed files with 53 additions and 60 deletions

View File

@ -1,53 +0,0 @@
import pygame
from level.Level import Level
from ui_elements.ColoredRectangleUiElement import ColoredRectangleUiElement
from ui_elements.ClickEvent import ClickEvent
from ui_elements.TextLabel import TextLabel
class LevelMenu:
def __init__(self, levels: [Level], x_pos: float, y_pos: float, width: float, height: float, column_count: int):
super().__init__()
self.levels = levels
self.level_select_listener = lambda selected_level: None
self.level_text_labels = []
self.width = width
self.height = height
self.column_count = column_count
self.position = (x_pos, y_pos)
self.create_level_text_labels()
self.background = ColoredRectangleUiElement(self.width, self.height, (100, 100, 100, 180))
self.background.position_scale.position = self.position
def create_level_text_labels(self):
current_text_label_position = [self.position[0], self.position[1]]
for index, level in enumerate(self.levels):
text_label = TextLabel(level.name,
current_text_label_position[0],
current_text_label_position[1],
60)
text_label.position_scale.scale = (0.5, 0.5)
text_label.add_click_listener(
lambda click_event, selected_level=level:
self.handle_level_text_label_click(click_event, selected_level)
)
self.level_text_labels.append(text_label)
if (index + 1) % self.column_count == 0:
current_text_label_position[0] = self.position[0]
current_text_label_position[1] += self.height / (len(self.levels) / self.column_count)
else:
current_text_label_position[0] += self.width / self.column_count
def handle_level_text_label_click(self, click_event: ClickEvent, level: Level):
if click_event.event.type == pygame.MOUSEBUTTONUP:
self.level_select_listener(level)
def extract_level(self):
return self

View File

@ -47,6 +47,10 @@ class LevelSelectionScreenManager(ScreenManager):
if click.is_click_down(ClickEvent.CLICK_LEFT): if click.is_click_down(ClickEvent.CLICK_LEFT):
self.main_loop.select_level(level) self.main_loop.select_level(level)
def go_to_menu(self, click):
if click.is_click_down(ClickEvent.CLICK_LEFT):
self.main_loop.select_main_menu()
def initialize(self): def initialize(self):
arrow_left = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow')) arrow_left = StaticSprite(self.spritesheet_manager.get_sheet('ui_arrow'))
arrow_left.set_animation_state('left') arrow_left.set_animation_state('left')
@ -67,7 +71,7 @@ class LevelSelectionScreenManager(ScreenManager):
self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30) self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30)
self.back_button.position_scale.scale = (0.5, 0.5) self.back_button.position_scale.scale = (0.5, 0.5)
self.add_element(DrawLayers.UI, self.back_button) self.add_element(DrawLayers.UI, self.back_button)
self.back_button.add_click_listener(lambda click: self.main_loop.select_main_menu()) self.back_button.add_click_listener(lambda click: self.go_to_menu(click))
for i in range(0, LABEL_COUNT): for i in range(0, LABEL_COUNT):
label = TextLabel(str(i), OFFSET[0] + 30, OFFSET[1] + 60 + i * 50, font_size=65) label = TextLabel(str(i), OFFSET[0] + 30, OFFSET[1] + 60 + i * 50, font_size=65)

View File

@ -5,7 +5,6 @@ from physics.SpriteManager import SpriteManager, DrawLayers
from physics.TickData import TickData from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager from sprite.SpritesheetManager import SpritesheetManager
from ui_elements import CoordinateTransform from ui_elements import CoordinateTransform
from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel from ui_elements.TextLabel import TextLabel
from ui_elements.ClickEvent import ClickEvent from ui_elements.ClickEvent import ClickEvent

View File

@ -4,6 +4,7 @@ from physics.TickData import TickData
from sprite.PositionScale import PositionScale from sprite.PositionScale import PositionScale
from sprite.SpritesheetManager import SpritesheetManager from sprite.SpritesheetManager import SpritesheetManager
from ui_elements import CoordinateTransform from ui_elements import CoordinateTransform
from ui_elements.ClickEvent import ClickEvent
from ui_elements.KeyManager import KeyManager from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel from ui_elements.TextLabel import TextLabel
@ -12,6 +13,10 @@ class OptionsScreenManager(ScreenManager):
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop): def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop):
super().__init__(sprite_manager, spritesheet_manager, main_loop) super().__init__(sprite_manager, spritesheet_manager, main_loop)
def go_to_menu(self, click):
if click.is_click_down(ClickEvent.CLICK_LEFT):
self.main_loop.select_main_menu()
def create_label(self, name: str, x_position, y_position, font_size): def create_label(self, name: str, x_position, y_position, font_size):
label = TextLabel(name, x_position, y_position, font_size, alignment="left") label = TextLabel(name, x_position, y_position, font_size, alignment="left")
self.add_element(DrawLayers.UI, label) self.add_element(DrawLayers.UI, label)
@ -21,7 +26,7 @@ class OptionsScreenManager(ScreenManager):
self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30) self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30)
self.back_button.position_scale.scale = (0.5, 0.5) self.back_button.position_scale.scale = (0.5, 0.5)
self.add_element(DrawLayers.UI, self.back_button) self.add_element(DrawLayers.UI, self.back_button)
self.back_button.add_click_listener(lambda click: self.main_loop.select_main_menu()) self.back_button.add_click_listener(lambda click: self.go_to_menu(click))
def create_button(self, name: str, label: TextLabel): def create_button(self, name: str, label: TextLabel):
if name == "SMALL": if name == "SMALL":

View File

@ -0,0 +1,27 @@
from abc import abstractmethod
from level.selection.ScreenManager import ScreenManager
from physics.SpriteManager import SpriteManager, DrawLayers
from physics.TickData import TickData
from sprite.SpritesheetManager import SpritesheetManager
from ui_elements import CoordinateTransform
from ui_elements.TextLabel import TextLabel
from ui_elements.ClickEvent import ClickEvent
class WinScreenManager(ScreenManager):
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop):
super().__init__(sprite_manager, spritesheet_manager, main_loop)
def go_to_menu(self, click):
if click.is_click_down(ClickEvent.CLICK_LEFT):
self.main_loop.select_level_selection()
def initialize(self):
self.back_button = TextLabel('BACK [ESC]', 610, 430, font_size=30)
self.back_button.position_scale.scale = (0.5, 0.5)
self.add_element(DrawLayers.UI, self.back_button)
self.back_button.add_click_listener(lambda click: self.go_to_menu(click))
def destroy(self):
super().destroy()

View File

@ -10,6 +10,7 @@ from level.selection.LevelSelectionScreenManager import LevelSelectionScreenMana
from level.selection.MainMenuScreenManager import MainMenuScreenManager from level.selection.MainMenuScreenManager import MainMenuScreenManager
from level.selection.OptionsScreenManager import OptionsScreenManager from level.selection.OptionsScreenManager import OptionsScreenManager
from level.selection.ScreenManager import ScreenManager from level.selection.ScreenManager import ScreenManager
from level.selection.WinScreenManager import WinScreenManager
from physics import ConstantsParser from physics import ConstantsParser
from physics.SpriteManager import SpriteManager from physics.SpriteManager import SpriteManager
from physics.TickData import TickData from physics.TickData import TickData
@ -24,6 +25,7 @@ BACKGROUND_IMAGES_UNSCALED = {
'cave': pygame.image.load('data/sprites/cave_bg.png'), 'cave': pygame.image.load('data/sprites/cave_bg.png'),
'menu': pygame.image.load('data/sprites/intro_bg.png'), 'menu': pygame.image.load('data/sprites/intro_bg.png'),
'level_select': pygame.image.load('data/sprites/level_select_bg.png'), 'level_select': pygame.image.load('data/sprites/level_select_bg.png'),
'win': pygame.image.load('data/sprites/win_bg.png'),
} }
BACKGROUND_IMAGES_SCALED = { BACKGROUND_IMAGES_SCALED = {
@ -32,6 +34,7 @@ BACKGROUND_IMAGES_SCALED = {
'cave': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['cave'], (1, 1)), 'cave': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['cave'], (1, 1)),
'menu': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['menu'], (1, 1)), 'menu': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['menu'], (1, 1)),
'level_select': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['level_select'], (1, 1)), 'level_select': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['level_select'], (1, 1)),
'win': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['win'], (1, 1)),
} }
@ -52,6 +55,7 @@ class MainLoop:
self.GAME_STATE_LEVEL_SELECTION = 'level_selection' self.GAME_STATE_LEVEL_SELECTION = 'level_selection'
self.GAME_STATE_LEVEL = 'level' self.GAME_STATE_LEVEL = 'level'
self.GAME_STATE_OPTIONS = 'options' self.GAME_STATE_OPTIONS = 'options'
self.GAME_STATE_WIN = 'win'
self.screen_transform: PositionScale = PositionScale((0, 0), (1.5, 1.5)) self.screen_transform: PositionScale = PositionScale((0, 0), (1.5, 1.5))
self.window_size: tuple[float, float] = (1, 1) self.window_size: tuple[float, float] = (1, 1)
@ -112,8 +116,7 @@ class MainLoop:
if next_level is not None: if next_level is not None:
self.select_level(next_level) self.select_level(next_level)
else: else:
print('WINNNNNN!!') self.set_game_state(self.GAME_STATE_WIN)
self.select_main_menu()
def select_main_menu(self): def select_main_menu(self):
self.set_game_state(self.GAME_STATE_MENU) self.set_game_state(self.GAME_STATE_MENU)
@ -143,6 +146,10 @@ class MainLoop:
self.screen_manager = OptionsScreenManager( self.screen_manager = OptionsScreenManager(
self.sprite_manager, self.spritesheet_manager, self, self.sprite_manager, self.spritesheet_manager, self,
) )
elif self.game_state == self.GAME_STATE_WIN:
self.screen_manager = WinScreenManager(
self.sprite_manager, self.spritesheet_manager, self,
)
else: else:
print('Invalid game state', self.game_state) print('Invalid game state', self.game_state)
@ -178,12 +185,16 @@ class MainLoop:
self.screen_manager.tick(tick_data) self.screen_manager.tick(tick_data)
self.sprite_manager.tick(tick_data) self.sprite_manager.tick(tick_data)
if self.level is not None and self.game_state == self.GAME_STATE_LEVEL: if self.level is not None and self.game_state == self.GAME_STATE_LEVEL:
self.screen.blit(BACKGROUND_IMAGES_SCALED[self.level.theme], (0, 0)) self.screen.blit(BACKGROUND_IMAGES_SCALED[self.level.theme], (0, 0))
elif self.game_state == self.GAME_STATE_MENU: elif self.game_state == self.GAME_STATE_MENU:
self.screen.blit(BACKGROUND_IMAGES_SCALED['menu'], (0, 0)) self.screen.blit(BACKGROUND_IMAGES_SCALED['menu'], (0, 0))
elif self.game_state == self.GAME_STATE_LEVEL_SELECTION: elif self.game_state == self.GAME_STATE_LEVEL_SELECTION or self.game_state == self.GAME_STATE_OPTIONS:
self.screen.blit(BACKGROUND_IMAGES_SCALED['level_select'], (0, 0)) self.screen.blit(BACKGROUND_IMAGES_SCALED['level_select'], (0, 0))
elif self.game_state == self.GAME_STATE_WIN:
self.screen.blit(BACKGROUND_IMAGES_SCALED['win'], (0, 0))
self.sprite_manager.draw(self.screen, self.screen_transform) self.sprite_manager.draw(self.screen, self.screen_transform)
pygame.display.update() pygame.display.update()

View File

@ -53,7 +53,7 @@ class PlayerSprite(DynamicSprite):
self.is_potentially_stuck = 0 self.is_potentially_stuck = 0
if self.is_potentially_stuck == 2: if self.is_potentially_stuck == 2:
self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1]) self.position_scale.position = (self.position_scale.position[0] - 2, self.position_scale.position[1] - 5)
self.is_potentially_stuck = 0 self.is_potentially_stuck = 0
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT): if tick_data.key_manager.is_keymap_down(KeyManager.KEY_RIGHT):