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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#,#,>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#,#,>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,C,,,#
#,#,>,,,,,,,,,,,,,,,,,,,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,S,S,S,S,S,S,S,S,+,+,+,+,+,+,+,+,+,#
#,#,>,,,,,,,,,,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#
#,#,>,,,,,,,,,,,,,,,,,,,,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#,#,>,,,,,,,,,,,,,,,,,,,,,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#,#,,,,,,,,,,,,,,,,,,,,,,G,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#

1 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3 # # #
4 # # #
5 # # S > #
6 # # S > #
7 # # S > #
8 # # S > C #
9 # # S > + + + + + + + + + + + + + + + + + + + + + S S S S S S S S + + + + + + + + + #
10 # # S > # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
11 # # S > # #
12 # # S > # #
13 # # G #
14 # #
15 # #

View File

@ -3,6 +3,7 @@ from typing import Optional
from level.Level import Level
from level.elements.dynamic.BouncingBallLevelElement import BouncingBallLevelElement
from level.elements.dynamic.PushableBoxLevelElement import PushableBoxLevelElement
from level.elements.static.SpikeLevelElement import SpikeLevelElement
from level.elements.static.ButtonInputLevelElement import ButtonInputLevelElement
from level.elements.static.GateReceiverLevelElement import GateReceiverLevelElement
from level.elements.LevelElement import LevelElement
@ -29,6 +30,11 @@ TILES = {
'M': PushableBoxLevelElement,
'q': BouncingBallLevelElement,
'S': SpikeLevelElement,
's': SpikeLevelElement,
'<': SpikeLevelElement,
'>': SpikeLevelElement
}

View File

@ -0,0 +1,23 @@
from level.Level import Level
from level.elements.static.StaticLevelElement import StaticLevelElement
from physics.SpriteManager import SpriteManager
from sprite.SpritesheetManager import SpritesheetManager
BLOCK_TYPES = {
'S': 'small_spike_up',
's': 'small_spike_down',
'<': 'small_spike_left',
'>': 'small_spike_right'
}
class SpikeLevelElement(StaticLevelElement):
def __init__(self, tile: dict, loaded_level):
super().__init__(tile, loaded_level)
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('1')
self.position_scale.position = self.tile['position']

View File

@ -76,6 +76,7 @@ if what_to_run == 'menu':
global level_text_label
for level_text_label in level_menu.level_text_labels:
sprite_manager.remove_ui_element(level_text_label)
sprite_manager.remove_ui_element(level_menu.background)
level_menu.level_select_listener = lambda selected_level: load_next_level(selected_level)
@ -103,6 +104,7 @@ if what_to_run == 'menu':
destroy_menu()
else:
show_menu = True
sprite_manager.add_ui_element(DrawLayers.UI, level_menu.background)
for level_text_label in level_menu.level_text_labels:
sprite_manager.add_ui_element(DrawLayers.UI, level_text_label)

View File

@ -167,8 +167,7 @@ class PhysicsElementsHandler:
for collider in colliders:
if sprite is not collider:
distance = self.calculate_basic_distance(sprite, collider)
if distance > max(self.get_sprite_size_for_distance(sprite, screen_transform),
self.get_sprite_size_for_distance(collider, screen_transform)):
if distance > 50:
continue
if sprite.collides_with(collider, TOLERANCE):
collides_with.append(collider)

View File

@ -0,0 +1,31 @@
from typing import Optional
import pygame
from pygame import Surface
from physics.TickData import TickData
from sprite.BoundingBox import BoundingBox
from ui_elements.UiElement import UiElement
class Background(UiElement):
def __init__(self, x_pos: float, y_pos: float, width: float, height: float, color: tuple):
super().__init__()
self.x_pos = x_pos
self.y_pos = y_pos
self.width = width
self.height = height
self.color = color
def tick(self, tick_data: TickData):
pass
def render_sprite_image(self) -> Optional[Surface]:
surface = pygame.Surface((self.width, self.height), pygame.SRCALPHA)
background_rect = pygame.Rect(self.x_pos, self.y_pos, self.width, self.height)
pygame.draw.rect(surface, self.color, background_rect)
return surface
def get_bounding_box(self) -> BoundingBox:
return BoundingBox(-1, -1, 0, 0)

View File

@ -1,13 +1,15 @@
import pygame
from level.Level import Level
from ui_elements.Background import Background
from ui_elements.ClickEvent import ClickEvent
from ui_elements.TextLabel import TextLabel
class LevelMenu:
def __init__(self, levels: [Level], x_pos: int, y_pos: int, width: float, height: float, column_count: int):
def __init__(self, levels: [Level], x_pos: float, y_pos: float, width: float, height: float, column_count: int):
super().__init__()
self.levels = levels
self.x_pos = x_pos
self.y_pos = y_pos
@ -18,6 +20,7 @@ class LevelMenu:
self.column_count = column_count
self.create_level_text_labels()
self.background = Background(self.x_pos, self.y_pos, self.width, self.height, (100, 100, 100, 180))
def create_level_text_labels(self):
current_text_label_x = self.x_pos