diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-30 16:08:03 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-30 16:08:03 +0200 |
commit | 1def24341ce4f3ab1c1de4a9dde27bf0b5fab179 (patch) | |
tree | e846c7ea2f4306146f33381c289350c2edf6f093 /src/sliceitoff/enemies/bouncher.py | |
parent | 5874005e58d0f26b4393845b3b18160658ece160 (diff) |
bounching balls and more refactoring
Diffstat (limited to 'src/sliceitoff/enemies/bouncher.py')
-rw-r--r-- | src/sliceitoff/enemies/bouncher.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/sliceitoff/enemies/bouncher.py b/src/sliceitoff/enemies/bouncher.py new file mode 100644 index 0000000..692492b --- /dev/null +++ b/src/sliceitoff/enemies/bouncher.py @@ -0,0 +1,36 @@ +""" enemies.bouncher - Enemy type that bouches around """ +from random import randrange, choice + +from text import get_letter_surface +from .enemy import Enemy + +BOUNCHER_SPAWN_AREA = (0, 0, 300_000, 80_000) +BOUNCHER_MOVEMENT = (200, 20) +BOUNCHER_SIZE = 12_000 +BOUNCHER_SYMBOLS = (0x1,0x2) +GRAVITY = 4 + +class EnemyBouncher(Enemy): + """ Type of enemy that is affected by gravity """ + def __init__(self): + super().__init__() + self.position = ( + randrange(BOUNCHER_SPAWN_AREA[0], BOUNCHER_SPAWN_AREA[2]), + randrange(BOUNCHER_SPAWN_AREA[1], BOUNCHER_SPAWN_AREA[3])) + self.movement = ( + randrange(0, BOUNCHER_MOVEMENT[0]*2) - BOUNCHER_MOVEMENT[0], + randrange(0, BOUNCHER_MOVEMENT[1]*2) - BOUNCHER_MOVEMENT[1]) + font_key = ('8x8', BOUNCHER_SIZE, 0) + surface = get_letter_surface(font_key, choice(BOUNCHER_SYMBOLS)) + self.image = surface.subsurface( + (0, 0, surface.get_rect().w, surface.get_rect().w)) + self.rect = None + self.update() + + def update(self, dt = 0, wall_hit = None, **kwargs): + """ wall hit from super(). added gravity """ + super().update(dt = dt, wall_hit = wall_hit, **kwargs) + if dt: + self.movement = ( + self.movement[0], + (self.movement[1] + GRAVITY)*0.999) |