diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-16 11:29:54 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-16 11:29:54 +0200 |
commit | 1ad8357f0039292b929e66cf703b4314660aded2 (patch) | |
tree | 09dff4e26eb64a4e355a54fd151d1de6759bc5cd | |
parent | 85adc89f53763b4390f7e51161a05ab394143152 (diff) |
field slice outline
-rw-r--r-- | src/sliceitoff/field/field.py | 26 | ||||
-rw-r--r-- | src/sliceitoff/main.py | 2 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py index c3d1d04..c7ebf81 100644 --- a/src/sliceitoff/field/field.py +++ b/src/sliceitoff/field/field.py @@ -23,16 +23,34 @@ class Field(): y * self.scaling.scale + self.scaling.top, w * self.scaling.scale, h * self.scaling.scale) + + def coordinates_inside_area(self, area, x, y): + if x < area[0]: + return False + if y < area[1]: + return False + if x >= area[0]+area[2]: + return False + if y >= area[1]+area[3]: + return False + return True + + def slice(self, x: int, y: int, direction: bool, thickness: int): + """ Slice one area into two areas """ + # Find the overlapping area + for area in self.areas: + if self.coordinates_inside_area(area, x, y): + break + else: + return False + self.areas.remove(area) + return False 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() diff --git a/src/sliceitoff/main.py b/src/sliceitoff/main.py index 6733466..d604d0b 100644 --- a/src/sliceitoff/main.py +++ b/src/sliceitoff/main.py @@ -20,7 +20,7 @@ def main(): field = Field(scaling=scaling) print(scaling) - + display.update( [ status.get_sprites(), |