from ld25.pgfw.Setup import Setup

if __name__ == "__main__":
    Setup().setup()
from ld25.pgfw.Configuration import TypeDeclarations
from ld25.pgfw.Game import Game

class LD25(Game):

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

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

    def update(self):
        self.get_screen().fill((0, 0, 255));


class Types(TypeDeclarations):

    additional_defaults = {};
from time import time

from pygame import event, joystick as joy, key as keyboard
from pygame.locals import *

from GameChild import *

class Input(GameChild):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.last_mouse_down_left = None
        self.joystick = Joystick()
        self.unsuppress()
        self.subscribe_to_events()
        self.build_key_map()

    def subscribe_to_events(self):
        self.subscribe_to(KEYDOWN, self.translate_key_press)
        self.subscribe_to(JOYBUTTONDOWN, self.translate_joy_button)
        self.subscribe_to(JOYAXISMOTION, self.translate_axis_motion)
        self.subscribe_to(MOUSEBUTTONDOWN, self.translate_mouse_input)
        self.subscribe_to(MOUSEBUTTONUP, self.translate_mouse_input)

    def suppress(self):
        self.suppressed = True

    def unsuppress(self):
        self.suppressed = False

    def build_key_map(self):
        key_map = {}
        for command, keys in self.get_configuration().items("keys"):
            key_map[command] = []
            if type(keys) == str:
                keys = [keys]
            for key in keys:
                key_map[command].append(globals()[key])
        self.key_map = key_map

    def translate_key_press(self, evt):
        self.print_debug("You pressed {0}, suppressed => {1}".\
                         format(evt.key, self.suppressed))
        if not self.suppressed:
            key = evt.key
            for cmd, keys in self.key_map.iteritems():
                if key in keys:
                    self.post_command(cmd)

    def post_command(self, cmd, **kwargs):
        config = self.get_configuration().get_section("event")
        eid = self.get_custom_event_id()
        self.print_debug("Posting {0} command with id {1}".format(cmd, eid))
        name = config["command-event-name"]
        event.post(event.Event(eid, name=name, command=cmd, **kwargs))

    def translate_joy_button(self, evt):
        if not self.suppressed:
            button = evt.button
            config = self.get_configuration().get_section("joy")
            if button == config["advance"]:
                self.post_command("advance")
            if button == config["pause"]:
                self.post_command("pause")

    def translate_axis_motion(self, evt):
        if not self.suppressed:
            axis = evt.axis
            value = evt.value
            if axis == 1:
                if value < 0:
                    self.post_command("up")
                elif value > 0:
                    self.post_command("down")
            else:
                if value > 0:
                    self.post_command("right")
                elif value < 0:
                    self.post_command("left")

    def is_command_active(self, command):
        if not self.suppressed:
            joystick = self.joystick
            if self.is_key_pressed(command):
                return True
            if command == "up":
                return joystick.is_direction_pressed(Joystick.up)
            elif command == "right":
                return joystick.is_direction_pressed(Joystick.right)
            elif command == "down":
                return joystick.is_direction_pressed(Joystick.down)
            elif command == "left":
                return joystick.is_direction_pressed(Joystick.left)

    def is_key_pressed(self, command):
        poll = keyboard.get_pressed()
        for key in self.key_map[command]:
            if poll[key]:
                return True

    def translate_mouse_input(self, evt):
        button = evt.button
        pos = evt.pos
        post = self.post_command
        if evt.type == MOUSEBUTTONDOWN:
            if button == 1:
                last = self.last_mouse_down_left
                if last:
                    limit = self.get_configuration("mouse",
                                                   "double-click-time-limit")
                    if time() - last < limit:
                        post("mouse-double-click-left", pos=pos)
                last = time()
                self.last_mouse_down_left = last
                post("mouse-down-left", pos=pos)
            elif button == 2:
                post("mouse-down-middle", pos=pos)
            elif button == 3:
                post("mouse-down-right", pos=pos)
            elif button == 4:
                post("mouse-scroll-up", pos=pos)
            elif button == 5:
                post("mouse-scroll-down", pos=pos)
        elif evt.type == MOUSEBUTTONUP:
            if button == 1:
                post("mouse-up-left", pos=pos)
            elif button == 2:
                post("mouse-up-middle", pos=pos)
            elif button == 3:
                post("mouse-up-right", pos=pos)

    def get_axes(self):
        axes = {}
        for direction in "up", "right", "down", "left":
            axes[direction] = self.is_command_active(direction)
        return axes


class Joystick:

    (up, right, down, left) = range(4)

    def __init__(self):
        js = None
        if joy.get_count() > 0:
            js = joy.Joystick(0)
            js.init()
        self.js = js

    def is_direction_pressed(self, direction):
        js = self.js
        if not js or direction > 4:
            return False
        if direction == 0:
            return js.get_axis(1) < 0
        elif direction == 1:
            return js.get_axis(0) > 0
        elif direction == 2:
            return js.get_axis(1) > 0
        elif direction == 3:
            return js.get_axis(0) < 0
from pygame import font

from GameChild import *

class Font(font.Font, GameChild):

    def __init__(self, parent, size):
        GameChild.__init__(self, parent)
        font.Font.__init__(self, self.get_resource("font-path"), size)
3.215.182.36
3.215.182.36
3.215.182.36
 
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.