from os.path import join

from pygame import Rect
from pygame.image import load
from pygame.transform import flip

from dark_stew.pgfw.Sprite import Sprite

class Rod(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.load_frames()
        self.center = self.display_surface.get_rect().center
        self.load_line()
        self.deactivate()
        self.frames = [self.normal_frame]
        self.measure_rect()

    def load_frames(self):
        image = load(join(self.parent.sitting_path,
                          self.get_configuration("aphids", "rod-path")))
        self.normal_frame = self.fill_colorkey(image)
        self.mirrored_frame = self.fill_colorkey(flip(image, True, False))

    def load_line(self):
        image = load(join(self.parent.sitting_path,
                          self.get_configuration("aphids",
                                                 "line-path"))).convert_alpha()
        self.line = image
        self.line_rect = self.line.get_rect()

    def activate(self, dx, dy, mirror=False):
        self.active = True
        cx, cy = self.center
        self.rect.topleft = cx + dx, cy + dy
        if mirror:
            self.frames = [self.mirrored_frame]
            self.line_rect.topleft = self.rect.topright
        else:
            self.frames = [self.normal_frame]
            self.line_rect.topleft = self.rect.topleft

    def deactivate(self):
        self.active = False

    def draw(self):
        if self.active:
            Sprite.draw(self)
            self.display_surface.blit(self.line, self.line_rect)
from pygame import event, key as keys, mouse
from pygame.locals import *

from GameChild import *
from EventDelegate import *

class Input(GameChild):

    command_event = EventDelegate.command_event
    left_mouse_button = 1

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.subscribe_to_events()

    def subscribe_to_events(self):
        self.subscribe_to(KEYDOWN, self.translate_key_press)
        self.subscribe_to(MOUSEBUTTONDOWN, self.translate_mouse_down)
        self.subscribe_to(MOUSEBUTTONUP, self.translate_mouse_up)
        self.subscribe_to(MOUSEMOTION, self.translate_mouse_motion)

    def translate_key_press(self, evt):
        key = evt.key
        config = self.get_configuration()
        if key in config["keys-quit"]:
            self.post_command("quit")
        if key in config["keys-capture-screen"]:
            self.post_command("capture-screen")
        if key in config["keys-reset"]:
            self.post_command("reset")

    def post_command(self, name):
        EventDelegate.post_event(self.command_event, command=name)

    def translate_mouse_down(self, evt):
        if evt.button == self.left_mouse_button:
            self.post_command("grab")

    def translate_mouse_up(self, evt):
        if evt.button == self.left_mouse_button:
            self.post_command("release")

    def translate_mouse_motion(self, evt):
        if mouse.get_pressed()[0]:
            self.post_command("drag")

    def is_key_pressed(self, identifier):
        poll = keys.get_pressed()
        for key in self.get_configuration()[identifier]:
            if poll[key]:
                return True
import os
import sys
import time

from pygame import image

from GameChild import *
from Input import *

class ScreenGrabber(GameChild):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.subscribe_to(Input.command_event, self.save_display)

    def save_display(self, event):
        if event.command == "capture-screen":
            directory = self.get_resource("capture-path")
            try:
                if not os.path.exists(directory):
                    os.mkdir(directory)
                name = self.build_name()
                path = os.path.join(directory, name)
                capture = image.save(self.get_screen(), path)
                print "Saved screen capture to %s" % directory + name
            except:
                print "Couldn't save screen capture to %s, %s" % \
                      (directory, sys.exc_info()[1])

    def build_name(self):
        config = self.get_configuration()
        prefix = config["capture-file-name-format"]
        extension = config["capture-extension"]
        return time.strftime(prefix) + extension
from pygame import display

from GameChild import *

class Display(GameChild):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.set_screen()
        self.set_caption()

    def set_screen(self):
        configuration = self.get_configuration()
        self.screen = display.set_mode(configuration["display-dimensions"])

    def set_caption(self):
        display.set_caption(self.get_configuration()["game-title"])

    def get_screen(self):
        return self.screen

    def get_size(self):
        return self.screen.get_size()
from os.path import exists, join

from pygame import mixer

import Game

class GameChild:

    def __init__(self, parent=None):
        self.parent = parent

    def get_game(self):
        current = self
        while not isinstance(current, Game.Game):
            current = current.parent
        return current

    def get_configuration(self):
        return self.get_game().get_configuration()

    def get_input(self):
        return self.get_game().get_input()

    def get_screen(self):
        return self.get_game().display.get_screen()

    def get_timer(self):
        return self.get_game().timer

    def get_audio(self):
        return self.get_game().audio

    def get_delegate(self):
        return self.get_game().delegate

    def get_resource(self, key):
        config = self.get_configuration()
        path = config[key]
        if exists(path):
            return path
        else:
            return join(config["media-install-path"], path)

    def subscribe_to(self, kind, callback):
        self.get_game().delegate.add_subscriber(kind, callback)
18.97.9.169
18.97.9.169
18.97.9.169
 
June 29, 2013

A few weeks ago, for Fishing Jam, I made a fishing simulation from what was originally designed to be a time attack arcade game. In the program, Dark Stew, the player controls Aphids, an anthropod who fishes for aquatic creatures living in nine pools of black water.



Fishing means waiting by the pool with the line in. The longer you wait before pulling the line out, the more likely a creature will appear. Aside from walking, it's the only interaction in the game. The creatures are drawings of things you maybe could find underwater in a dream.

The background music is a mix of clips from licensed to share songs on the Free Music Archive. Particularly, Seed64 is an album I used a lot of songs from. The full list of music credits is in the game's README file.

I'm still planning to use the original design in a future version. There would be a reaction-based mini game for catching fish, and the goal would be to catch as many fish as possible within the time limit. I also want to add details and obstacles to the background, which is now a little boring, being a plain, tiled, white floor.

If you want to look at all the drawings or hear the music in the context of the program, there are Windows and source versions available. The source should work on any system with Python and Pygame. If it doesn't, bug reports are much appreciated. Comments are also welcome :)

Dark Stew: Windows, Pygame Source

I wrote in my last post that I would be working on an old prototype about searching a cloud for organisms for Fishing Jam. I decided to wait a while before developing that game, tentatively titled Xenographic Barrier. Its main interactive element is a first-person scope/flashlight, so I'd like to make a Wii version of it.

I'm about to start working on a complete version of Ball & Cup. If I make anything interesting for it, I'll post something. There are a lot of other things I want to write about, like game analyses, my new GP2X and arcades in Korea, and there's still music to release. Lots of fun stuff coming!