summaryrefslogtreecommitdiff
path: root/src/sliceitoff/enemies
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-23 20:19:38 +0200
committerViljami Ilola <+@hix.fi>2024-03-23 20:19:38 +0200
commit87cd7293498d6b30389e056a59b2e69eb7b3a418 (patch)
tree392e2e15446a533d0bdc1faddd5a6e2d8fc731ee /src/sliceitoff/enemies
parentb03cb075e7a2042764a355a46d649b187f66343b (diff)
enemies as group
Diffstat (limited to 'src/sliceitoff/enemies')
-rw-r--r--src/sliceitoff/enemies/enemies.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py
index a3a60a0..aaa41be 100644
--- a/src/sliceitoff/enemies/enemies.py
+++ b/src/sliceitoff/enemies/enemies.py
@@ -18,11 +18,11 @@ class EnemySprite(pygame.sprite.Sprite):
def set_movement(self, movement: tuple):
self.movement = movement
- def update(self, move = 0):
- if move:
+ def update(self, dt = 0):
+ if dt:
self.position = (
- self.position[0] + self.movement[0] * move,
- self.position[1] + self.movement[1] * move)
+ self.position[0] + self.movement[0] * dt,
+ self.position[1] + self.movement[1] * dt)
self.rect = pygame.Rect(
Scaling.scale_to_display(self.position),
self.image.get_size())
@@ -46,18 +46,15 @@ class EnemyBall(EnemySprite):
self.update()
-class Enemies():
+class Enemies(pygame.sprite.Group):
def __init__(self, field = None):
- self.sprites = pygame.sprite.Group()
- self.emerge_enemies()
- self.field = field
-
- def emerge_enemies(self):
+ super().__init__()
for _ in range(3 + (Stats.level-1) * 2):
enemy = EnemyBall()
enemy.set_position( (randrange(0,300_000), randrange(0,200_000)) )
enemy.set_movement( (randrange(0,200)-100, randrange(0,200)-100) )
- self.sprites.add(enemy)
+ self.add(enemy)
+ self.field = field
def wall_hit(self, field, enemy):
if enemy.rect.x < field.rect.x:
@@ -69,10 +66,10 @@ class Enemies():
if ( enemy.rect.y + enemy.rect.h >= field.rect.y + field.rect.h ):
enemy.force_up()
- def update(self, dt):
+ def update(self, dt = 0):
""" Update sprites basis of dt. dt = milliseconds from last update """
- self.sprites.update(move=dt)
- for enemy in self.sprites:
+ super().update(dt = dt)
+ for enemy in self.sprites():
for field in self.field.sprites():
if field.rect.contains(enemy):
break