From 2e3cc2f1ad0be16b2e8e99b2d29eef11b83d3cd4 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 28 Dec 2022 18:13:02 -0800 Subject: [PATCH] use intermediate surface for trail effect, restore static to top layer --- electric_sieve/ElectricSieve.py | 44 +++++++++++++++++++++++++-------- electric_sieve/land/Land.py | 1 + electric_sieve/land/Plate.py | 2 +- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/electric_sieve/ElectricSieve.py b/electric_sieve/ElectricSieve.py index 5fc4a5b..4a93c1e 100644 --- a/electric_sieve/ElectricSieve.py +++ b/electric_sieve/ElectricSieve.py @@ -66,6 +66,13 @@ class ElectricSieve(Game): self.initialize_gpio() self.velocity = Vector(0, 0) + + # Create an intermediate surface to draw the triangles to and create a trail effect + self.trail_effect = Surface(self.get_display_surface().get_size(), pygame.SRCALPHA) + + # Create a black background + self.background = Surface(self.get_display_surface().get_size()) + self.background.fill((0, 0, 0)) # Create game objects self.title = Title(self) @@ -75,11 +82,6 @@ class ElectricSieve(Game): self.static = Static(self) self.land = Land(self) - # Create a purple background - self.background = Surface(self.display.screen.get_size()) - # self.background.fill((255, 80, 190)) - self.background.fill((0, 0, 0)) - # Start the title screen self.title.activate() @@ -157,15 +159,36 @@ class ElectricSieve(Game): return rotated def update(self): - self.background.set_alpha(int((1 - self.acid.get_volume() * 1.75) * 255)) self.title.update() + + # Test if the level is being played if self.triangles.active: - self.display.screen.blit(self.background, (0, 0)) + + # Draw grid effect self.land.update() - self.static.update() - self.triangles.update() + + # Set the background alpha low to create a trail effect on the triangles. + self.background.set_alpha(255 * 0.1) + + # Draw the alpha background only to the trail effect surface. This will partially erase the previous drawings of the triangles. + self.trail_effect.blit(self.background, (0, 0)) + + # Draw triangles onto the trail effect surface, update position + self.triangles.update() + + # Set alpha back to full for drawing the bottom layer background + self.background.set_alpha(255) + self.get_display_surface().blit(self.background, (0, 0)) + + # Draw the triangles to the screen, using the intermediate trail effect surface + self.get_display_surface().blit(self.trail_effect, (0, 0)) + + # Draw the sieve self.sieve.update() + # Draw the static + self.static.update() + class Title(GameChild): @@ -218,6 +241,7 @@ class Title(GameChild): self.parent.sieve.activate() self.parent.static.activate() self.advance.play() + self.get_display_surface().blit(self.get_game().background, (0, 0)) def activate(self): self.active = True @@ -508,7 +532,7 @@ class Triangles(GameChild, list): GameChild.__init__(self, parent) self.music = Sound(self.get_resource("audio", "triangles")) self.deactivate() - self.display_surface = self.get_display_surface() + self.display_surface = self.get_game().trail_effect self.delegate = self.get_game().delegate self.booster = Shift(self, 1, "boost") self.hit = Sound(self.get_resource("audio", "hit")) diff --git a/electric_sieve/land/Land.py b/electric_sieve/land/Land.py index d6eadb5..b555aee 100644 --- a/electric_sieve/land/Land.py +++ b/electric_sieve/land/Land.py @@ -11,6 +11,7 @@ class Land(GameChild, Rect): def __init__(self, parent): GameChild.__init__(self, parent) + self.display_surface = self.get_game().background self.load_configuration() if not self.get_game().rotated: self.intermediate = pygame.Surface(self.get_display_surface().get_size()) diff --git a/electric_sieve/land/Plate.py b/electric_sieve/land/Plate.py index 95057b7..149f036 100644 --- a/electric_sieve/land/Plate.py +++ b/electric_sieve/land/Plate.py @@ -24,7 +24,7 @@ class Plate(GameChild, Surface): color = Color(0, 0, 0) for y in range(height): hue = abs(int(float(y) / (height) * 240) - 120) - color.hsva = hue, 100, 20, 100 + color.hsva = hue, 100, 40, 100 background.fill(color, (0, y, width, 1)) self.background = background