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