use intermediate surface for trail effect, restore static to top layer
This commit is contained in:
parent
51196d47e1
commit
2e3cc2f1ad
|
@ -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"))
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue