From 947df85053af2704ce1a17daf1fab13e273f0cc5 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sat, 23 Mar 2024 21:02:56 +0200 Subject: remove cross dependencies. moving logic towards game/... --- src/sliceitoff/enemies/enemies.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/sliceitoff/enemies') diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py index aaa41be..3f206c7 100644 --- a/src/sliceitoff/enemies/enemies.py +++ b/src/sliceitoff/enemies/enemies.py @@ -65,15 +65,16 @@ class Enemies(pygame.sprite.Group): enemy.force_left() if ( enemy.rect.y + enemy.rect.h >= field.rect.y + field.rect.h ): enemy.force_up() - - def update(self, dt = 0): - """ Update sprites basis of dt. dt = milliseconds from last update """ - super().update(dt = dt) + + def hit_walls(self, field_sprites): + """ Do actions on enemies that are only partly on the fields """ for enemy in self.sprites(): - for field in self.field.sprites(): + for field in field_sprites: + # if enemy is completely inside any field do next enemy if field.rect.contains(enemy): break else: - for field in self.field.sprites(): + # now find field that enemy is partly on + for field in field_sprites: if field.rect.colliderect(enemy): self.wall_hit(field, enemy) -- cgit v1.2.3