diff options
-rw-r--r-- | src/sliceitoff/field/field.py | 49 |
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) |