50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from pygame import Surface, Color
|
|
|
|
from lib.pgfw.pgfw.GameChild import GameChild
|
|
|
|
class Plate(GameChild, Surface):
|
|
|
|
def __init__(self, parent):
|
|
GameChild.__init__(self, parent)
|
|
self.load_configuration()
|
|
self.init_surface()
|
|
self.set_background()
|
|
|
|
def load_configuration(self):
|
|
config = self.get_configuration("land")
|
|
self.height = config["height"]
|
|
self.speed = config["fade-speed"]
|
|
|
|
def init_surface(self):
|
|
Surface.__init__(self, (self.parent.intermediate.get_width(), self.height))
|
|
|
|
def set_background(self):
|
|
width, height = self.get_size()
|
|
background = Surface((width, height))
|
|
color = Color(0, 0, 0)
|
|
for y in range(height):
|
|
hue = abs(int(float(y) / (height) * 80) - 40) + 280
|
|
color.hsva = hue, 100, 40, 100
|
|
background.fill(color, (0, y, width, 1))
|
|
self.background = background
|
|
|
|
def reset(self):
|
|
self.offset = 0
|
|
|
|
def update(self):
|
|
self.update_offset()
|
|
self.draw()
|
|
|
|
def update_offset(self):
|
|
offset = self.offset - self.speed
|
|
height = self.get_height()
|
|
if offset < -height:
|
|
offset += height
|
|
self.offset = offset
|
|
|
|
def draw(self):
|
|
offset = int(self.offset)
|
|
background = self.background
|
|
self.blit(background, (0, offset))
|
|
self.blit(background, (0, offset + self.get_height()))
|