diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-29 13:52:24 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-29 13:52:24 +0200 |
commit | 063628a3c493df902af9cef4f56f726a9d4ee906 (patch) | |
tree | 3a9b95f1060cc5d4302b6ff86d2ddf9901dd361e /src/sliceitoff/field | |
parent | 4e88912ff032f1df77480ba37c82fb7049d1ff1b (diff) |
refactor lettersrite and textpage; field explodes to letters
Diffstat (limited to 'src/sliceitoff/field')
-rw-r--r-- | src/sliceitoff/field/field.py | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py index 5769bfc..6baf966 100644 --- a/src/sliceitoff/field/field.py +++ b/src/sliceitoff/field/field.py @@ -3,6 +3,7 @@ import pygame from random import randrange from display import Scaling, INTERNAL_WIDTH, INTERNAL_HEIGHT +from text import LetterSprite DEBUG = os.getenv("DEBUG") @@ -24,7 +25,7 @@ class SliceSprite(FieldSprite): self.timeout = 300 self.dead = True - def update(self, dt = 0): + def update(self, dt = 0, **kwargs): if dt: self.timeout -= dt self.color = ( @@ -37,30 +38,6 @@ class SliceSprite(FieldSprite): else: self.image.fill(self.color) -class ExplodedField(FieldSprite): - def __init__(self, area: tuple): - super().__init__(area) - self.dead = True - self.color = (255,255,255,255) - self.image.fill(self.color) - self.direction = ( - Scaling.factor * (500 - randrange(1000)), - Scaling.factor * (500 - randrange(1000))) - - def update(self, dt = 0, **kwargs): - if dt: - self.rect = pygame.Rect( - self.rect.x + self.direction[0] * dt, - self.rect.y + self.direction[1] * dt, - self.rect.w, - self.rect.h) - self.direction = ( - self.direction[0] * 0.95, - self.direction[1] * 0.95 + 0.3) - if (self.rect.x > Scaling.resolution[0] - or self.rect.y > Scaling.resolution[1]): - self.kill() - class Field(pygame.sprite.LayeredUpdates): initial_area = (320_000, 220_000) @@ -74,6 +51,9 @@ class Field(pygame.sprite.LayeredUpdates): def calculate_current_area(self): 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 @@ -139,7 +119,11 @@ class Field(pygame.sprite.LayeredUpdates): 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(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): |