Implement different screen size settings

main
Fabian Hoppe 2023-03-29 15:59:51 +02:00
parent 3b5223da23
commit 14475314f5
3 changed files with 67 additions and 6 deletions

View File

@ -19,21 +19,22 @@ class MainMenuScreenManager(ScreenManager):
self.main_loop.select_level_selection()
def go_to_options_screen(self, click):
self.destroy()
if click.is_click_down(ClickEvent.CLICK_LEFT):
self.main_loop.select_options()
def initialize(self):
size = CoordinateTransform.transform_screen_to_world(self.main_loop.window_size, self.main_loop.screen_transform)
self.create_button("START", size[0] * 0.5, size[1] * 0.5)
self.create_button("OPTIONS", size[0] * 0.5, size[1] * 0.65)
self.create_button("START", size[0] * 0.5, size[1] * 0.5, 70)
self.create_button("SCREEN SIZE", size[0] * 0.5, size[1] * 0.7, 40)
def create_button(self, name: str, x_position, y_position):
label = TextLabel(name, x_position, y_position, font_size=70, alignment="center")
def create_button(self, name: str, x_position, y_position, font_size):
label = TextLabel(name, x_position, y_position, font_size, alignment="center")
self.add_element(DrawLayers.UI, label)
label.position_scale.scale = (1, 1)
if name == "START":
label.add_click_listener(lambda click: self.go_to_menu(click))
elif name == "OPTIONS":
elif name == "SCREEN SIZE":
label.add_click_listener(lambda click: self.go_to_options_screen(click))
def destroy(self):

View File

@ -0,0 +1,51 @@
from level.selection.ScreenManager import ScreenManager
from physics.SpriteManager import DrawLayers, SpriteManager
from physics.TickData import TickData
from sprite.PositionScale import PositionScale
from sprite.SpritesheetManager import SpritesheetManager
from ui_elements import CoordinateTransform
from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel
class OptionsScreenManager(ScreenManager):
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, main_loop):
super().__init__(sprite_manager, spritesheet_manager, main_loop)
def create_label(self, name: str, x_position, y_position, font_size):
label = TextLabel(name, x_position, y_position, font_size, alignment="left")
self.add_element(DrawLayers.UI, label)
label.position_scale.scale = (1, 1)
self.create_button(name, label)
def create_button(self, name: str, label: TextLabel):
if name == "SMALL":
label.add_click_listener(lambda click: self.make_small_screen(click))
elif name == "MEDIUM":
label.add_click_listener(lambda click: self.make_medium_screen(click))
elif name == "LARGE":
label.add_click_listener(lambda click: self.make_large_screen(click))
def make_small_screen(self, click):
self.main_loop.update_position_scale(PositionScale((0, 0), (1, 1)))
def make_medium_screen(self, click):
self.main_loop.update_position_scale(PositionScale((0, 0), (1.25, 1.25)))
def make_large_screen(self, click):
self.main_loop.update_position_scale(PositionScale((0, 0), (1.5, 1.5)))
def initialize(self):
size = CoordinateTransform.transform_screen_to_world(self.main_loop.window_size,
self.main_loop.screen_transform)
self.create_label("SCREEN SIZE", size[0] * 0.2, size[1] * 0.2, font_size=70)
self.create_label("SMALL", size[0] * 0.15, size[1] * 0.6, font_size=30)
self.create_label("MEDIUM", size[0] * 0.45, size[1] * 0.6, font_size=30)
self.create_label("LARGE", size[0] * 0.75, size[1] * 0.6, font_size=30)
def destroy(self):
super().destroy()
def tick(self, tick_data: TickData):
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
self.main_loop.select_main_menu()

View File

@ -8,6 +8,7 @@ from level.LevelManager import LevelManager
from level.selection.LevelScreenManager import LevelScreenManager
from level.selection.LevelSelectionScreenManager import LevelSelectionScreenManager
from level.selection.MainMenuScreenManager import MainMenuScreenManager
from level.selection.OptionsScreenManager import OptionsScreenManager
from level.selection.ScreenManager import ScreenManager
from physics import ConstantsParser
from physics.SpriteManager import SpriteManager
@ -46,6 +47,7 @@ class MainLoop:
self.GAME_STATE_MENU = 'main_menu'
self.GAME_STATE_LEVEL_SELECTION = 'level_selection'
self.GAME_STATE_LEVEL = 'level'
self.GAME_STATE_OPTIONS = 'options'
self.screen_transform: PositionScale = PositionScale((0, 0), (1.5, 1.5))
self.window_size: tuple[float, float] = (1, 1)
@ -104,6 +106,9 @@ class MainLoop:
def select_main_menu(self):
self.set_game_state(self.GAME_STATE_MENU)
def select_options(self):
self.set_game_state(self.GAME_STATE_OPTIONS)
def set_game_state(self, game_state: str):
self.game_state = game_state
@ -122,6 +127,10 @@ class MainLoop:
self.screen_manager = LevelSelectionScreenManager(
self.sprite_manager, self.spritesheet_manager, self, self.parsed_levels_manager
)
elif self.game_state == self.GAME_STATE_OPTIONS:
self.screen_manager = OptionsScreenManager(
self.sprite_manager, self.spritesheet_manager, self,
)
else:
print('Invalid game state', self.game_state)