Correct background scaling

main
Skyball2000 2023-03-29 14:14:45 +02:00
parent 1897b4be04
commit f94f33d1bb
3 changed files with 25 additions and 12 deletions

View File

@ -16,5 +16,5 @@ class GoalDoorReceiverLevelElement(ReceiverLevelElement):
def set_active(self, active: bool): def set_active(self, active: bool):
super().set_active(active) super().set_active(active)
self.set_animation_state('open' if self.active_state else 'close') self.set_animation_state('open' if self.active_state else 'close')
self.is_collider = not self.active_state self.is_collider = False
self.register_collisions = self.is_collider self.register_collisions = not self.active_state

View File

@ -1,3 +1,5 @@
from typing import Optional
from level.Level import Level from level.Level import Level
from level.LevelManager import LevelManager from level.LevelManager import LevelManager
from level.selection.ScreenManager import ScreenManager from level.selection.ScreenManager import ScreenManager
@ -22,6 +24,7 @@ class LevelSelectionScreenManager(ScreenManager):
self.themes = ['tutorial', 'cave', 'castle'] self.themes = ['tutorial', 'cave', 'castle']
self.level_labels: list[TextLabel] = [] self.level_labels: list[TextLabel] = []
self.theme_label: Optional[TextLabel] = None
self.selected_theme = self.themes[0] self.selected_theme = self.themes[0]
@ -54,6 +57,10 @@ class LevelSelectionScreenManager(ScreenManager):
arrow_right.add_click_listener(self.select_next_theme) arrow_right.add_click_listener(self.select_next_theme)
self.add_element(DrawLayers.UI, arrow_right) 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): 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)
label.position_scale.scale = (0.5, 0.5) label.position_scale.scale = (0.5, 0.5)
@ -64,6 +71,7 @@ class LevelSelectionScreenManager(ScreenManager):
def select_theme(self, theme: str): def select_theme(self, theme: str):
self.selected_theme = theme self.selected_theme = theme
self.theme_label.set_text(theme)
for label in self.level_labels: for label in self.level_labels:
label.set_text('') label.set_text('')

View File

@ -16,16 +16,16 @@ from sprite.SpritesheetManager import SpritesheetManager
from ui_elements.ClickEvent import ClickEvent from ui_elements.ClickEvent import ClickEvent
from ui_elements.KeyManager import KeyManager from ui_elements.KeyManager import KeyManager
DEPRECATED_WIDTH = 12 * 71 * 1.5 BACKGROUND_IMAGES_UNSCALED = {
DEPRECATED_HEIGHT = 12 * 40 * 1.5 '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 = { BACKGROUND_IMAGES_SCALED = {
'tutorial': pygame.transform.scale(pygame.image.load('data/sprites/tutorial_bg.png'), 'tutorial': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['tutorial'], (1, 1)),
(DEPRECATED_WIDTH, DEPRECATED_HEIGHT)), 'castle': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['castle'], (1, 1)),
'castle': pygame.transform.scale(pygame.image.load('data/sprites/castle_bg.png'), 'cave': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['cave'], (1, 1)),
(DEPRECATED_WIDTH, DEPRECATED_HEIGHT)),
'cave': pygame.transform.scale(pygame.image.load('data/sprites/cave_bg.png'),
(DEPRECATED_WIDTH, DEPRECATED_HEIGHT)),
} }
@ -82,6 +82,11 @@ class MainLoop:
self.screen = pygame.display.set_mode((self.window_size[0], self.window_size[1])) 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): def select_level(self, level: Level):
print('Loading level', level.name) print('Loading level', level.name)
self.level = level self.level = level
@ -144,7 +149,7 @@ 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: 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) self.sprite_manager.draw(self.screen, self.screen_transform)
pygame.display.update() pygame.display.update()