from os import listdir
from os.path import join

from pygame.mixer import Channel, Sound, music, find_channel

from GameChild import *
from Input import *

class Audio(GameChild):

    current_channel = None
    paused = False
    muted = False

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.delegate = self.get_delegate()
        self.load_fx()
        self.subscribe(self.respond)

    def load_fx(self):
        fx = {}
        if self.get_configuration().has_option("audio", "sfx-path"):
            root = self.get_resource("audio", "sfx-path")
            if root:
                for name in listdir(root):
                    fx[name.split(".")[0]] = Sound(join(root, name))
        self.fx = fx

    def respond(self, event):
        if self.delegate.compare(event, "mute"):
            self.mute()

    def mute(self):
        self.muted = True
        self.set_volume()

    def unmute(self):
        self.muted = False
        self.set_volume()

    def set_volume(self):
        volume = int(not self.muted)
        music.set_volume(volume)
        if self.current_channel:
            self.current_channel.set_volume(volume)

    def play_bgm(self, path, stream=False):
        self.stop_current_channel()
        if stream:
            music.load(path)
            music.play(-1)
        else:
            self.current_channel = Sound(path).play(-1)
        self.set_volume()

    def stop_current_channel(self):
        music.stop()
        if self.current_channel:
            self.current_channel.stop()
        self.current_channel = None
        self.paused = False

    def play_fx(self, name, panning=.5):
        if not self.muted:
            channel = find_channel(True)
            if panning != .5:
                offset = 1 - abs(panning - .5) * 2
                if panning < .5:
                    channel.set_volume(1, offset)
                else:
                    channel.set_volume(offset, 1)
            channel.play(self.fx[name])

    def pause(self):
        channel = self.current_channel
        paused = self.paused
        if paused:
            music.unpause()
            if channel:
                channel.unpause()
        else:
            music.pause()
            if channel:
                channel.pause()
        self.paused = not paused

    def is_bgm_playing(self):
        current = self.current_channel
        if current and current.get_sound():
            return True
        return music.get_busy()
import os
delattr(os, "link")

from ball_cup.pgfw.Setup import Setup

if __name__ == "__main__":
    Setup().setup()
from _send.pgfw.SetupWin import SetupWin

if __name__ == "__main__":
    SetupWin().setup()
from _send.pgfw.Configuration import TypeDeclarations

class Types(TypeDeclarations):

    additional_defaults = {

        "display": {"path": "font-path"},

        "tartan": {"path": "path",

                   "float": "ratio-to-ball",

                   "int": ["thread-size", "sample-size"]},

        "title": {"path": ["channel-audio", "stream-audio"],

                  "float": ["pan-frequency", "lead-volume", "beat-volume"],

                  "int": ["arrow-overlap", "arrow-count", "arrow-saturation"],

                  "int-list": ["arrow-size", "arrow-hue", "background-offset"]},

        "arrow": {"int": "frame-count"},

        "static": {"path": "path",

                   "float": ["frequency", "volume"]},

        "fields": {"path": ["default-path", "custom-path"],

                   "list": "palette-base",

                   "float": "music-initial-volume"},

        "sideline": {"float": "proportion"},

        "cloth": {"float": "scroll-speed"},

        "ball": {"int-list": "base-velocity-range",

                 "int": "base-size",

                 "float": "base-deceleration"},

        "charge": {"int": ["peak-time", "margin"],

                   "int-list": ["transparent-color", "size-limits"],

                   "list": "colors"},

        "cup": {"int-list": ["color", "size-range"],

                "float": "size-range",

                "int": ["margin-vertical", "margin-right"]},

        "result": {"list": ["text", "colors"],

                   "int": ["margin", "font-size", "framerate"],

                   "float": "main-color-probability"},

        "scoreboard": {"int": ["height", "margin-top", "score-segment-width",
                               "score-border-width"],

                       "int-list": "score-border-color"},

        "life-meter": {"int": ["initial-lives", "max-lives"],

                       "path": ["heart-path", "miss-path"]},

        "score": {"path": "path"}

        }
from pygame.mixer import Sound

class SoundEffect(Sound):

    def __init__(self, path, volume):
        Sound.__init__(self, path)
        self.set_volume(volume)

from _send.pgfw.Game import Game
from _send.Types import Types
from _send.field.Fields import Fields
from _send.tartan.Tartans import Tartans
from _send.title.Title import Title
from _send.Editor import Editor

class Send(Game):

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

    def draw_sample_tiles(self):
        from pygame import Surface
        from pygame.image import save
        for name, tartan in self.tartans.iteritems():
            surface = Surface((100, 100))
            tile = tartan.generate(.2)
            for x in xrange(0, surface.get_width(), tile.get_width()):
                for y in xrange(0, surface.get_height(), tile.get_height()):
                    surface.blit(tile, (x, y))
            save(surface, "/tmp/%s.png" % \
                 tartan.get_filesystem_formatted_name())

    def set_children(self):
        Game.set_children(self)
        self.fields = Fields(self)
        self.tartans = Tartans(self)
        self.title = Title(self)
        if self.check_command_line(self.get_configuration("editor", "flag")):
            self.editor = Editor(self)

    def update(self):
        self.title.update()
        self.fields.update()
54.80.81.223
54.80.81.223
54.80.81.223
 
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 ↞