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))
December 3, 2013

Where in the mind's prism does light shine, inward, outward, or backward, and where in a plane does it intersect, experientially and literally, while possessing itself in a dripping wet phantasm?

Fig 1.1 What happens after you turn on a video game and before it appears?

The taxonomy of fun contains the difference between gasps of desperation and exaltation, simultaneously identical and opposite; one inspires you to have sex, while the other to ejaculate perpetually. A destruction and its procession are effervescent, while free play is an inseminated shimmer hatching inside you. Unlikely to be resolved, however, in such a way, are the climaxes of transitions between isolated, consecutive game states.

You walk through a door or long-jump face first (your face, not Mario's) into a painting. A moment passes for eternity, viscerally fading from your ego, corpus, chakra, gaia, the basis of your soul. It happens when you kill too, and especially when you precisely maim or obliterate something. It's a reason to live, a replicating stasis.

Fig 1.2 Sequence in a video game

Video games are death reanimated. You recurse through the underworld toward an illusion. Everything in a decision and logic attaches permanently to your fingerprint. At the core, you use its energy to soar, comatose, back into the biosphere, possibly because the formal structure of a mind by human standards is useful in the next world.

↠ RSS Feed ↞