From f94f33d1bb212419ffa709327d20150f5c6ef331 Mon Sep 17 00:00:00 2001 From: Skyball2000 Date: Wed, 29 Mar 2023 14:14:45 +0200 Subject: [PATCH] Correct background scaling --- .../static/GoalDoorReceiverLevelElement.py | 4 +-- .../selection/LevelSelectionScreenManager.py | 8 ++++++ project/main.py | 25 +++++++++++-------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/project/level/elements/static/GoalDoorReceiverLevelElement.py b/project/level/elements/static/GoalDoorReceiverLevelElement.py index 738e605..6068013 100644 --- a/project/level/elements/static/GoalDoorReceiverLevelElement.py +++ b/project/level/elements/static/GoalDoorReceiverLevelElement.py @@ -16,5 +16,5 @@ class GoalDoorReceiverLevelElement(ReceiverLevelElement): def set_active(self, active: bool): super().set_active(active) self.set_animation_state('open' if self.active_state else 'close') - self.is_collider = not self.active_state - self.register_collisions = self.is_collider + self.is_collider = False + self.register_collisions = not self.active_state diff --git a/project/level/selection/LevelSelectionScreenManager.py b/project/level/selection/LevelSelectionScreenManager.py index 9f966b7..c36c520 100644 --- a/project/level/selection/LevelSelectionScreenManager.py +++ b/project/level/selection/LevelSelectionScreenManager.py @@ -1,3 +1,5 @@ +from typing import Optional + from level.Level import Level from level.LevelManager import LevelManager from level.selection.ScreenManager import ScreenManager @@ -22,6 +24,7 @@ class LevelSelectionScreenManager(ScreenManager): self.themes = ['tutorial', 'cave', 'castle'] self.level_labels: list[TextLabel] = [] + self.theme_label: Optional[TextLabel] = None self.selected_theme = self.themes[0] @@ -54,6 +57,10 @@ class LevelSelectionScreenManager(ScreenManager): arrow_right.add_click_listener(self.select_next_theme) self.add_element(DrawLayers.UI, arrow_right) + self.theme_label = TextLabel('', OFFSET[0] + 120, OFFSET[1] - 2, font_size=65) + self.theme_label.position_scale.scale = (0.5, 0.5) + self.add_element(DrawLayers.UI, self.theme_label) + for i in range(0, LABEL_COUNT): label = TextLabel(str(i), OFFSET[0] + 30, OFFSET[1] + 60 + i * 50, font_size=65) label.position_scale.scale = (0.5, 0.5) @@ -64,6 +71,7 @@ class LevelSelectionScreenManager(ScreenManager): def select_theme(self, theme: str): self.selected_theme = theme + self.theme_label.set_text(theme) for label in self.level_labels: label.set_text('') diff --git a/project/main.py b/project/main.py index 76d3839..2b37fc9 100644 --- a/project/main.py +++ b/project/main.py @@ -16,16 +16,16 @@ from sprite.SpritesheetManager import SpritesheetManager from ui_elements.ClickEvent import ClickEvent from ui_elements.KeyManager import KeyManager -DEPRECATED_WIDTH = 12 * 71 * 1.5 -DEPRECATED_HEIGHT = 12 * 40 * 1.5 +BACKGROUND_IMAGES_UNSCALED = { + 'tutorial': pygame.image.load('data/sprites/tutorial_bg.png'), + 'castle': pygame.image.load('data/sprites/castle_bg.png'), + 'cave': pygame.image.load('data/sprites/cave_bg.png'), +} -BACKGROUND_IMAGES = { - 'tutorial': pygame.transform.scale(pygame.image.load('data/sprites/tutorial_bg.png'), - (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), - 'castle': pygame.transform.scale(pygame.image.load('data/sprites/castle_bg.png'), - (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), - 'cave': pygame.transform.scale(pygame.image.load('data/sprites/cave_bg.png'), - (DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), +BACKGROUND_IMAGES_SCALED = { + 'tutorial': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['tutorial'], (1, 1)), + 'castle': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['castle'], (1, 1)), + 'cave': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['cave'], (1, 1)), } @@ -82,6 +82,11 @@ class MainLoop: self.screen = pygame.display.set_mode((self.window_size[0], self.window_size[1])) + for key in BACKGROUND_IMAGES_UNSCALED: + BACKGROUND_IMAGES_SCALED[key] = pygame.transform.scale( + BACKGROUND_IMAGES_UNSCALED[key], self.window_size + ) + def select_level(self, level: Level): print('Loading level', level.name) self.level = level @@ -144,7 +149,7 @@ class MainLoop: self.screen_manager.tick(tick_data) self.sprite_manager.tick(tick_data) if self.level is not None: - self.screen.blit(BACKGROUND_IMAGES[self.level.theme], (0, 0)) + self.screen.blit(BACKGROUND_IMAGES_SCALED[self.level.theme], (0, 0)) self.sprite_manager.draw(self.screen, self.screen_transform) pygame.display.update()