import pygame
from pygame.locals import *

from GameChild import GameChild
from Mainloop import Mainloop
from Audio import Audio
from Display import Display
from Configuration import Configuration
from Delegate import Delegate
from Input import Input
from ScreenGrabber import ScreenGrabber
from Profile import Profile
from VideoRecorder import VideoRecorder
from Interpolator import Interpolator
from TimeFilter import TimeFilter

class Game(GameChild):

    resource_path = None

    def __init__(self, config_rel_path=None, type_declarations=None):
        self.profile = Profile(self)
        self.config_rel_path = config_rel_path
        self.type_declarations = type_declarations
        self.subscribe(self.end, QUIT)

    def set_configuration(self):
        self.configuration = Configuration(self.config_rel_path,

    def set_children(self):
        self.time_filter = TimeFilter(self)
        self.delegate = Delegate(self)
        self.display = Display(self)
        self.mainloop = Mainloop(self)
        self.input = Input(self) = Audio(self)
        self.screen_grabber = ScreenGrabber(self)
        self.video_recorder = VideoRecorder(self)
        self.interpolator = Interpolator(self)

    def frame(self):
        if not self.interpolator.is_gui_active():
        if self.video_recorder.requested:

    def run(self):

    def update(self):

    def blit(self, source, destination, area=None, special_flags=0):
        self.get_screen().blit(source, destination, area, special_flags)

    def get_rect(self):
        return self.get_screen().get_rect()

    def end(self, evt):
        if evt.type == QUIT or, "quit"):
from os import makedirs
from os.path import exists, join
from tempfile import TemporaryFile
from time import strftime

from pygame.image import tostring, frombuffer, save
from pygame.time import get_ticks

from GameChild import GameChild

class VideoRecorder(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        if self.requested:
            self.display_surface = self.get_display_surface()
            self.delegate = self.get_delegate()

    def set_requested(self):
        self.requested = self.get_configuration("video-recordings")["enable"] \
                         or self.check_command_line("-enable-video")

    def load_configuration(self):
        config = self.get_configuration("video-recordings")
        self.root = config["path"]
        self.directory_name_format = config["directory-name-format"]
        self.file_extension = config["file-extension"]
        self.frame_format = config["frame-format"]
        self.framerate = config["framerate"]

    def reset(self):
        self.recording = False
        self.frame_length = None
        self.frames = None
        self.last_frame = 0

    def respond(self, event):
        compare =
        if compare(event, "record-video"):
        elif compare(event, "reset-game"):

    def toggle_record(self):
        recording = not self.recording
        if recording:
            self.frame_length = len(self.get_string())
            self.frames = TemporaryFile()
        self.recording = recording

    def get_string(self):
        return tostring(self.display_surface, self.frame_format)

    def write_frames(self):
        root = join(self.root, strftime(self.directory_name_format))
        if not exists(root):
        size = self.display_surface.get_size()
        frames = self.frames
        for ii, frame in enumerate(iter(lambda:,
            path = join(root, "%04i.png" % ii)
            save(frombuffer(frame, size, self.frame_format), path)
        print "wrote video frames to " + root

    def update(self):
        ticks = get_ticks()
        if self.recording and ticks - self.last_frame >= self.framerate:
            self.last_frame = ticks
from pygame.time import get_ticks

from GameChild import GameChild

class TimeFilter(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.ticks = self.unfiltered_ticks = self.last_ticks = get_ticks()

    def close(self):
        self.closed = True

    def open(self):
        self.closed = False

    def get_ticks(self):
        return self.ticks

    def get_unfiltered_ticks(self):
        return self.unfiltered_ticks

    def get_last_ticks(self):
        return self.last_ticks

    def get_last_frame_duration(self):
        return self.last_frame_duration

    def update(self):
        ticks = get_ticks()
        self.last_frame_duration = duration = ticks - self.last_ticks
        if not self.closed:
            self.ticks += duration
        self.unfiltered_ticks += duration
        self.last_ticks = ticks
class Vector(list):

    def __init__(self, x=0, y=0):
        list.__init__(self, (x, y))

    def __getattr__(self, name):
        if name == "x":
            return self[0]
        elif name == "y":
            return self[1]

    def __setattr__(self, name, value):
        if name == "x":
            self[0] = value
        elif name == "y":
            self[1] = value
            list.__setattr__(self, name, value)

    def __add__(self, other):
        return Vector(self.x + other[0], self.y + other[1])

    __radd__ = __add__

    def __iadd__(self, other):
        self.x += other[0]
        self.y += other[1]
        return self

    def __sub__(self, other):
        return Vector(self.x - other[0], self.y - other[1])

    def __rsub__(self, other):
        return Vector(other[0] - self.x, other[1] - self.y)

    def __isub__(self, other):
        self.x -= other[0]
        self.y -= other[1]
        return self

    def __mul__(self, other):
        return Vector(self.x * other, self.y * other)

    __rmul__ = __mul__

    def __imul__(self, other):
        self.x *= other
        self.y *= other
        return self

    def apply_to_components(self, function):
        self.x = function(self.x)
        self.y = function(self.y)

    def place(self, x=None, y=None):
        if x is not None:
            self.x = x
        if y is not None:
            self.y = y

    def move(self, dx=0, dy=0):
        if dx:
            self.x += dx
        if dy:
            self.y += dy

    def place_at_origin(self):
        self.x = 0
        self.y = 0
July 19, 2017

f1. BOSS

Games are corrupt dissolutions of nature modeled on prison, ordering a census from the shadows of a vile casino, splintered into shattered glass, pushing symbols, rusted, stale, charred, ultraviolet harbingers of consumption and violence, badges without merit that host a disease of destruction and decay.

You are trapped. You are so trapped your only recourse of action is to imagine an escape route and deny your existence so fully that your dream world becomes the only reality you know. You are fleeing deeper and deeper into a chasm of self-delusion.

While you're dragging your listless, distending corpus from one cell to another, amassing rewards, upgrades, bonuses, achievements, prizes, add-ons and status boosts in rapid succession, stop to think about what's inside the boxes because each one contains a vacuous, soul-sucking nightmare.

Playing can be an awful experience that spirals one into a void of harm and chaos, one so bad it creates a cycle between the greater and lesser systems, each breaking the other's rules. One may succeed by acting in a way that ruins the world.

↠ RSS Feed ↞