from pygame import Surface

from dark_stew.pgfw.GameChild import GameChild
from dark_stew.water.Layer import Layer

class Water(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.load_configuration()
        self.set_background()
        self.add_layers()

    def load_configuration(self):
        config = self.get_configuration("water")
        self.opacity = config["opacity"]
        self.speed = config["speed"]
        self.color = config["color"]

    def set_background(self):
        background = Surface(self.display_surface.get_size())
        background.fill(self.color)
        self.background = background

    def add_layers(self):
        layers = []
        for ii, opacity in enumerate(self.opacity):
            layers.append(Layer(self, opacity, self.speed[ii], ii * 16))
        self.layers = layers

    def update(self):
        for layer in self.layers:
            layer.update()
        self.draw()

    def draw(self):
        self.display_surface.blit(self.background, (0, 0))
        for layer in reversed(self.layers):
            layer.draw()
from pygame import Surface
from pygame.image import load

from dark_stew.pgfw.GameChild import GameChild

class Layer(GameChild, Surface):

    def __init__(self, parent, opacity, speed, base_offset):
        GameChild.__init__(self, parent)
        self.opacity = opacity
        self.speed = speed
        self.base_offset = base_offset
        self.display_surface = self.get_display_surface()
        self.transparent_color = (255, 0, 255)
        self.offset = 0
        self.set_tile()
        self.init_surface()
        self.paint()

    def set_tile(self):
        path = self.get_resource("water", "tile-path")
        self.tile = load(path).convert_alpha()

    def init_surface(self):
        padding = self.tile.get_width()
        width, height = self.parent.parent.size
        Surface.__init__(self, (width + padding, height + padding))
        transparent_color = self.transparent_color
        self.fill(transparent_color)
        self.set_colorkey(transparent_color)
        self.set_alpha(self.opacity)
        self.padding = padding

    def paint(self):
        tile = self.tile
        for x in xrange(0, self.get_width(), tile.get_width()):
            for y in xrange(0, self.get_height(), tile.get_height()):
                self.blit(tile, (x, y))

    def update(self):
        offset = self.offset - self.speed
        padding = self.padding
        if offset < -padding:
            offset += padding
        self.offset = offset

    def draw(self):
        rect = self.parent.parent.move([int(self.offset)] * 2)
        rect.top += self.base_offset
        self.display_surface.blit(self, rect)
from math import sqrt
from os import listdir
from os.path import isdir, join
from re import match

from dark_stew.pgfw.GameChild import GameChild
from dark_stew.pool.Pool import Pool

class Pools(GameChild, list):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.add_pools()

    def add_pools(self):
        width = self.parent.w
        step = int(float(width) / sqrt(self.count_pools()))
        ii = 0
        for x in xrange(step / 2, width, step):
            for y in xrange(step / 2, width, step):
                self.append(Pool(self, (x, y), ii))
                ii += 1
        self.step = step

    def count_pools(self):
        count = 0
        root = self.get_resource("pool", "water-path")
        for name in listdir(root):
            if match("^[0-9]", name):
                count += 1
        return count

    def update(self):
        for pool in self:
            pool.update()
from os.path import join

from dark_stew.pgfw.Sprite import Sprite

class Ring(Sprite):

    def __init__(self, parent, index):
        Sprite.__init__(self, parent)
        self.index = index
        self.display_surface = self.get_display_surface()
        self.load_from_path(self.build_path(), transparency=True, ppa=False)
        self.rect.center = parent.center

    def build_path(self):
        return join(self.get_resource("pool", "ring-path"),
                    str(self.index) + ".png")

    def draw(self):
        x, y = self.rect.topleft
        frame = self.get_current_frame()
        surface = self.display_surface
        for dx, dy in self.parent.parent.parent.get_corners():
            surface.blit(frame, (x + dx, y + dy))
from os.path import join

from pygame import Surface
from pygame.image import load

from dark_stew.pgfw.Sprite import Sprite

class Water(Sprite):

    def __init__(self, parent, index):
        Sprite.__init__(self, parent)
        self.index = index
        self.display_surface = self.get_display_surface()
        self.transparent_color = (255, 0, 255)
        self.load_configuration()
        self.load_groove()
        self.set_framerate(self.framerate)
        self.load_from_path(join(self.frames_root, str(index)),
                            transparency=True, ppa=False)
        self.rect.center = parent.center

    def load_configuration(self):
        config = self.get_configuration("pool")
        self.framerate = config["framerate"]
        self.frames_root = self.get_resource("pool", "water-path")
        self.groove_path = self.get_resource(join(config["water-path"],
                                                  config["groove-path"]))

    def load_groove(self):
        image = load(join(self.groove_path, str(self.index) + ".png"))
        surface = Surface(image.get_size())
        transparent_color = self.transparent_color
        surface.fill(transparent_color)
        surface.set_colorkey(transparent_color)
        surface.blit(image, (0, 0))
        self.groove = surface

    def draw(self):
        x, y = self.rect.topleft
        frame = self.get_current_frame()
        surface = self.display_surface
        groove = self.groove
        for dx, dy in self.parent.parent.parent.get_corners():
            surface.blit(frame, (x + dx, y + dy))
            surface.blit(groove, (x + dx, y + dy))
54.196.103.26
54.196.103.26
54.196.103.26
 
June 5, 2016

↠ RSS Feed ↞