Merge remote-tracking branch 'origin/main'

main
Thomas 2023-03-29 17:48:02 +02:00
commit 2a8cb66eda
11 changed files with 64 additions and 10 deletions

View File

@ -7,7 +7,7 @@
"file": "playground.csv" "file": "playground.csv"
}, },
{ {
"name": "0-tutorial", "name": "tutorial",
"theme": "tutorial", "theme": "tutorial",
"abilities": [ "abilities": [
], ],

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -47,6 +47,12 @@ TILES = {
'i': InvisibleElement 'i': InvisibleElement
} }
BACK_LAYER = [
]
FRONT_LAYER = [
'M'
]
class LoadedLevel: class LoadedLevel:
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager): def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager):
@ -57,6 +63,26 @@ class LoadedLevel:
self.level_screen_manager = None self.level_screen_manager = None
def load_level(self, level: Level): def load_level(self, level: Level):
# create a wall of InvisibleElement around the level left and right
# block_left = SimpleBlockLevelElement({'name': '#', 'position': (30, 300)}, self, self.level_screen_manager)
# block_left.load(self.sprite_manager, self.spritesheet_manager, level)
# self.blocks.append(block_left)
# self.sprite_manager.add_ui_element(DrawLayers.OBJECTS_BACK, block_left)
for i in range(0, 100):
block_left = InvisibleElement({'name': 'i', 'position': (-16, i * 32)}, self, self.level_screen_manager)
block_left.load(self.sprite_manager, self.spritesheet_manager, level)
self.blocks.append(block_left)
self.sprite_manager.add_ui_element(DrawLayers.OBJECTS_BACK, block_left)
for i in range(0, 100):
block_right = InvisibleElement({'name': 'i', 'position':
(ConstantsParser.CONFIG.block_size[0] * ConstantsParser.CONFIG.level_size[0] + 4, i * 32)},
self, self.level_screen_manager)
block_right.load(self.sprite_manager, self.spritesheet_manager, level)
self.blocks.append(block_right)
self.sprite_manager.add_ui_element(DrawLayers.OBJECTS_BACK, block_right)
for row_number, row in enumerate(level.tiles): for row_number, row in enumerate(level.tiles):
for tile_number, tile in enumerate(row): for tile_number, tile in enumerate(row):
world_position = (tile_number, row_number) world_position = (tile_number, row_number)
@ -71,6 +97,10 @@ class LoadedLevel:
if name in TILES: if name in TILES:
element = TILES[name](tile, self, self.level_screen_manager) element = TILES[name](tile, self, self.level_screen_manager)
if name in BACK_LAYER:
layer = DrawLayers.OBJECTS_BACK
elif name in FRONT_LAYER:
layer = DrawLayers.OBJECTS_FRONT
elif name == 'C': elif name == 'C':
ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character")) ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character"))
@ -81,7 +111,7 @@ class LoadedLevel:
elif not name == '': elif not name == '':
print(f"Unknown tile at {position}: {name}") print(f"Unknown tile at {position}: {name}")
element = UnknownTileLevelElement(tile, self, self.level_screen_manager) element = UnknownTileLevelElement(tile, self , self.level_screen_manager)
if element: if element:
self.blocks.append(element) self.blocks.append(element)

View File

@ -5,10 +5,11 @@ import pygame.time
from level.Level import Level from level.Level import Level
from level.elements.LoadedLevel import LoadedLevel from level.elements.LoadedLevel import LoadedLevel
from level.selection.ScreenManager import ScreenManager from level.selection.ScreenManager import ScreenManager
from physics.SpriteManager import SpriteManager 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.KeyManager import KeyManager from ui_elements.KeyManager import KeyManager
from ui_elements.TextLabel import TextLabel
class LevelScreenManager(ScreenManager): class LevelScreenManager(ScreenManager):
@ -21,6 +22,11 @@ class LevelScreenManager(ScreenManager):
self.loaded_level.level_screen_manager = self self.loaded_level.level_screen_manager = self
self.loaded_level.load_level(self.level) self.loaded_level.load_level(self.level)
self.back_button = TextLabel('BACK [ESC]', 635, 460, 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.back_to_level_selection())
def initialize(self): def initialize(self):
pass pass
@ -30,8 +36,11 @@ class LevelScreenManager(ScreenManager):
def tick(self, tick_data: TickData): def tick(self, tick_data: TickData):
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE): if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
self.back_to_level_selection()
pygame.time.delay(250)
def back_to_level_selection(self):
self.main_loop.select_level_selection(self.level.theme) self.main_loop.select_level_selection(self.level.theme)
pygame.time.delay(200)
def player_death(self): def player_death(self):
self.main_loop.player_death(self.level) self.main_loop.player_death(self.level)

