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 | |
parent | 7765d20550a8d5680b624f6063b4d2b23a094fed (diff) |
docstrings
-rw-r--r-- | src/sliceitoff/enemies/__init__.py | 1 | ||||
-rw-r--r-- | src/sliceitoff/enemies/enemies.py | 13 | ||||
-rw-r--r-- | src/sliceitoff/field/field.py | 20 | ||||
-rw-r--r-- | src/sliceitoff/screens/__init__.py | 2 | ||||
-rw-r--r-- | src/sliceitoff/screens/gameover.py | 2 | ||||
-rw-r--r-- | src/sliceitoff/screens/hiscores.py | 2 | ||||
-rw-r--r-- | src/sliceitoff/screens/initials.py | 3 | ||||
-rw-r--r-- | src/sliceitoff/screens/level.py | 3 | ||||
-rw-r--r-- | src/sliceitoff/screens/levelup.py | 3 | ||||
-rw-r--r-- | src/sliceitoff/screens/welcome.py | 2 |
10 files changed, 32 insertions, 19 deletions
diff --git a/src/sliceitoff/enemies/__init__.py b/src/sliceitoff/enemies/__init__.py index 2d00927..0f06761 100644 --- a/src/sliceitoff/enemies/__init__.py +++ b/src/sliceitoff/enemies/__init__.py @@ -1 +1,2 @@ +""" enemies - enemies as sprites and groups """ from .enemies import Enemies diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py index e9b4829..66ebcbd 100644 --- a/src/sliceitoff/enemies/enemies.py +++ b/src/sliceitoff/enemies/enemies.py @@ -9,11 +9,11 @@ class EnemySprite(pygame.sprite.Sprite): super().__init__() self.position = (0, 0) self.movement = (0, 0) - + def set_position(self, position: tuple): self.position = position self.update() - + def set_movement(self, movement: tuple): self.movement = movement @@ -25,7 +25,7 @@ class EnemySprite(pygame.sprite.Sprite): self.rect = pygame.Rect( Scaling.scale_to_display(self.position), self.image.get_size()) - + def force_right(self): self.movement = (abs(self.movement[0]), self.movement[1]) @@ -45,7 +45,6 @@ class EnemyBall(EnemySprite): colored = letter.fill( "black", special_flags = pygame.BLEND_RGBA_MULT) self.image = pygame.transform.scale_by(letter, 1_000 * Scaling.factor) self.update() - class Enemies(pygame.sprite.Group): def __init__(self, field = None, count = 0): @@ -58,8 +57,8 @@ class Enemies(pygame.sprite.Group): self.field = field def update(self, field_rects = [], **kwargs): - super().update(**kwargs) """ Do actions on enemies that are only partly on the fields """ + super().update(**kwargs) for enemy in self.sprites(): for field_rect in field_rects: # if enemy is completely inside any field do next enemy @@ -76,7 +75,7 @@ class Enemies(pygame.sprite.Group): enemy.force_right() if enemy.rect.y < field.y: enemy.force_down() - if ( enemy.rect.x + enemy.rect.w >= field.x + field.w ): + 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 ): + if enemy.rect.y + enemy.rect.h >= field.y + field.h: enemy.force_up() 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(): diff --git a/src/sliceitoff/screens/__init__.py b/src/sliceitoff/screens/__init__.py index d448890..107d231 100644 --- a/src/sliceitoff/screens/__init__.py +++ b/src/sliceitoff/screens/__init__.py @@ -1,3 +1,5 @@ +""" screens - collection of functions that generates group of spites + to fill the screen """ from .welcome import welcome_screen from .levelup import levelup_screen from .gameover import gameover_screen diff --git a/src/sliceitoff/screens/gameover.py b/src/sliceitoff/screens/gameover.py index 33bda18..aac4b22 100644 --- a/src/sliceitoff/screens/gameover.py +++ b/src/sliceitoff/screens/gameover.py @@ -1,6 +1,8 @@ +""" screen.gameover - screen to be displayer game over situation """ from text import TextPage def gameover_screen(): + """ gameover_screen - overlay top of ended gameplay """ return TextPage( "Game Over!", font = '8x8', diff --git a/src/sliceitoff/screens/hiscores.py b/src/sliceitoff/screens/hiscores.py index 74a0ee2..c73f0bf 100644 --- a/src/sliceitoff/screens/hiscores.py +++ b/src/sliceitoff/screens/hiscores.py @@ -1,6 +1,8 @@ +""" screens.hiscores - Defines how to display hiscore text on the screen """ from text import TextPage def hiscores_screen(score_text): + """ hiscores_screen - only ajustments to hiscore text """ return TextPage( score_text, font = 'lcd', diff --git a/src/sliceitoff/screens/initials.py b/src/sliceitoff/screens/initials.py index aadb141..334f515 100644 --- a/src/sliceitoff/screens/initials.py +++ b/src/sliceitoff/screens/initials.py @@ -1,6 +1,9 @@ +""" screens.initials - screen where input initials when one makes + to hiscores """ from text import TextPage def initials_screen(name): + """ initials_screen - screen where name is updating as user imputs """ return TextPage( f" New High Score!\n" f"\n" diff --git a/src/sliceitoff/screens/level.py b/src/sliceitoff/screens/level.py index ea298ad..d3a60f8 100644 --- a/src/sliceitoff/screens/level.py +++ b/src/sliceitoff/screens/level.py @@ -1,7 +1,8 @@ +""" screens.level - Screen to be shown when level begins. """ from text import TextPage -from stats import Stats def level_screen(level): + """ level_screen - displays level number """ return TextPage( f"Level {level}!", font = '8x8', diff --git a/src/sliceitoff/screens/levelup.py b/src/sliceitoff/screens/levelup.py index ef48b7b..25cb1b9 100644 --- a/src/sliceitoff/screens/levelup.py +++ b/src/sliceitoff/screens/levelup.py @@ -1,6 +1,8 @@ +""" screen.levelup - Screen to show after succesfully completing level """ from text import TextPage def levelup_screen(stats = None): + """ levelup_screen - screen full of stats how bonus is calculated """ ( total_bonus, level_bonus, @@ -20,7 +22,6 @@ def levelup_screen(stats = None): f"\xea\x0f\xef{herd_bonus:9d}pts\n" f"\n" f"Bonus{total_bonus:13d}pts\n") - return TextPage( text, font = 'lcd', diff --git a/src/sliceitoff/screens/welcome.py b/src/sliceitoff/screens/welcome.py index f3fd25e..7078f1f 100644 --- a/src/sliceitoff/screens/welcome.py +++ b/src/sliceitoff/screens/welcome.py @@ -1,6 +1,8 @@ +""" screens.welcome - name, objective and scoring """ from text import TextPage def welcome_screen(): + """ welcome_screen - could be also considered as instruction screen """ return TextPage( " Slice it off!\n" " \n" |