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.py56
1 files changed, 13 insertions, 43 deletions
diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py
index 41a19fa..c52059f 100644
--- a/src/sliceitoff/enemies/enemies.py
+++ b/src/sliceitoff/enemies/enemies.py
@@ -1,52 +1,22 @@
-import pygame
from random import randrange
+import pygame
-from display import Scaling
-from text import get_letter_surface
-
-BALL_SPAWN_AREA = (0, 0, 300_000, 200_000)
-BALL_MOVEMENT = (100, 100)
-
-class EnemyBall(pygame.sprite.Sprite):
- def __init__(self):
- super().__init__()
- self.position = (
- randrange(BALL_SPAWN_AREA[0], BALL_SPAWN_AREA[2]),
- randrange(BALL_SPAWN_AREA[1], BALL_SPAWN_AREA[3]))
- self.movement = (
- randrange(0, BALL_MOVEMENT[0]*2) - BALL_MOVEMENT[0],
- randrange(0, BALL_MOVEMENT[1]*2) - BALL_MOVEMENT[1])
- self.image = get_letter_surface(
- ('8x8', 8_000, 0),
- randrange(1,3)).subsurface(
- (0,0,8_000*Scaling.factor,8_000*Scaling.factor))
- self.update()
- self.rect = None
-
- def update(self, dt = 0, wall_hit = None, **kwargs):
- if wall_hit:
- if self.rect.x < wall_hit.x:
- self.movement = (abs(self.movement[0]), self.movement[1])
- if self.rect.y < wall_hit.y:
- self.movement = (self.movement[0], abs(self.movement[1]))
- if self.rect.x + self.rect.w >= wall_hit.x + wall_hit.w:
- self.movement = (-abs(self.movement[0]), self.movement[1])
- if self.rect.y + self.rect.h >= wall_hit.y + wall_hit.h:
- self.movement = (self.movement[0], -abs(self.movement[1]))
- return
- if dt:
- self.position = (
- 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())
+from .ball import EnemyBall
+from .bouncher import EnemyBouncher
class Enemies(pygame.sprite.Group):
def __init__(self, field = None, count = 0):
super().__init__()
- for _ in range(count):
- self.add(EnemyBall())
+ while count:
+ match randrange(0,4):
+ case 0|1|2:
+ if count >= 1:
+ self.add(EnemyBall())
+ count -= 1
+ case 3:
+ if count >= 2:
+ self.add(EnemyBouncher())
+ count -= 2
self.field = field
def update(self, field_rects = [], **kwargs):