from pygame.key import get_pressed, get_mods
from pygame.font import Font
from pygame.locals import *

from esp_hadouken.pgfw.GameChild import GameChild

class Calibrator(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_screen()
        self.font = Font(self.parent.font_path, 10)
        self.delegate = self.get_delegate()
        self.load_configuration()
        self.render()
        self.place()
        self.subscribe(self.respond, KEYDOWN)

    def load_configuration(self):
        config = self.get_configuration("engine")
        self.step = config["calibrator-step"]

    def render(self):
        string = str(self)
        self.text = self.font.render(string, False, (0, 0, 0), (255, 255, 255))
        self.string = string

    def __str__(self):
        engine = self.parent
        accelerator = engine.accelerator
        pattern = "v {0:.2f} a {1:.2f} r {2:.2f} t {3:.2f} pa {4:.2f} " + \
                  "pd {5:.2f} lna {6:.2f} lnd {7:.2f} hna {8:.2f} d {9:.2f}"
        return pattern.format(engine.max_velocity, accelerator.attack,
                              accelerator.release, accelerator.initial_thrust,
                              accelerator.peak_acceleration,
                              accelerator.peak_distance,
                              accelerator.min_negative_acceleration,
                              accelerator.min_negative_acceleration_distance,
                              accelerator.max_negative_acceleration,
                              engine.deceleration)

    def place(self):
        rect = self.text.get_rect()
        rect.bottomleft = self.display_surface.get_rect().bottomleft
        self.rect = rect

    def respond(self, event):
        if self.parent.parent.is_active():
            if get_mods() & KMOD_CTRL and event.key == K_COMMA:
                profile = self.parent.profile
                profile.add(increment_index=True)
                profile.write()

    def update(self):
        self.calibrate()
        self.draw()

    def calibrate(self):
        state = get_pressed()
        step = self.step
        engine = self.parent
        accelerator = engine.accelerator
        if state[K_1]:
            engine.max_velocity += step
        if state[K_q]:
            engine.max_velocity -= step
        if state[K_2]:
            accelerator.attack += step
        if state[K_w]:
            accelerator.attack -= step
        if state[K_3]:
            accelerator.release += step
        if state[K_e]:
            accelerator.release -= step
        if state[K_4]:
            accelerator.initial_thrust += step
        if state[K_r]:
            accelerator.initial_thrust -= step
        if state[K_5]:
            accelerator.peak_acceleration += step
        if state[K_t]:
            accelerator.peak_acceleration -= step
        if state[K_6]:
            accelerator.peak_distance += step
        if state[K_y]:
            accelerator.peak_distance -= step
        if state[K_7]:
            accelerator.min_negative_acceleration += step
        if state[K_u]:
            accelerator.min_negative_acceleration -= step
        if state[K_8]:
            accelerator.min_negative_acceleration_distance += step
        if state[K_i]:
            accelerator.min_negative_acceleration_distance -= step
        if state[K_9]:
            accelerator.max_negative_acceleration += step
        if state[K_o]:
            accelerator.max_negative_acceleration -= step
        if state[K_0]:
            engine.deceleration += step
        if state[K_p]:
            engine.deceleration -= step

    def draw(self):
        if self.string != str(self):
            self.render()
        self.display_surface.blit(self.text, self.rect)
from esp_hadouken.pgfw.GameChild import GameChild

class Profile(GameChild, list):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.delegate = self.get_delegate()
        self.load_configuration()
        self.load()
        self.apply()
        self.subscribe(self.respond)

    def load_configuration(self):
        self.path = self.get_resource("engine", "profile-path")

    def load(self):
        list.__init__(self)
        for line in file(self.path):
            self.add(line.split())
        self.index = 0

    def add(self, values=None, increment_index=False):
        if not values:
            engine = self.parent
            accelerator = engine.accelerator
            values = "NAME-ME", engine.max_velocity, accelerator.attack, \
                     accelerator.release, accelerator.initial_thrust, \
                     accelerator.peak_acceleration, accelerator.peak_distance, \
                     accelerator.min_negative_acceleration, \
                     accelerator.min_negative_acceleration_distance, \
                     accelerator.max_negative_acceleration, \
                     engine.deceleration, 1
        self.append([values[0]] + map(float, values[1:-1]) + \
                    [bool(int(values[-1]))])
        if increment_index:
            self.increment_index()


    def apply(self):
        engine = self.parent
        profile = self[self.index]
        engine.set(profile[1], profile[-2])
        engine.accelerator.set(profile[2:-2])

    def respond(self, event):
        if self.parent.parent.is_active():
            if self.delegate.compare(event, "select"):
                self.rotate()

    def rotate(self):
        self.set_next_active()
        self.apply()

    def set_next_active(self):
        while True:
            self.increment_index()
            if self[self.index][-1]:
                break

    def increment_index(self):
        index = self.index + 1
        if index >= len(self):
            index = 0
        self.index = index

    def write(self):
        stream = file(self.path, "w")
        for profile in self:
            stream.write(" ".join(map(str, profile[:-1]) + \
                                  [str(int(profile[-1]))]) + "\n")
from esp_hadouken.pgfw.GameChild import GameChild
from esp_hadouken.pgfw.Vector import Vector
from esp_hadouken.dot.engine.accelerator.Pedal import Pedal

class Accelerator(GameChild, list):

    N, NE, E, SE, S, SW, W, NW = range(8)

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.input = self.get_input()
        self.load_configuration()
        self.init_list()

    def load_configuration(self):
        config = self.get_configuration("engine")
        self.display_flag = config["accelerator-display-flag"]

    def init_list(self):
        list.__init__(self, [Pedal(self, ii) for ii in range(8)])

    def set(self, values):
        self.attack = values[0]
        self.release = values[1]
        self.initial_thrust = values[2]
        self.peak_acceleration = values[3]
        self.peak_distance = values[4]
        self.min_negative_acceleration = values[5]
        self.min_negative_acceleration_distance = values[6]
        self.max_negative_acceleration = values[7]

    def set_slopes(self):
        self.apply_to_pedals("set_slopes")

    def apply_to_pedals(self, method):
        for pedal in self:
            getattr(pedal, method)()

    def reset(self):
        self.apply_to_pedals("reset")

    def update(self):
        S, E, N, W = self.input.get_axes().values()
        self[self.N].update(N and not W and not E)
        self[self.NE].update(N and E)
        self[self.E].update(E and not N and not S)
        self[self.SE].update(E and S)
        self[self.S].update(S and not E and not W)
        self[self.SW].update(S and W)
        self[self.W].update(W and not S and not N)
        self[self.NW].update(W and N)

    def get_sum(self):
        total = Vector()
        for pedal in self:
            total += pedal
        return total
34.203.28.212
34.203.28.212
34.203.28.212
 
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!


↠ RSS Feed ↞