from os import listdir
from os.path import join

from pygame.mixer import Channel, Sound, music, find_channel

from GameChild import *
from Input import *

class Audio(GameChild):

    current_channel = None
    paused = False
    muted = False

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.delegate = self.get_delegate()

    def load_fx(self):
        fx = {}
        if self.get_configuration().has_option("audio", "sfx-path"):
            root = self.get_resource("audio", "sfx-path")
            if root:
                for name in listdir(root):
                    fx[name.split(".")[0]] = Sound(join(root, name))
        self.fx = fx

    def respond(self, event):
        if, "mute"):

    def mute(self):
        self.muted = True

    def unmute(self):
        self.muted = False

    def set_volume(self):
        volume = int(not self.muted)
        if self.current_channel:

    def play_bgm(self, path, stream=False):
        if stream:
            self.current_channel = Sound(path).play(-1)

    def stop_current_channel(self):
        if self.current_channel:
        self.current_channel = None
        self.paused = False

    def play_fx(self, name, panning=.5):
        if not self.muted:
            channel = find_channel(True)
            if panning != .5:
                offset = 1 - abs(panning - .5) * 2
                if panning < .5:
                    channel.set_volume(1, offset)
                    channel.set_volume(offset, 1)

    def pause(self):
        channel = self.current_channel
        paused = self.paused
        if paused:
            if channel:
            if channel:
        self.paused = not paused

    def is_bgm_playing(self):
        current = self.current_channel
        if current and current.get_sound():
            return True
        return music.get_busy()
from ld25.pgfw.Setup import Setup

if __name__ == "__main__":
from pgfw.SetupWin import SetupWin

if __name__ == "__main__":
from antidefense.pgfw.Configuration import TypeDeclarations

class Types(TypeDeclarations):

    additional_defaults = {
        "map": {

            "int": "magnitude"},

        "stamps": {

            "int": ["tile-size", "count", "resolution", "max-magnification",
            "list": ["palette-0", "palette-1", "palette-2", "palette-3",
                     "palette-4", "palette-5", "palette-6", "palette-7",
            "float-list": "projection-vector"},

        "scale": {

            "int-list": ["bar-dimensions", "offset"],
            "list": ["prefixes", "colors"],
            "int": ["resolution", "segments", "font-size", "font-padding",
                    "bar-alpha", "stroke-size"]}

from time import sleep

import pygame

from antidefense.pgfw.Game import Game
from antidefense.Types import Types
from import Map

class Antidefense(Game):

    def __init__(self):
        Game.__init__(self, type_declarations=Types())

    def set_children(self):
        Game.set_children(self) = Map(self)

    def update(self):
        self.get_screen().fill((0, 0, 255), (153, 222, 60, 45))
from time import time
from random import choice

from pygame import Surface, Color

from antidefense.pgfw.GameChild import GameChild

class Layer(GameChild, Surface):

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

    def init_surface(self):
        Surface.__init__(self, self.parent.get_size())

    def randomize(self):
        w, h = self.get_size()
        parent = self.parent
        stamps = parent.stamps.get_stamps(parent.get_zoom_level())
        step = stamps[0].get_width()
        start = time()
        for y in range(0, h, step):
            for x in range(0, w, step):
                self.blit(choice(stamps), (x, y))
        print time() - start
from math import sqrt
from random import choice, randint

from pygame import Color, Surface

from antidefense.pgfw.GameChild import GameChild

class Stamps(GameChild, list):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.config = self.get_configuration("stamps")

    def reset(self):
        list.__init__(self, [])

    def load_palette(self):
        config = self.config
        resolution = config["section-resolution"]
        parent = self.parent
        w, h = parent.dimensions
        x, y =
        index = int(float(x) / w * resolution) + resolution * \
                int(float(y) / h * resolution)
        self.palette = map(Color, config["palette-" + str(index)])

    def populate(self):
        config = self.config
        resolution = config["resolution"]
        max_magnification = config["max-magnification"]
        magnification_step = float(max_magnification) / resolution
        magnification = 1
        for ii in range(resolution):
            while len(self[ii]) < config["count"]:
                saturation = float(ii) / resolution
            magnification += magnification_step

    def build_stamp(self, saturation, magnification):
        size = self.config["tile-size"] * magnification
        stamp = Surface((size, size))
        self.randomize_stamp(stamp, saturation, magnification)
        return stamp

    def randomize_stamp(self, stamp, saturation, magnification):
        w, h = stamp.get_size()
        for y in range(0, h, magnification):
            for x in range(0, w, magnification):
                          (x, y, magnification, magnification))
    def get_random_color(self, saturation):
        color = choice(self.palette)
        pr, pg, pb = self.config["projection-vector"]
        r, g, b = color[0], color[1], color[2]
        p = sqrt(r ** 2 * pr + g ** 2 * pg + b ** 2 * pb)
        r = int(p + (r - p) * saturation)
        g = int(p + (g - p) * saturation)
        b = int(p + (b - p) * saturation)
        return self.convert_rgb(r, g, b)

    def convert_rgb(self, r, g, b):
        rgb = [hex(x)[2:].zfill(2) for x in (r, g, b)]
        return Color("#" + "".join(rgb))

    def get_stamps(self, zoom_level):
        return self[int((len(self) - 1) * zoom_level)]
June 29, 2013

A few weeks ago, for Fishing Jam, I made a fishing simulation from what was originally designed to be a time attack arcade game. In the program, Dark Stew, the player controls Aphids, an anthropod who fishes for aquatic creatures living in nine pools of black water.

Fishing means waiting by the pool with the line in. The longer you wait before pulling the line out, the more likely a creature will appear. Aside from walking, it's the only interaction in the game. The creatures are drawings of things you maybe could find underwater in a dream.

The background music is a mix of clips from licensed to share songs on the Free Music Archive. Particularly, Seed64 is an album I used a lot of songs from. The full list of music credits is in the game's README file.

I'm still planning to use the original design in a future version. There would be a reaction-based mini game for catching fish, and the goal would be to catch as many fish as possible within the time limit. I also want to add details and obstacles to the background, which is now a little boring, being a plain, tiled, white floor.

If you want to look at all the drawings or hear the music in the context of the program, there are Windows and source versions available. The source should work on any system with Python and Pygame. If it doesn't, bug reports are much appreciated. Comments are also welcome :)

Dark Stew: Windows, Pygame Source

I wrote in my last post that I would be working on an old prototype about searching a cloud for organisms for Fishing Jam. I decided to wait a while before developing that game, tentatively titled Xenographic Barrier. Its main interactive element is a first-person scope/flashlight, so I'd like to make a Wii version of it.

I'm about to start working on a complete version of Ball & Cup. If I make anything interesting for it, I'll post something. There are a lot of other things I want to write about, like game analyses, my new GP2X and arcades in Korea, and there's still music to release. Lots of fun stuff coming!