Interactions between elements in between layers

main
Yan Wittmann 2023-03-26 10:05:23 +02:00
parent 72fd82c5a6
commit e6d34fcbf2
4 changed files with 12 additions and 8 deletions

View File

@ -5,3 +5,4 @@ Links:
- [doc: Software design](https://docs.google.com/document/d/1GpieqcuPjXC1P-a0mXGLe61XF8xzZ_h2taeojuUqToA/edit#heading=h.a6o0m6lt88hs)
- [tab: Arbeitspakete](https://docs.google.com/spreadsheets/d/1zyScof0CLPPSmdI0Dq3QWAdLAvyMhk_QFo7VJDFPymk/edit#gid=0)
- [tab: Levels](https://docs.google.com/spreadsheets/d/1kIfnlJLYZ0p-zY8Jl699yGgnn6wju2nfAVBx9WdDkQI/edit#gid=741912808)
- [tab: Grafiken](https://docs.google.com/spreadsheets/d/1gT3khuVGXgm-Wk83aEAYn9wOUzQKluHDlfMs6SlZ8KU/edit)

View File

@ -58,10 +58,11 @@ elif what_to_run == 'physics':
test_2_sprite.position_scale = PositionScale((10, 80), (1, 1))
sprite_manager.add_sprite(DrawLayers.OBJECTS, test_2_sprite)
text_1 = TextLabel("Das ist ein Test", 10, 80, 50, alignment="left")
text_1 = TextLabel("Frame: 0", 10, 110, 50, alignment="left")
text_1.position_scale.scale = (0.1, 0.1)
sprite_manager.add_sprite(DrawLayers.UI, text_1)
counter = 0
while True:
clock.tick(frame_rate)
@ -77,6 +78,8 @@ elif what_to_run == 'physics':
if skip:
continue
counter += 1
text_1.set_text(f"Frame: {counter}")
screen.fill((0, 0, 0))
sprite_manager.tick(apply_frame_rate(1))

View File

@ -14,13 +14,13 @@ class PhysicsElementsHandler:
def __init__(self):
pass
def tick_all_layers(self, dt: float, layers: dict[str, list[UiElement]]):
def tick(self, dt: float, layers: dict[str, list[UiElement]]):
sprites = []
for layer in layers:
self.tick(dt, layers[layer])
def tick(self, dt: float, sprites: list[UiElement]):
for sprite in sprites:
for sprite in layers[layer]:
sprite.tick(dt)
if isinstance(sprite, Sprite):
sprites.append(sprite)
# handle motion and collisions. To do this:
# 1. Find all sprites that have collision enabled and store them in a list

View File

@ -33,7 +33,7 @@ class SpriteManager:
self.layers[layer].remove(sprite)
def tick(self, dt: float):
self.physics_handler.tick_all_layers(dt, self.layers)
self.physics_handler.tick(dt, self.layers)
def draw(self, screen: Surface, screen_transform: PositionScale):
for layer in DrawLayers.DRAW_ORDER: