summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-30 16:46:29 +0200
committerViljami Ilola <+@hix.fi>2024-03-30 16:46:29 +0200
commitaf17f92e0beda893fb91ff757b76f2499e500666 (patch)
tree180ddcc4fac223e057d76db71f6ae4ddbe67721a /src
parent1def24341ce4f3ab1c1de4a9dde27bf0b5fab179 (diff)
lint
Diffstat (limited to 'src')
-rw-r--r--src/sliceitoff/field/__init__.py1
-rw-r--r--src/sliceitoff/field/field.py18
-rw-r--r--src/sliceitoff/stats/__init__.py1
-rw-r--r--src/sliceitoff/stats/stats.py16
-rw-r--r--src/sliceitoff/text/fonts.py1
-rw-r--r--src/sliceitoff/text/text.py5
6 files changed, 26 insertions, 16 deletions
diff --git a/src/sliceitoff/field/__init__.py b/src/sliceitoff/field/__init__.py
index 2ae0139..2c9bcfb 100644
--- a/src/sliceitoff/field/__init__.py
+++ b/src/sliceitoff/field/__init__.py
@@ -1 +1,2 @@
+""" field - playfield or slices left of it """
from .field import Field
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py
index abcc615..58464de 100644
--- a/src/sliceitoff/field/field.py
+++ b/src/sliceitoff/field/field.py
@@ -1,13 +1,16 @@
+""" field.field - The playing area or slices, lazer of explosions of it """
import os
+from random import randrange, choice
+
import pygame
-from random import randrange
-from display import Scaling, INTERNAL_WIDTH, INTERNAL_HEIGHT
+from display import Scaling, CGA_COLORS
from text import LetterSprite
DEBUG = os.getenv("DEBUG")
class FieldSprite(pygame.sprite.Sprite):
+ """ Playing area consist of these sprites """
def __init__(self, area: tuple):
super().__init__()
self.color = (0,255,0,255)
@@ -18,6 +21,7 @@ class FieldSprite(pygame.sprite.Sprite):
self.image.fill(self.color)
class SliceSprite(FieldSprite):
+ """ Flashing rectangle like lazer """
def __init__(self, area: tuple ):
super().__init__(area)
self.color = (255,255,255,255)
@@ -26,13 +30,12 @@ class SliceSprite(FieldSprite):
self.dead = True
def update(self, dt = 0, **kwargs):
+ """ Just pick a randon color every update from cga palette """
+ # pylint: disable = unused-argument
+ # explosion arg is given, but no use in SliceSprite
if dt:
self.timeout -= dt
- self.color = (
- (randrange(0,300) < self.timeout) * 255,
- (randrange(0,300) < self.timeout) * 255,
- (randrange(0,300) < self.timeout) * 255,
- 255)
+ self.color = choice(CGA_COLORS)
if self.timeout <= 0:
self.kill()
else:
@@ -54,6 +57,7 @@ class Field(pygame.sprite.LayeredUpdates):
return sum( s.area[2]*s.area[3] for s in self.active_sprites() )
def update(self, **kwargs):
+ """ just force explosion on """
super().update(explode = True, **kwargs)
def update_stats(self):
diff --git a/src/sliceitoff/stats/__init__.py b/src/sliceitoff/stats/__init__.py
index 900594e..f35a548 100644
--- a/src/sliceitoff/stats/__init__.py
+++ b/src/sliceitoff/stats/__init__.py
@@ -1 +1,2 @@
+""" stats - accounting statistics during game. level, score, bonus..."""
from .stats import Stats
diff --git a/src/sliceitoff/stats/stats.py b/src/sliceitoff/stats/stats.py
index 2d63953..87c4c5f 100644
--- a/src/sliceitoff/stats/stats.py
+++ b/src/sliceitoff/stats/stats.py
@@ -1,5 +1,6 @@
+""" stats.stats """
class Stats:
-
+ """ score, level, enemy count etc stats during the game """
def __init__(self):
self.score = 0
self.level = 1
@@ -8,26 +9,28 @@ class Stats:
self.enemies = 3
self.percent = 100
self.field_count = 1
- self.bgcolor = (64,0,0,255)
- self.bordercolor = (0,0,0,255)
-
+
def level_up(self):
+ """ task on beginning of level. new bonus, enemy count... """
self.score += self.calc_bonus()[0]
self.bonus = 20_000
self.percent = 100
self.field_count = 1
self.level += 1
self.enemies = 3 + (self.level - 1) * 2
-
+
def lose_life(self):
+ """ lives left after losing life """
self.lives -= 1
return not self.lives
-
+
def add_score(self, score_to_add):
+ """ adding score never goes negative """
self.score += score_to_add
self.score = max(0, self.score)
def calc_bonus(self):
+ """ calculates bonus and returns components """
level = self.level * 3_000
life = self.lives * 1_000
time = self.level * self.bonus
@@ -37,4 +40,5 @@ class Stats:
return total, level, life, time, area, herd
def update_bonus(self, dt):
+ """ bonus countdown. never goes negative """
self.bonus = max(0, self.bonus - dt)
diff --git a/src/sliceitoff/text/fonts.py b/src/sliceitoff/text/fonts.py
index af9aefb..5743e2a 100644
--- a/src/sliceitoff/text/fonts.py
+++ b/src/sliceitoff/text/fonts.py
@@ -10,6 +10,7 @@ class Fonts:
@staticmethod
def load_fonts(base_path):
+ """ loads fonts from list """
filename_fontlist = os.path.join(base_path, "assets", "fonts.lst")
with open(filename_fontlist, "r", encoding="utf-8") as fontlist_file:
for line in fontlist_file:
diff --git a/src/sliceitoff/text/text.py b/src/sliceitoff/text/text.py
index 69a30bc..c1fd7b8 100644
--- a/src/sliceitoff/text/text.py
+++ b/src/sliceitoff/text/text.py
@@ -29,7 +29,7 @@ def get_letter_surface(font_key, ch):
CGA_COLORS[color],
special_flags = pygame.BLEND_RGBA_MULT)
return scaled_fonts[font_key][ch]
-
+
class LetterSprite(pygame.sprite.Sprite):
""" Make sprite out of letter surface at given position """
@@ -42,7 +42,7 @@ class LetterSprite(pygame.sprite.Sprite):
Scaling.factor * (1_000 - randrange(2_000)),
Scaling.factor * (1_000 - randrange(2_000)))
- def update(self, dt = 0, explode = 0, **kwargs):
+ def update(self, dt = 0, explode = 0):
""" All the movements for letters """
if explode and dt:
self.rect = pygame.Rect(
@@ -94,4 +94,3 @@ class TextPage(pygame.sprite.Group):
(pos[0]+col*grid[0], pos[1]+row*grid[1]) )
self.add(LetterSprite(font_key, ch, sprite_pos))
col += 1
- \ No newline at end of file