diff --git a/project/data/sprites/ghost_character.png b/project/data/sprites/ghost_character.png index c7b2cb5..688f77b 100644 Binary files a/project/data/sprites/ghost_character.png and b/project/data/sprites/ghost_character.png differ diff --git a/project/level/elements/LoadedLevel.py b/project/level/elements/LoadedLevel.py index c51acf6..e548985 100644 --- a/project/level/elements/LoadedLevel.py +++ b/project/level/elements/LoadedLevel.py @@ -29,8 +29,10 @@ class LoadedLevel: def load_level(self, level: Level): for row_number, row in enumerate(level.tiles): for tile_number, tile in enumerate(row): + world_position = (tile_number, row_number) position = (tile_number * ConstantsParser.CONFIG.block_size[0], row_number * ConstantsParser.CONFIG.block_size[1]) + tile['world_position'] = world_position tile['position'] = position name = tile['name'] @@ -47,6 +49,28 @@ class LoadedLevel: self.sprite_manager.add_ui_element(DrawLayers.OBJECTS, element) element.load(self.sprite_manager, self.spritesheet_manager, level) + if isinstance(element, SimpleBlockLevelElement): + if self.is_surrounded_by_blocks(world_position, level.tiles): + element.is_collider = False + # self.sprite_manager.remove_ui_element(element) + + def is_surrounded_by_blocks(self, position, tiles): + for i in range(-1, 2): + for j in range(-1, 2): + + if i == 0 and j == 0: + continue + + if position[0] + i < 0 or position[0] + i >= len(tiles[0]): + continue + if position[1] + j < 0 or position[1] + j >= len(tiles): + continue + + tile = tiles[position[1] + j][position[0] + i] + if not tile['name'] in ['#', '+', '-', 'l', 'r', '~', '|']: + return False + return True + def destroy_level(self): for block in self.blocks: self.sprite_manager.remove_ui_element(block) diff --git a/project/physics/sprites/PlayerSprite.py b/project/physics/sprites/PlayerSprite.py index 4bbc6a4..b72da4e 100644 --- a/project/physics/sprites/PlayerSprite.py +++ b/project/physics/sprites/PlayerSprite.py @@ -3,13 +3,11 @@ from physics.TickData import TickData from sprite.DynamicSprite import DynamicSprite from sprite.Spritesheet import Spritesheet from ui_elements.KeyManager import KeyManager -from ui_elements.TextLabel import TextLabel class PlayerSprite(DynamicSprite): def __init__(self, spritesheet: Spritesheet): super().__init__(spritesheet) - self.cheat_fly = False self.jump_time = -1 self.allowed_jump_time = 12 @@ -33,17 +31,11 @@ class PlayerSprite(DynamicSprite): if self.motion[0] > -self.max_motion_horizontal_via_input: self.motion = (self.motion[0] - self.acceleration_horizontal, self.motion[1]) - if not self.cheat_fly: - if tick_data.key_manager.is_keymap_down(KeyManager.KEY_UP): - if self.jump_time < 0 and self.get_collides_with_direction(CollisionDirection.BOTTOM): - self.jump_time = self.allowed_jump_time - self.motion = (self.motion[0], self.motion[1] - 7) - if self.jump_time >= 0: - self.motion = (self.motion[0], self.motion[1] - 0.5) + if tick_data.key_manager.is_keymap_down(KeyManager.KEY_UP): + if self.jump_time < 0 and self.get_collides_with_direction(CollisionDirection.BOTTOM): + self.jump_time = self.allowed_jump_time + self.motion = (self.motion[0], self.motion[1] - 7) if self.jump_time >= 0: - self.jump_time -= 1 - else: - if tick_data.key_manager.is_keymap_down(KeyManager.KEY_UP): - self.motion = (self.motion[0], self.motion[1] - 2) - if tick_data.key_manager.is_keymap_down(KeyManager.KEY_DOWN): - self.motion = (self.motion[0], self.motion[1] + 2) + self.motion = (self.motion[0], self.motion[1] - 0.5) + if self.jump_time >= 0: + self.jump_time -= 1