summaryrefslogtreecommitdiff
path: root/src/sliceitoff/field
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-23 22:55:20 +0200
committerViljami Ilola <+@hix.fi>2024-03-23 22:55:20 +0200
commiteef859a2acfead581c4960c7a3bff466983b9b2b (patch)
treed511b9beb46a0ddc61703e5dca96cc5ad6b5cad2 /src/sliceitoff/field
parent98d91824cacec97c581ae0a4f1efd9fa3faa18ab (diff)
effects
Diffstat (limited to 'src/sliceitoff/field')
-rw-r--r--src/sliceitoff/field/field.py57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py
index 4fb4eff..09a0b1b 100644
--- a/src/sliceitoff/field/field.py
+++ b/src/sliceitoff/field/field.py
@@ -1,5 +1,6 @@
import os
import pygame
+from random import randrange
from display import Scaling, INTERNAL_WIDTH, INTERNAL_HEIGHT
from stats import Stats
@@ -14,29 +15,53 @@ class FieldSprite(pygame.sprite.Sprite):
self.dead = False
self.area = area
self.rect = Scaling.area_to_rect(self.area)
- self.image = pygame.Surface(self.rect.size, pygame.SRCALPHA)
+ self.image = pygame.Surface(self.rect.size)
self.image.fill(self.color)
+class SliceSprite(FieldSprite):
+ def __init__(self, area: tuple ):
+ super().__init__(area)
+ self.color = (255,255,255,255)
+ self.image.fill(self.color)
+ self.timeout = 500
+ self.dead = True
+
def update(self, dt = 0):
- if dt and self.dead:
+ if dt:
+ self.timeout -= dt
self.color = (
- self.color[0],
- self.color[1],
- self.color[2],
- self.color[3] - dt/4)
- if self.color[3] <= 0:
+ (randrange(0,500) < self.timeout) * 255,
+ (randrange(0,500) < self.timeout) * 255,
+ (randrange(0,500) < self.timeout) * 255,
+ 255)
+ if self.timeout <= 0:
self.kill()
else:
self.image.fill(self.color)
-
-class SliceSprite(FieldSprite):
- def __init__(self, area: tuple ):
+class ExplodedField(FieldSprite):
+ def __init__(self, area: tuple):
super().__init__(area)
- self.color = (255,255,0,255)
- self.image.fill(self.color)
self.dead = True
-
+ self.color = (255,255,255,255)
+ self.image.fill(self.color)
+ self.direction = (
+ Scaling.factor * (500 - randrange(1000)),
+ Scaling.factor * (500 - randrange(1000)))
+
+ def update(self, dt = 0, **kwargs):
+ if dt:
+ self.rect = pygame.Rect(
+ self.rect.x + self.direction[0] * dt,
+ self.rect.y + self.direction[1] * dt,
+ self.rect.w,
+ self.rect.h)
+ self.direction = (
+ self.direction[0] * 0.95,
+ self.direction[1] * 0.95 + 0.3)
+ if (self.rect.x > Scaling.resolution[0]
+ or self.rect.y > Scaling.resolution[1]):
+ self.kill()
class Field(pygame.sprite.LayeredUpdates):
@@ -114,4 +139,8 @@ class Field(pygame.sprite.LayeredUpdates):
if enemy.rect.colliderect(field.rect):
break
else:
- field.dead = True
+ 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)