summaryrefslogtreecommitdiff
path: root/src/sliceitoff/field/field.py
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-23 23:32:19 +0200
committerViljami Ilola <+@hix.fi>2024-03-23 23:32:19 +0200
commit4353670f0cee67550b20dfcfd51b81386372f358 (patch)
treefac7878ad160115437b0e359a1d73c9a5882fffd /src/sliceitoff/field/field.py
parenteef859a2acfead581c4960c7a3bff466983b9b2b (diff)
slicing partikles
Diffstat (limited to 'src/sliceitoff/field/field.py')
-rw-r--r--src/sliceitoff/field/field.py49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py
index 09a0b1b..134501c 100644
--- a/src/sliceitoff/field/field.py
+++ b/src/sliceitoff/field/field.py
@@ -23,16 +23,16 @@ class SliceSprite(FieldSprite):
super().__init__(area)
self.color = (255,255,255,255)
self.image.fill(self.color)
- self.timeout = 500
+ self.timeout = 300
self.dead = True
def update(self, dt = 0):
if dt:
self.timeout -= dt
self.color = (
- (randrange(0,500) < self.timeout) * 255,
- (randrange(0,500) < self.timeout) * 255,
- (randrange(0,500) < self.timeout) * 255,
+ (randrange(0,300) < self.timeout) * 255,
+ (randrange(0,300) < self.timeout) * 255,
+ (randrange(0,300) < self.timeout) * 255,
255)
if self.timeout <= 0:
self.kill()
@@ -112,25 +112,35 @@ class Field(pygame.sprite.LayeredUpdates):
if x4 > x3:
self.add(FieldSprite( (x3, ay, x4-x3, ah) ))
- self.add(SliceSprite( (x2, ay, x3-x2, ah) ))
- return Scaling.area_to_rect((x2, ay, x3-x2, ah))
- y1 = ay
- y2 = pos[1] - thickness
- y3 = pos[1] + thickness
- y4 = ay + ah
+ area = x2, ay, x3-x2, ah
- if y2 > y1:
- self.add(FieldSprite( (ax, y1, aw, y2-y1) ))
- if y4 > y3:
- self.add(FieldSprite( (ax, y3, aw, y4-y3) ))
+ else:
+ y1 = ay
+ y2 = pos[1] - thickness
+ y3 = pos[1] + thickness
+ y4 = ay + ah
+
+ if y2 > y1:
+ self.add(FieldSprite( (ax, y1, aw, y2-y1) ))
+ if y4 > y3:
+ self.add(FieldSprite( (ax, y3, aw, y4-y3) ))
- self.add(SliceSprite( (ax, y2, aw, y3-y2) ))
+ area = ax, y2, aw, y3-y2
- return Scaling.area_to_rect((ax, y2, aw, y3-y2))
+ self.explode(area)
+ self.add(SliceSprite(area))
+ return Scaling.area_to_rect( area )
def active_sprites(self):
""" Returns all sprites that are not dead """
return [s for s in self.sprites() if not s.dead]
+
+ def explode(self, area):
+ sx, sy, w, h = area
+ for x in range(int(sx),int(sx+w),4_000):
+ for y in range(int(sy),int(sy+h),3_000):
+ self.add(ExplodedField((x,y,3_000,3_000)))
+
def kill_if_not_colliding(self, sprites):
""" If there is empty fields that are not yet dead kill them """
@@ -139,8 +149,5 @@ class Field(pygame.sprite.LayeredUpdates):
if enemy.rect.colliderect(field.rect):
break
else:
- sx, sy, w, h = field.area
- for x in range(int(sx),int(sx+w),4_000):
- for y in range(int(sy),int(sy+h),4_000):
- self.add(ExplodedField((x,y,4_000,4_000)))
- self.remove(field)
+ self.explode(field.area)
+ field.remove(self)