from random import choice, randrange

from pygame import Surface
from pygame.mixer import Sound

from _send.pgfw.Sprite import Sprite
from _send.Send import SoundEffect

class Cup(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.set_frame()
        self.set_color()
        self.direction = choice((1, -1))
        self.moving = True
        self.wall_audio = SoundEffect(self.get_resource("cup", "wall-audio"),
                                      .8)

    def set_frame(self):
        size = self.get_size()
        surface = Surface((size, size))
        self.add_frame(surface)
        self.place()
        self.align()

    def get_size(self):
        return self.parent.cup_scale * self.display_surface.get_height() * \
               (1 - self.get_configuration("sideline", "proportion") * 2)

    def place(self):
        sidelines = self.parent.parent.sidelines
        self.rect.top = randrange(sidelines[0].bottom,
                                  sidelines[1].top - self.rect.h)

    def align(self):
        self.rect.right = self.display_surface.get_rect().right

    def set_color(self):
        self.color = self.parent.get_foreground_color()
        self.paint()

    def paint(self):
        self.get_current_frame().fill(self.color)

    def stop(self):
        self.moving = False

    def update(self):
        if self.moving:
            self.move(dy=self.parent.speed * self.direction)
            self.collide()
        Sprite.update(self)

    def collide(self):
        for sideline in self.parent.parent.sidelines:
            if self.location.colliderect(sideline):
                self.direction *= -1
                self.move(dy=sideline.clip(self.location).h * self.direction)
                self.wall_audio.play()
from pygame import Color, Surface, Rect
from pygame.time import get_ticks
from pygame.draw import circle
from pygame.mixer import Sound

from _send.pgfw.GameChild import GameChild
from _send.Send import SoundEffect

class Charge(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.delegate = self.get_game().delegate
        self.display_surface = self.get_display_surface()
        self.charging_audio = SoundEffect(self.get_resource("charge",
                                                            "charging-audio"),
                                          .55)
        self.send_audio = SoundEffect(self.get_resource("charge",
                                                        "send-audio"), .1)
        self.load_configuration()
        self.subscribe(self.respond)
        self.reset()

    def load_configuration(self):
        config = self.get_configuration("charge")
        self.transparent_color = Color(*config["transparent-color"])
        self.colors = tuple(Color(color + "ff") for color in config["colors"])
        self.peak_time = config["peak-time"]
        self.size_limits = config["size-limits"]
        self.margin = config["margin"]

    def respond(self, event):
        fields = self.parent
        if not fields.loading and not fields.suppressing_input and \
               fields.get_current_field():
            if not self.sent and self.delegate.compare(event, "charge"):
                self.charging = True
                self.start = get_ticks()
            elif self.charging and self.delegate.compare(event, "charge", True):
                self.sent = True
                self.charging = False
                self.parent.get_current_field().ball.launch(self.get_strength())
                self.send_audio.play()

    def reset(self):
        self.charging = False
        self.start = None
        self.sent = False
        self.color_index = 0
        self.last_strength = None

    def get_strength(self):
        return float((get_ticks() - self.start) % self.peak_time) / \
               self.peak_time

    def update(self):
        if not self.sent and self.charging:
            self.increment_color_index()
            lower, upper = 4, 150
            if self.last_strength is None or \
                   self.last_strength > self.get_strength():
                self.charging_audio.play()
            strength = self.last_strength = self.get_strength()
            width = strength * (upper - lower) + lower
            lower, upper = 1, 22
            height = strength * (upper - lower) + lower
            rect = Rect(0, 0, width, height)
            rect.midbottom = self.parent.sidelines[1].midtop
            self.display_surface.fill(self.get_color(), rect)

    def increment_color_index(self):
        self.color_index += 1
        if self.color_index == len(self.colors):
            self.color_index = 0

    def get_color(self):
        return self.colors[self.color_index]
from pygame import Surface
from pygame.mixer import Sound

from _send.pgfw.Sprite import Sprite
from _send.Send import SoundEffect

class Ball(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.set_frame()
        self.set_color()
        self.adjust_for_size()
        self.reset()
        self.reflect_audio = SoundEffect(self.get_resource("ball",
                                                           "reflect-audio"),
                                         .35)

    def set_frame(self):
        size = self.get_size()
        surface = Surface((size, size))
        self.add_frame(surface)
        self.center()

    def get_size(self):
        return self.parent.ball_scale * self.display_surface.get_height() * \
               (1 - self.get_configuration("sideline", "proportion") * 2)

    def center(self):
        self.rect.centery = self.display_surface.get_rect().centery

    def set_color(self):
        self.color = self.parent.get_foreground_color()
        self.paint()

    def paint(self):
        self.get_current_frame().fill(self.color)

    def adjust_for_size(self):
        lower, upper = self.get_configuration("ball", "base-velocity-range")
        ratio = self.rect.w / float(self.get_configuration("ball", "base-size"))
        self.velocity_range = ratio * lower, ratio * upper
        self.deceleration = ratio * self.get_configuration("ball",
                                                           "base-deceleration")

    def reset(self):
        self.velocity = 0

    def launch(self, strength):
        lower, upper = self.velocity_range
        self.velocity = strength * (upper - lower) + lower
        self.direction = 1

    def update(self):
        if self.velocity:
            self.move(self.velocity * self.direction)
            if self.rect.right >= self.display_surface.get_rect().right:
                self.direction = -1
                self.move(self.display_surface.get_rect().right - \
                          self.rect.right)
                self.reflect_audio.play()
            self.velocity -= self.deceleration
            if self.velocity < 1 or self.rect.right < 0:
                self.velocity = 0
                self.parent.cup.stop()
                self.parent.parent.result.evaluate()
        Sprite.update(self)
        if self.rect.colliderect(self.parent.cup.location):
            self.display_surface.fill(self.parent.get_background_color(),
                                      self.rect.clip(self.parent.cup.location))
216.73.216.221
216.73.216.221
216.73.216.221
 
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!