from GameChild import GameChild

class Animation(GameChild):

    def __init__(self, parent, method=None, interval=None, unfiltered=False):
        GameChild.__init__(self, parent)
        self.unfiltered = unfiltered
        self.default_method = method or self.build_frame
        self.accounts = {}
        self.register(self.default_method, interval=interval)
        self.current_elapsed = 0
        self.last_update = 0

    def build_frame(self):

    def register(self, *args, **kwargs):
        interval = None
        if kwargs.has_key("interval"):
            interval = kwargs["interval"]
        for method in args:
            if method not in self.accounts:
                self.accounts[method] = Account(interval, self)

    def play(self, method=None, interval=None, delay=0, play_once=False,
        account = self.accounts[self.get_default(method)]
        if interval:

    def get_default(self, method=None):
        if not method:
            method = self.default_method
        return method

    def halt(self, method=None):
        if not method:
            for account in self.accounts.values():
            if self.accounts.has_key(method):

    def is_playing(self, method=None, check_all=False, include_delay=False):
        if check_all:
            return any(self.is_account_playing(account, include_delay) for \
                       method, account in self.accounts.iteritems())
        return self.is_account_playing(self.accounts[self.get_default(method)],

    def is_account_playing(self, account, include_delay):
        return account.playing and (not include_delay or not account.delay)

    def reset_timer(self, method):
        if not method:
            for account in self.accounts.values():

    def update(self):
        for method, account in self.accounts.iteritems():
            if account.update():

class Account:

    def __init__(self, interval, animation):
        self.animation = animation
        self.time_filter = animation.get_game().time_filter
        self.interval_index = 0
        self.last_frame = 0

    def set_interval(self, interval):
        if isinstance(interval, int) or isinstance(interval, str):
            interval = [interval]
        self.interval = interval

    def set_delay(self, delay):
        self.delay = delay

    def set_play_once(self, play_once):
        self.play_once = play_once

    def set_args(self, args):
        self.args = args

    def play(self):
        self.playing = True

    def halt(self):
        self.last_update = None
        self.playing = False

    def update(self):
        if self.playing:
            if self.animation.unfiltered:
                ticks = self.time_filter.get_unfiltered_ticks()
                ticks = self.time_filter.get_ticks()
            if not self.delay:
                interval = self.interval
                if interval:
                    if ticks - self.last_frame < self.get_current_interval():
                        return False
                    self.last_frame = ticks
                if self.play_once:
                return True

    def get_current_interval(self):
        return self.interval[self.interval_index]

    def increment_interval_index(self, increment=1):
        index = self.interval_index + increment
        while index >= len(self.interval):
            index -= len(self.interval)
        self.interval_index = index

    def reset_interval(self):
        self.interval_index = 0

    def reset_timer(self):
        if self.animation.unfiltered:
            ticks = self.time_filter.get_unfiltered_ticks()
            ticks = self.time_filter.get_ticks()
        self.last_frame = ticks

    def update_delay(self, ticks):
        delay = self.delay
        if delay > 0:
            last_update = self.last_update or ticks
            delay -= ticks - last_update
            if delay < 0:
                delay = 0
        self.last_update = ticks
        self.delay = delay
from pygame.event import get, pump, Event, post
from pygame.locals import *

from GameChild import GameChild
from Input import Input

class Delegate(GameChild):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.subscribers = dict()

    def load_configuration(self):
        config = self.get_configuration("event")
        self.cancel_flag_key = config["cancel-flag-key"]
        self.command_key = config["command-key"]
        self.command_event_id = config["command-id-offset"] + \

    def disable(self):
        self.enabled = False

    def enable(self):
        self.enabled = True
        self.interpolator = self.get_game().interpolator

    def dispatch(self):
        if self.enabled:
            subscribers = self.subscribers
            for evt in get():
                kind = evt.type
                if kind in subscribers:
                    for subscriber in subscribers[kind]:
                        if not self.interpolator.is_gui_active() or \
                               hasattr(subscriber, "im_class") and \
                               (subscriber.im_class == Input or \
                                subscriber.im_class == \
                            self.print_debug("Passing %s to %s" % (evt,

    def add_subscriber(self, callback, kind=None):
        self.print_debug("Subscribing %s to %s" % (callback, kind))
        if kind is None:
            kind = self.command_event_id
        subscribers = self.subscribers
        if kind not in subscribers:
            subscribers[kind] = list()

    def is_command(self, event):
        return event.type == self.command_event_id

    def remove_subscriber(self, callback, kind=None):
        if kind is None:
            kind = self.command_event_id

    def compare(self, evt, commands=None, cancel=False, **attributes):
        if self.is_command(evt):
            self.add_cancel_flag_to_attributes(attributes, cancel)
        if commands is not None and not isinstance(commands, list):
            commands = [commands]
        if commands is not None:
            if not self.command_in_list(evt, commands):
                return False
        return all(key in evt.dict and evt.dict[key] == value for \
                   key, value in attributes.iteritems())

    def add_cancel_flag_to_attributes(self, attributes, cancel):
        attributes[self.cancel_flag_key] = cancel

    def command_in_list(self, evt, commands):
        return self.get_command_attribute(evt) in commands

    def get_command_attribute(self, evt):
        return evt.dict[self.command_key]

    def post(self, command=None, cancel=False, **attributes):
        attributes[self.command_key] = command
        self.add_cancel_flag_to_attributes(attributes, cancel)
        post(Event(self.command_event_id, attributes))
September 26, 2017

I made a video about my game Picture Processing for Out of Index 2017! Here is the video along with a transcript.

To save memory, video games are designed to repeat graphics. In raster-based games, image files like textures, tiles and sprites are loaded once into memory and drawn repeatedly by the program to create environments, characters, animations and text. In my puzzle game, 8 by 8 pixel tiles are used to create scenes the player has to recreate. For level 1, the tiles are a cloud, a tree, a mushroom, a character, sky, ground and rock.

An algorithm scrambles the tiles so that each tile is in the wrong memory address at the beginning of a level and the screen looks like a graphics glitch. When level 1 begins, the clouds may be where the trees should be, the mushrooms may be floating in the sky and the character may be switched with rock or the ground. The player's task is to put the tiles where they belong by swapping each tile with a tile in another memory address.

There are five levels, in order of difficulty, based on classic video games or classic video game genres.

The name of this game is taken from the Picture Processing Unit, a microprocessor designed by Nintendo for the Nintendo Entertainment System. The PPU is the hardware component responsible for translating image data into video signals for televisions and screens. It does this with a memory of 8 by 8 pixel tile data, which, along with palette and sprite attribute memory, generates each frame of a video game.

Companies often create lofty, evocative titles for hardware and products. What does the name Picture Processing Unit mean if we consider pictures something independent of a video screen? The phrase picture processing evokes the phrase image processing, a technique used to create applications such as automatic facial and emotion recognition. We often anthropomorphize electronic devices, infusing them with intelligence and souls, forgetting how much more infinitely complex the human mind is compared to a digital processor.

The game is named as a reference to Nintendo's microprocessor because the graphics are tile based, but it is also a reference to the players who are image processors, interpreting a picture from something deterministic into something non-deterministic.

The prototype of this game was created for a game jam called A Game By Its Cover where designers created video games based on imagined Nintendo game cartridges created by visual artists for an exhibition called My Famicase.

Picture Processing is based on one of the imagined cartridges from that exhibition. The cartridge's cover depicts a grid of unordered tiles and is described as a game where one inserts a game cartridge, sees a glitching screen, and meditates about the concept of beauty in imperfection. I added the idea that the player meditates into a state of transcendence until they are able to fix the game's graphics by accessing the memory telepathically.

↠ RSS Feed ↞