diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-16 11:11:56 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-16 11:11:56 +0200 |
commit | 85adc89f53763b4390f7e51161a05ab394143152 (patch) | |
tree | b63de708a75d7ea3fd961f8d63ca2af381cb66c5 /src/sliceitoff/field | |
parent | 5d921239e0577988e2b7814025149d9160ecbdda (diff) |
drafting game components
Diffstat (limited to 'src/sliceitoff/field')
-rw-r--r-- | src/sliceitoff/field/__init__.py | 1 | ||||
-rw-r--r-- | src/sliceitoff/field/field.py | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/sliceitoff/field/__init__.py b/src/sliceitoff/field/__init__.py new file mode 100644 index 0000000..2ae0139 --- /dev/null +++ b/src/sliceitoff/field/__init__.py @@ -0,0 +1 @@ +from .field import Field diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py new file mode 100644 index 0000000..c3d1d04 --- /dev/null +++ b/src/sliceitoff/field/field.py @@ -0,0 +1,43 @@ +import pygame +from display import Scaling + +class FieldSprite(pygame.sprite.Sprite): + def __init__(self, rect: pygame.Rect): + super().__init__() + self.rect = rect + self.image = pygame.Surface(self.rect.size) + self.image.fill("green") + + +class Field(): + def __init__(self, scaling: Scaling = None): + self.scaling = scaling if scaling else Scaling(50,0,0) + self.sprites = pygame.sprite.Group() + self.updated = True + self.areas = [(0,0,40_000,28_000)] + + def area_to_rect(self, area): + x, y, w, h = area + return pygame.Rect( + x * self.scaling.scale + self.scaling.left, + y * self.scaling.scale + self.scaling.top, + w * self.scaling.scale, + h * self.scaling.scale) + + def __update_sprites(self): + self.sprites.empty() + for area in self.areas: + self.sprites.add(FieldSprite(self.area_to_rect(area))) + + def add_score(self, score_to_add): + self.updated = True + self.score += score_to_add + + def get_sprites(self): + if self.updated: + self.__update_sprites() + return self.sprites + + def __del__(self): + pass +
\ No newline at end of file |