View File

@ -64,6 +64,11 @@ class LevelSelectionScreenManager(ScreenManager):
self.theme_label.position_scale.scale = (0.5, 0.5) self.theme_label.position_scale.scale = (0.5, 0.5)
self.add_element(DrawLayers.UI, self.theme_label) self.add_element(DrawLayers.UI, self.theme_label)
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.main_loop.select_main_menu())
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)

View File

@ -25,8 +25,8 @@ class MainMenuScreenManager(ScreenManager):
def initialize(self): def initialize(self):
size = CoordinateTransform.transform_screen_to_world(self.main_loop.window_size, self.main_loop.screen_transform) 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, 70) self.create_button("START", size[0] * 0.495, size[1] * 0.772, 38)
self.create_button("SCREEN SIZE", size[0] * 0.5, size[1] * 0.7, 40) self.create_button("SCREEN SIZE", size[0] * 0.85, size[1] * 0.9, 20)
def create_button(self, name: str, x_position, y_position, font_size): def create_button(self, name: str, x_position, y_position, font_size):
label = TextLabel(name, x_position, y_position, font_size, alignment="center") label = TextLabel(name, x_position, y_position, font_size, alignment="center")

View File

@ -18,6 +18,11 @@ class OptionsScreenManager(ScreenManager):
label.position_scale.scale = (1, 1) label.position_scale.scale = (1, 1)
self.create_button(name, label) self.create_button(name, label)
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.main_loop.select_main_menu())
def create_button(self, name: str, label: TextLabel): def create_button(self, name: str, label: TextLabel):
if name == "SMALL": if name == "SMALL":
label.add_click_listener(lambda click: self.make_small_screen(click)) label.add_click_listener(lambda click: self.make_small_screen(click))

View File

@ -22,12 +22,14 @@ BACKGROUND_IMAGES_UNSCALED = {
'tutorial': pygame.image.load('data/sprites/tutorial_bg.png'), 'tutorial': pygame.image.load('data/sprites/tutorial_bg.png'),
'castle': pygame.image.load('data/sprites/castle_bg.png'), 'castle': pygame.image.load('data/sprites/castle_bg.png'),
'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'),
} }
BACKGROUND_IMAGES_SCALED = { BACKGROUND_IMAGES_SCALED = {
'tutorial': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['tutorial'], (1, 1)), 'tutorial': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['tutorial'], (1, 1)),
'castle': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['castle'], (1, 1)), 'castle': pygame.transform.scale(BACKGROUND_IMAGES_UNSCALED['castle'], (1, 1)),
'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)),
} }
@ -53,7 +55,7 @@ class MainLoop:
self.window_size: tuple[float, float] = (1, 1) self.window_size: tuple[float, float] = (1, 1)
pygame.init() pygame.init()
pygame.display.set_caption("PM GAME") pygame.display.set_caption("Don't Get Busted")
self.update_position_scale(self.screen_transform) self.update_position_scale(self.screen_transform)
@ -176,6 +178,8 @@ class MainLoop:
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:
self.screen.blit(BACKGROUND_IMAGES_SCALED['menu'], (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

@ -12,11 +12,13 @@ from ui_elements.UiElement import UiElement
class DrawLayers: class DrawLayers:
BACKGROUND = 'background' BACKGROUND = 'background'
LEVEL = 'level' LEVEL = 'level'
OBJECTS_BACK = 'objects_back'
OBJECTS = 'objects' OBJECTS = 'objects'
OBJECTS_FRONT = 'objects_front'
PLAYER = 'player' PLAYER = 'player'
UI = 'ui' UI = 'ui'
DRAW_ORDER = [BACKGROUND, LEVEL, OBJECTS, PLAYER, UI] DRAW_ORDER = [BACKGROUND, LEVEL, OBJECTS_BACK, OBJECTS, OBJECTS_FRONT, PLAYER, UI]
class SpriteManager: class SpriteManager:

View File

@ -53,7 +53,6 @@ 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:
print('stuck')
self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1]) self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1])
self.is_potentially_stuck = 0 self.is_potentially_stuck = 0