summaryrefslogtreecommitdiff
path: root/src/sliceitoff/enemies/enemies.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/sliceitoff/enemies/enemies.py')
-rw-r--r--src/sliceitoff/enemies/enemies.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py
index 797fe31..e9b4829 100644
--- a/src/sliceitoff/enemies/enemies.py
+++ b/src/sliceitoff/enemies/enemies.py
@@ -17,7 +17,7 @@ class EnemySprite(pygame.sprite.Sprite):
def set_movement(self, movement: tuple):
self.movement = movement
- def update(self, dt = 0):
+ def update(self, dt = 0, **kwargs):
if dt:
self.position = (
self.position[0] + self.movement[0] * dt,
@@ -56,26 +56,27 @@ class Enemies(pygame.sprite.Group):
enemy.set_movement( (randrange(0,200)-100, randrange(0,200)-100) )
self.add(enemy)
self.field = field
-
- def wall_hit(self, field, enemy):
- if enemy.rect.x < field.rect.x:
- enemy.force_right()
- if enemy.rect.y < field.rect.y:
- enemy.force_down()
- if ( enemy.rect.x + enemy.rect.w >= field.rect.x + field.rect.w ):
- enemy.force_left()
- if ( enemy.rect.y + enemy.rect.h >= field.rect.y + field.rect.h ):
- enemy.force_up()
-
- def hit_walls(self, field_sprites):
+
+ def update(self, field_rects = [], **kwargs):
+ super().update(**kwargs)
""" Do actions on enemies that are only partly on the fields """
for enemy in self.sprites():
- for field in field_sprites:
+ for field_rect in field_rects:
# if enemy is completely inside any field do next enemy
- if field.rect.contains(enemy):
+ if field_rect.contains(enemy):
break
else:
# now find field that enemy is partly on
- for field in field_sprites:
- if field.rect.colliderect(enemy):
- self.wall_hit(field, enemy)
+ for field_rect in field_rects:
+ if field_rect.colliderect(enemy):
+ self.wall_hit(field_rect, enemy)
+
+ def wall_hit(self, field, enemy):
+ if enemy.rect.x < field.x:
+ enemy.force_right()
+ if enemy.rect.y < field.y:
+ enemy.force_down()
+ if ( enemy.rect.x + enemy.rect.w >= field.x + field.w ):
+ enemy.force_left()
+ if ( enemy.rect.y + enemy.rect.h >= field.y + field.h ):
+ enemy.force_up()