Merge remote-tracking branch 'origin/main'
commit
3b5223da23
|
@ -141,7 +141,7 @@
|
|||
{
|
||||
"id": "off",
|
||||
"delays": [
|
||||
20
|
||||
30
|
||||
],
|
||||
"width": 48,
|
||||
"height": 36
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from abc import abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from level.Level import Level
|
||||
from physics.SpriteManager import SpriteManager
|
||||
|
@ -7,9 +8,10 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
|
||||
class LevelElement:
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
self.tile = tile
|
||||
self.loaded_level = loaded_level
|
||||
self.level_screen_manager: 'LevelScreenManager' = level_screen_manager
|
||||
|
||||
if 'id' in tile:
|
||||
self.id = tile['id']
|
||||
|
|
|
@ -52,6 +52,7 @@ class LoadedLevel:
|
|||
self.spritesheet_manager = spritesheet_manager
|
||||
self.blocks = []
|
||||
self.elements_by_id: dict[str, LevelElement] = {}
|
||||
self.level_screen_manager = None
|
||||
|
||||
def load_level(self, level: Level):
|
||||
for row_number, row in enumerate(level.tiles):
|
||||
|
@ -67,7 +68,7 @@ class LoadedLevel:
|
|||
layer = DrawLayers.OBJECTS
|
||||
|
||||
if name in TILES:
|
||||
element = TILES[name](tile, self)
|
||||
element = TILES[name](tile, self, self.level_screen_manager)
|
||||
|
||||
elif name == 'C':
|
||||
ghost_character = PlayerSprite(self.spritesheet_manager.get_sheet("ghost_character"))
|
||||
|
|
|
@ -5,8 +5,8 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
|
||||
class BouncingBallLevelElement(PushableLevelElement):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
self.bounce_factor = -1
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ from sprite.DynamicSprite import DynamicSprite
|
|||
|
||||
|
||||
class DynamicLevelElement(DynamicSprite, LevelElement, ABC):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
DynamicSprite.__init__(self)
|
||||
LevelElement.__init__(self, tile, loaded_level)
|
||||
LevelElement.__init__(self, tile, loaded_level, level_screen_manager)
|
||||
|
|
|
@ -5,8 +5,8 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
|
||||
class PushableBoxLevelElement(PushableLevelElement):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
if 'size' in self.tile:
|
||||
self.position_scale.scale = (float(self.tile['size']),
|
||||
|
|
|
@ -6,8 +6,8 @@ from physics.TickData import TickData
|
|||
|
||||
|
||||
class PushableLevelElement(DynamicLevelElement, ABC):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
if 'weight' in self.tile:
|
||||
self.weight = float(self.tile['weight'])
|
||||
|
|
|
@ -8,8 +8,8 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
class ButtonInputLevelElement(InputLevelElement):
|
||||
|
||||
def __init__(self, tile: dict, level: Level):
|
||||
super().__init__(tile, level)
|
||||
def __init__(self, tile: dict, level: Level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, level, level_screen_manager)
|
||||
self.is_currently_stood_on = False
|
||||
|
||||
self.is_collider = False
|
||||
|
|
|
@ -5,8 +5,8 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
|
||||
class GateReceiverLevelElement(ReceiverLevelElement):
|
||||
def __init__(self, tile: dict, level: Level):
|
||||
super().__init__(tile, level)
|
||||
def __init__(self, tile: dict, level: Level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, level, level_screen_manager)
|
||||
|
||||
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
|
||||
self.spritesheet = spritesheet_manager.get_sheet('gate')
|
||||
|
|
|
@ -5,8 +5,8 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
|
||||
class GoalDoorReceiverLevelElement(ReceiverLevelElement):
|
||||
def __init__(self, tile: dict, level: Level):
|
||||
super().__init__(tile, level)
|
||||
def __init__(self, tile: dict, level: Level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, level, level_screen_manager)
|
||||
|
||||
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
|
||||
self.spritesheet = spritesheet_manager.get_sheet('goal_door')
|
||||
|
|
|
@ -5,8 +5,8 @@ from level.elements.static.StaticLevelElement import StaticLevelElement
|
|||
|
||||
|
||||
class InputLevelElement(StaticLevelElement, ABC):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
if 'emitter_state' in tile:
|
||||
self.emitter_state = tile['emitter_state'] == 'true'
|
||||
|
|
|
@ -8,8 +8,8 @@ from sprite.SpritesheetManager import SpritesheetManager
|
|||
|
||||
class LeverInputLevelElement(InputLevelElement):
|
||||
|
||||
def __init__(self, tile: dict, level: Level):
|
||||
super().__init__(tile, level)
|
||||
def __init__(self, tile: dict, level: Level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, level, level_screen_manager)
|
||||
self.is_currently_stood_on = False
|
||||
|
||||
self.is_collider = False
|
||||
|
|
|
@ -5,8 +5,8 @@ from physics.TickData import TickData
|
|||
|
||||
|
||||
class ReceiverLevelElement(StaticLevelElement, ABC):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
self.requires = {
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ BLOCK_TYPES = {
|
|||
|
||||
|
||||
class SimpleBlockLevelElement(StaticLevelElement):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
|
||||
if self.tile['name'] in BLOCK_TYPES:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from level.Level import Level
|
||||
from level.elements.static.StaticLevelElement import StaticLevelElement
|
||||
from physics.SpriteManager import SpriteManager
|
||||
from physics.TickData import TickData
|
||||
from sprite.SpritesheetManager import SpritesheetManager
|
||||
|
||||
BLOCK_TYPES = {
|
||||
|
@ -12,8 +13,8 @@ BLOCK_TYPES = {
|
|||
|
||||
class SpikeLevelElement(StaticLevelElement):
|
||||
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
|
||||
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
|
||||
block_type = BLOCK_TYPES[self.tile['name']]
|
||||
|
@ -21,3 +22,9 @@ class SpikeLevelElement(StaticLevelElement):
|
|||
self.spritesheet = spritesheet_manager.get_sheet(block_type)
|
||||
self.set_animation_state('1')
|
||||
self.position_scale.position = self.tile['position']
|
||||
|
||||
def tick(self, tick_data: TickData):
|
||||
super().tick(tick_data)
|
||||
for collision in self.get_collides_with():
|
||||
if collision.secondary_sprite.id == 'player':
|
||||
self.level_screen_manager.player_death()
|
|
@ -5,6 +5,6 @@ from sprite.StaticSprite import StaticSprite
|
|||
|
||||
|
||||
class StaticLevelElement(StaticSprite, LevelElement, ABC):
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
StaticSprite.__init__(self)
|
||||
LevelElement.__init__(self, tile, loaded_level)
|
||||
LevelElement.__init__(self, tile, loaded_level, level_screen_manager)
|
||||
|
|
|
@ -3,19 +3,39 @@ from level.elements.static.StaticLevelElement import StaticLevelElement
|
|||
from physics.SpriteManager import SpriteManager
|
||||
from sprite.SpritesheetManager import SpritesheetManager
|
||||
|
||||
from project.physics.TickData import TickData
|
||||
|
||||
BLOCK_TYPES = {
|
||||
'A': 'staubsauger'
|
||||
}
|
||||
|
||||
|
||||
class VacuumCleanerElement(StaticLevelElement):
|
||||
|
||||
def __init__(self, tile: dict, loaded_level):
|
||||
super().__init__(tile, loaded_level)
|
||||
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
||||
super().__init__(tile, loaded_level, level_screen_manager)
|
||||
self.animation_state_counter = 0
|
||||
self.danger = True
|
||||
self.danger_time = 30
|
||||
self.off_time = 50
|
||||
|
||||
def tick(self, tick_data: TickData):
|
||||
super().tick(tick_data)
|
||||
self.animation_state_counter += tick_data.dt
|
||||
if self.danger:
|
||||
if self.animation_state_counter >= self.danger_time:
|
||||
self.set_animation_state('off')
|
||||
self.animation_state_counter = 0
|
||||
self.danger = not self.danger
|
||||
else:
|
||||
if self.animation_state_counter >= self.off_time:
|
||||
self.set_animation_state('on')
|
||||
self.animation_state_counter = 0
|
||||
self.danger = not self.danger
|
||||
|
||||
def load(self, sprite_manager: SpriteManager, spritesheet_manager: SpritesheetManager, level: Level):
|
||||
block_type = BLOCK_TYPES[self.tile['name']]
|
||||
|
||||
self.spritesheet = spritesheet_manager.get_sheet(block_type)
|
||||
|
||||
self.set_animation_state('on')
|
||||
|
||||
self.position_scale.position = self.tile['position']
|
|
@ -16,6 +16,7 @@ class LevelScreenManager(ScreenManager):
|
|||
|
||||
self.level = level
|
||||
self.loaded_level = LoadedLevel(sprite_manager, spritesheet_manager)
|
||||
self.loaded_level.level_screen_manager = self
|
||||
self.loaded_level.load_level(self.level)
|
||||
|
||||
def initialize(self):
|
||||
|
@ -28,3 +29,6 @@ class LevelScreenManager(ScreenManager):
|
|||
def tick(self, tick_data: TickData):
|
||||
if tick_data.key_manager.is_keymap_down(KeyManager.KEY_ESCAPE):
|
||||
self.main_loop.select_level_selection(self.level.theme)
|
||||
|
||||
def player_death(self):
|
||||
self.main_loop.player_death(self.level)
|
||||
|
|
|
@ -98,6 +98,9 @@ class MainLoop:
|
|||
if self.screen_manager is not None and isinstance(self.screen_manager, LevelSelectionScreenManager):
|
||||
self.screen_manager.select_theme(theme)
|
||||
|
||||
def player_death(self, level: Level):
|
||||
self.select_level(level)
|
||||
|
||||
def select_main_menu(self):
|
||||
self.set_game_state(self.GAME_STATE_MENU)
|
||||
|
||||
|
|
Loading…
Reference in New Issue