summaryrefslogtreecommitdiff
path: root/src/sliceitoff/field
diff options
context:
space:
mode:
Diffstat (limited to 'src/sliceitoff/field')
-rw-r--r--src/sliceitoff/field/field.py53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py
index 93b4dba..2bf7d12 100644
--- a/src/sliceitoff/field/field.py
+++ b/src/sliceitoff/field/field.py
@@ -81,39 +81,42 @@ class Field(pygame.sprite.LayeredUpdates):
return None
# Save the area information and remove the sprite
- ax, ay, aw, ah = overlap.area
+ overlap_area = overlap.area
overlap.remove(self)
+ slicer = self.vertical_slicer if direction else self.horizontal_slicer
# create new areas if there is any space
- if direction:
- t2 = pos[0] - thickness
- t3 = pos[0] + thickness
- t4 = ax + aw
-
- if t2 > ax:
- self.add(FieldSprite( (ax, ay, t2-ax, ah) ))
- if t4 > t3:
- self.add(FieldSprite( (t3, ay, t4-t3, ah) ))
-
- area = t2, ay, t3-t2, ah
-
- else:
- t2 = pos[1] - thickness
- t3 = pos[1] + thickness
- t4 = ay + ah
-
- if t2 > ay:
- self.add(FieldSprite( (ax, ay, aw, t2-ay) ))
- if t4 > t3:
- self.add(FieldSprite( (ax, t3, aw, t4-t3) ))
-
- area = ax, t2, aw, t3-t2
-
+ area = slicer(pos, overlap_area, thickness)
self.explode(area)
zap_spite = SliceSprite(area)
self.add(zap_spite)
return zap_spite
+ def vertical_slicer(self, pos, area, thickness):
+ """ slices area in 3 parts vertically. returns lazer area """
+ ax, ay, aw, ah = area
+ t2 = pos[0] - thickness
+ t3 = pos[0] + thickness
+ t4 = ax + aw
+ if t2 > ax:
+ self.add(FieldSprite( (ax, ay, t2-ax, ah) ))
+ if t4 > t3:
+ self.add(FieldSprite( (t3, ay, t4-t3, ah) ))
+ return (t2, ay, t3-t2, ah)
+
+ def horizontal_slicer(self, pos, area, thickness):
+ """ slices area in 3 parts horizontally. returns lazer area """
+ ax, ay, aw, ah = area
+ t2 = pos[1] - thickness
+ t3 = pos[1] + thickness
+ t4 = ay + ah
+ if t2 > ay:
+ self.add(FieldSprite( (ax, ay, aw, t2-ay) ))
+ if t4 > t3:
+ self.add(FieldSprite( (ax, t3, aw, t4-t3) ))
+ return (ax, t2, aw, t3-t2)
+
+
def active_sprites(self):
""" Returns all sprites that are not dead """
return [s for s in self.sprites() if not s.dead]