Merge remote-tracking branch 'origin/main'

main
Jonas Wächter 2023-03-29 17:37:30 +02:00
commit cb5db15771
6 changed files with 42 additions and 7 deletions

View File

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

View File

@ -47,6 +47,12 @@ TILES = {
'i': InvisibleElement
}
BACK_LAYER = [
]
FRONT_LAYER = [
'M'
]
class LoadedLevel:
def __init__(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager):
@ -57,6 +63,26 @@ class LoadedLevel:
self.level_screen_manager = None
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 tile_number, tile in enumerate(row):
world_position = (tile_number, row_number)
@ -71,6 +97,10 @@ class LoadedLevel:
if name in TILES:
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':
ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character"))

View File

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

View File

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

View File

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

View File

@ -53,7 +53,6 @@ class PlayerSprite(DynamicSprite):
self.is_potentially_stuck = 0
if self.is_potentially_stuck == 2:
print('stuck')
self.position_scale.position = (self.position_scale.position[0] - 5, self.position_scale.position[1])
self.is_potentially_stuck = 0