diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-29 18:39:41 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-29 18:39:41 +0200 |
commit | a9631796cf6d03946c6d1a72fba3cff554bd0f5c (patch) | |
tree | 27713cd7325aa55428f066b7fccdde0a74b862f9 /src/sliceitoff/field | |
parent | 7765d20550a8d5680b624f6063b4d2b23a094fed (diff) |
docstrings
Diffstat (limited to 'src/sliceitoff/field')
-rw-r--r-- | src/sliceitoff/field/field.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py index a062159..abcc615 100644 --- a/src/sliceitoff/field/field.py +++ b/src/sliceitoff/field/field.py @@ -40,6 +40,7 @@ class SliceSprite(FieldSprite): class Field(pygame.sprite.LayeredUpdates): + """ group that contains all pieces of field """ initial_area = (320_000, 220_000) def __init__(self, stats = None): @@ -49,11 +50,12 @@ class Field(pygame.sprite.LayeredUpdates): self.stats = stats def calculate_current_area(self): + """ calculates sum of areas of all fields """ return sum( s.area[2]*s.area[3] for s in self.active_sprites() ) - + def update(self, **kwargs): super().update(explode = True, **kwargs) - + def update_stats(self): """ calculates remaining area and remaining percentage """ self.stats.percent = 100 * self.calculate_current_area() / self.area_full @@ -66,15 +68,14 @@ class Field(pygame.sprite.LayeredUpdates): direction: bool, thickness: int) -> pygame.Rect: """ Slice one area into two areas """ - + # Slicing hits the area? for overlap in self.get_sprites_at(Scaling.scale_to_display(pos)): if not overlap.dead: break else: return None - - + # Save the area information and remove the sprite ax, ay, aw, ah = overlap.area overlap.remove(self) @@ -85,7 +86,7 @@ class Field(pygame.sprite.LayeredUpdates): x2 = pos[0] - thickness x3 = pos[0] + thickness x4 = ax + aw - + if x2 > x1: self.add(FieldSprite( (x1, ay, x2-x1, ah) )) if x4 > x3: @@ -114,22 +115,21 @@ class Field(pygame.sprite.LayeredUpdates): def active_sprites(self): """ Returns all sprites that are not dead """ return [s for s in self.sprites() if not s.dead] - + def active_rects(self): """ Returns active areas as rects """ return [s.rect for s in self.sprites() if not s.dead] def explode(self, area): + """ Make area full of explogind letters """ sx, sy, w, h = area for x in range(int(sx),int(sx+w),8_000): for y in range(int(sy),int(sy+h),8_000): - #self.add(ExplodedField((x,y,4_000,4_000))) self.add(LetterSprite( ('8x8', 8_000, 0xf), randrange(0,0x100), Scaling.scale_to_display((x,y)) )) - - + def kill_if_not_colliding(self, sprites): """ If there is empty fields that are not yet dead kill them """ for field in self.active_sprites(): |