from time import time
from random import randint

from pygame import Surface, Color

from antidefense.pgfw.GameChild import GameChild
from antidefense.map.scale.Scale import Scale
from antidefense.map.Layer import Layer
from antidefense.map.Stamps import Stamps

class Map(GameChild, Surface):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.deactivate()
        self.set_surface()
        self.set_dimensions()
        self.subscribe_to(self.get_custom_event_id(), self.respond_to_event)
        self.scale = Scale(self)
        self.stamps = Stamps(self)
        self.reset()

    def deactivate(self):
        self.active = False

    def set_surface(self):
        Surface.__init__(self, self.get_screen().get_size())

    def set_dimensions(self):
        magnitude = self.get_configuration("map", "magnitude")
        self.dimensions = tuple(map(lambda x: x ** magnitude, self.get_size()))

    def respond_to_event(self, evt):
        if evt.command == "reset-game":
            self.reset()

    def reset(self):
        self.visible_dimensions = self.dimensions
        self.scale.update()
        self.set_target()
        self.set_target_pixel()
        self.stamps.reset()
        self.current_layer = Layer(self)

    def set_target(self):
        w, h = self.dimensions
        self.target = randint(0, w - 1), randint(0, h - 1)

    def set_target_pixel(self):
        vx, vy = self.visible_dimensions
        x, y = self.target
        w, h = self.get_screen().get_size()
        self.target_pixel = int(float(x) / vx * w), int(float(y) / vy * h)

    def activate(self):
        self.active = True

    def get_zoom_level(self):
        return 1 - float(self.visible_dimensions[0]) / self.dimensions[0]
        
    def update(self):
        if self.active:
            self.clear()
            self.draw()

    def clear(self):
        self.blit(self.current_layer, (0, 0))

    def draw(self):
        self.scale.draw()
        self.get_screen().blit(self, (0, 0))
from pygame import Surface, Color

from antidefense.pgfw.GameChild import GameChild

class Bar(GameChild, Surface):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.config = self.get_configuration("scale")
        self.init_surface()
        self.set_rect()
        self.paint()

    def init_surface(self):
        config = self.config
        Surface.__init__(self, config["bar-dimensions"])
        self.set_alpha(config["bar-alpha"])

    def set_rect(self):
        rect = self.get_rect()
        rect.bottom = self.parent.get_height()
        self.rect = rect

    def paint(self):
        config = self.config
        colors = map(Color, config["colors"])
        w = self.get_width()
        segment_w = w / config["segments"]
        for ii, x in enumerate(range(0, w, segment_w)):
            color = colors[ii % len(colors)]
            self.fill(color, (x, 0, segment_w, self.get_height()))

    def draw(self):
        self.parent.blit(self, self.rect)
from pygame import Surface, Color
from pygame.locals import *

from antidefense.pgfw.GameChild import GameChild
from antidefense.map.scale.Bar import Bar
from antidefense.map.scale.Text import Text

class Scale(GameChild, Surface):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.config = self.get_configuration("scale")
        self.init_surface()
        self.set_rect()
        self.bar = Bar(self)
        self.text = Text(self)

    def init_surface(self):
        config = self.config
        bar_w, bar_h = config["bar-dimensions"]
        h = bar_h + config["font-size"] + config["font-padding"] * 2
        Surface.__init__(self, (bar_w, h), SRCALPHA)
        self.clear()

    def set_rect(self):
        rect = self.get_rect()
        x, y = self.config["offset"]
        rect.left = x
        rect.bottom = self.parent.get_height() - y
        self.rect = rect

    def update(self):
        self.clear()
        self.text.update()
        self.bar.draw()

    def clear(self):
        self.fill((0, 0, 0, 0))

    def draw(self):
        self.parent.blit(self, self.rect)
from math import log

from pygame import Surface, Color
from pygame.font import Font
from pygame.locals import *

from antidefense.pgfw.GameChild import GameChild

class Text(GameChild, Surface):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.config = self.get_configuration("scale")
        self.init_surface()
        self.set_rect()
        self.set_fonts()
        self.text = ""

    def init_surface(self):
        parent = self.parent
        h = parent.get_height() - self.config["bar-dimensions"][1]
        Surface.__init__(self, (self.parent.get_width(), h), SRCALPHA)

    def set_rect(self):
        self.rect = self.get_rect()

    def set_fonts(self):
        config = self.config
        path = self.get_resource("scale", "font-path")
        font = Font(path, config["font-size"])
        font.set_bold(True)
        self.font = font

    def update(self):
        self.set_text()
        self.clear()
        self.write_text()
        self.draw()

    def set_text(self):
        config = self.config
        grandparent = self.parent.parent
        ratio = float(self.get_width()) / grandparent.get_width()
        distance = ratio * grandparent.visible_dimensions[0]
        magnitude = int(log(distance, 10))
        resolution = config["resolution"]
        interval = magnitude / resolution
        prefix = config["prefixes"][interval]
        converted = int(distance / 10 ** (interval * resolution))
        self.text = ("%i %s%s" % (converted, prefix, config["unit"])).decode("utf-8")

    def clear(self):
        self.fill((0, 0, 0))
        self.fill((0, 0, 0, 0))

    def write_text(self):
        self.write_stroke()
        block = self.font.render(self.text, True,
                                 Color(self.config["font-color"]))
        rect = block.get_rect()
        rect.center = self.rect.center
        self.blit(block, rect)

    def write_stroke(self):
        config = self.config
        font = self.font
        text = self.text
        color = Color(config["stroke-color"])
        offset = config["stroke-offset"]
        left, right = [font.render(text, True, color) for _ in range(2)]
        lrect = left.get_rect()
        center = self.rect.center
        lrect.center = center
        lrect.x -= 1
        self.blit(left, lrect)
        rrect = right.get_rect()
        rrect.center = center
        rrect.x += 1
        self.blit(right, rrect)

    def draw(self):
        self.parent.blit(self, self.rect)
34.239.151.158
34.239.151.158
34.239.151.158
 
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.