Merge remote-tracking branch 'origin/main'

main
Stephan Halder 2023-03-29 23:14:59 +02:00
commit f79c1f6c9d
5 changed files with 14 additions and 9 deletions

View File

@ -11,6 +11,7 @@ BLOCK_TYPES = {
'>': 'small_spike_right'
}
class SpikeLevelElement(StaticLevelElement):
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
@ -22,9 +23,11 @@ class SpikeLevelElement(StaticLevelElement):
self.spritesheet = spritesheet_manager.get_sheet(block_type)
self.set_animation_state('1')
self.position_scale.position = self.tile['position']
self.bounding_box_margin = (-5, -5)
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()
# print('You dies in ze spikes')
self.level_screen_manager.player_death()

View File

@ -29,6 +29,7 @@ class MainMenuScreenManager(ScreenManager):
def create_button(self, name: str, x_position, y_position, font_size):
label = TextLabel(name, x_position, y_position, font_size, alignment="center")
label.bounding_box_margin = (10, 18)
self.add_element(DrawLayers.UI, label)
label.position_scale.scale = (1, 1)
if name == "START":

View File

@ -99,10 +99,10 @@ class Sprite(UiElement):
if self.bounding_box.x != self.position_scale.position[0] or \
self.bounding_box.y != self.position_scale.position[1]:
self.bounding_box = BoundingBox(
self.position_scale.position[0],
self.position_scale.position[1],
self.image.get_width() * self.position_scale.scale[0],
self.image.get_height() * self.position_scale.scale[1]
self.position_scale.position[0] - self.bounding_box_margin[0],
self.position_scale.position[1] - self.bounding_box_margin[1],
self.image.get_width() * self.position_scale.scale[0] + self.bounding_box_margin[0] * 2,
self.image.get_height() * self.position_scale.scale[1] + self.bounding_box_margin[1] * 2
)
return self.bounding_box

View File

@ -49,8 +49,8 @@ class TextLabel(UiElement):
def get_bounding_box(self) -> BoundingBox:
return BoundingBox(
self.position_scale.position[0],
self.position_scale.position[1],
self.current_width * self.position_scale.scale[0],
self.current_height * self.position_scale.scale[1]
self.position_scale.position[0] - self.bounding_box_margin[0],
self.position_scale.position[1] - self.bounding_box_margin[1],
self.current_width * self.position_scale.scale[0] + self.bounding_box_margin[0] * 2,
self.current_height * self.position_scale.scale[1] + self.bounding_box_margin[1] * 2
)

View File

@ -18,6 +18,7 @@ class UiElement:
self.click_listeners = []
self.bounding_box = BoundingBox(0, 0, 0, 0)
self.bounding_box_margin = (0, 0)
self.uuid = uuid.uuid4()