from pygame.image import load

from lib.pgfw.pgfw.GameChild import GameChild

class Title(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.delegate = self.get_delegate()
        self.audio = self.get_audio()
        self.load_configuration()
        self.set_background()
        self.subscribe(self.respond)
        self.reset()

    def load_configuration(self):
        config = self.get_configuration("title")
        self.background_path = self.get_resource("title", "background")
        self.audio_path = self.get_resource("title", "audio")

    def set_background(self):
        self.background = load(self.background_path).convert()

    def respond(self, event):
        if self.active:
            if self.delegate.compare(event, "any"):
                self.deactivate()
                self.parent.home.activate()
        if self.activate_queued:
            self.activate()
            self.activate_queued = False

    def reset(self):
        self.activate_queued = False
        self.deactivate()

    def deactivate(self):
        self.active = False
        self.audio.stop_current_channel()

    def activate(self):
        self.active = True
        self.audio.play_bgm(self.audio_path)

    def queue_activation(self):
        self.activate_queued = True

    def update(self):
        if self.active:
            self.display_surface.blit(self.background, (0, 0))
from os.path import join

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

from lib.pgfw.pgfw.Animation import Animation
from food_spring.level.land.Land import Land
from food_spring.level.platform.Platforms import Platforms
from food_spring.level.Food import Food
from food_spring.level.planet.Planet import Planet
from food_spring.level.stars.Stars import Stars
from food_spring.level.drop.Drops import Drops
from food_spring.level.door.Door import Door
from food_spring.level.ExitArrow import ExitArrow
from food_spring.level.obstacle.Obstacles import Obstacles
from food_spring.level.Window import Window

class Level(Animation):

    any_press_ignored = "left"
    transparent_color = 255, 0, 255

    def __init__(self, parent, index, horizontal_drop=False):
        Animation.__init__(self, parent)
        self.index = index
        self.display_surface = self.get_display_surface()
        self.input = self.get_input()
        self.compare = self.get_delegate().compare
        self.audio = self.get_audio()
        self.timer = self.get_game().timer
        self.siphon = self.get_game().siphon
        self.velocity = [0, 0]
        self.time = 0.0
        self.altitude = 0
        self.load_configuration()
        self.assign_defaults()
        self.set_background()
        self.land = Land(self)
        self.planet = Planet(self)
        self.stars = Stars(self)
        self.guns = self.parent.parent.gun_library[index]
        self.drops = Drops(self)
        self.platforms = Platforms(self)
        self.food = Food(self)
        self.door = Door(self)
        self.exit_arrow = ExitArrow(self)
        self.obstacles = Obstacles(self)
        self.window = Window(self)
        self.saved_food_surface = self.food.display_surface
        self.subscribe(self.respond)
        self.register(self.go, self.stall, self.enter, self.transition_to_go,
                      self.exit, self.fade_in_arrow)
        self.deactivate()

    def load_configuration(self):
        config = self.get_configuration("level")
        self.background_color = config["background-color"]
        self.gravity = config["gravity"]
        self.velocity_range = config["velocity"]
        self.stall_length = config["stall"]
        self.fall_pause = config["fall-pause"]
        self.entrance_offset = config["entrance-offset"]
        self.entrance_speed = config["entrance-speed"]
        self.audio_root = config["audio"]

    def assign_defaults(self):
        self.distance = 0.0
        self.velocity[0] = 0.0
        self.time = 0.0
        self.reset_queued = False

    def set_background(self):
        surface = Surface(self.display_surface.get_size())
        surface.fill(self.background_color)
        self.background = surface

    def deactivate(self):
        self.active = False
        self.halt()
        self.input.unregister_any_press_ignore(self.any_press_ignored)
        self.restore_food_surface()
        self.audio.stop_current_channel()

    def restore_food_surface(self):
        self.food.display_surface = self.saved_food_surface

    def respond(self, event):
        if self.compare(event, "reset-game"):
            self.deactivate()
        elif self.active and self.compare(event, "left") and \
                 self.exit_available and self.is_playing(check_all=True):
            self.halt()
            self.timer.stop()
            self.velocity[0] = 0.0
            food = self.food.location
            difference = self.platforms[0].location.right - food.right
            rect = self.get_entrance_mask()[1]
            food.bottomright = rect.w - difference, rect.h
            self.play(self.exit)

    def reset(self):
        self.assign_defaults()
        self.land.reset()
        self.drops.reset()
        self.platforms.reset()
        self.food.reset()
        self.door.reset()
        self.exit_arrow.reset()
        self.obstacles.reset()
        self.window.reset()

    def activate(self):
        self.active = True
        self.exit_available = False
        self.siphon.set_level(self.index)
        self.reset()
        self.input.register_any_press_ignore(self.any_press_ignored)
        mask, rect = self.get_entrance_mask()
        self.food.location.bottomleft = -self.entrance_offset, rect.h
        self.saved_food_surface = self.food.display_surface
        self.audio.play_bgm(self.get_resource(join(self.audio_root,
                                                   str(self.index) + ".ogg")))
        self.play(self.enter)

    def get_entrance_mask(self):
        base = self.door.foreground.location
        width = self.platforms[0].location.right - base.right
        mask = Surface((width, base.h), SRCALPHA)
        rect = mask.get_rect()
        rect.topleft = base.topright
        return mask, rect

    def enter(self):
        self.food.move(self.entrance_speed)
        mask, rect = self.get_entrance_mask()
        self.food.display_surface = mask
        self.clear_and_update_children()
        self.display_surface.blit(mask, rect)
        if self.food.location.left >= self.food.offset - rect.left:
            self.restore_food_surface()
            self.food.place_at_start()
            self.halt()
            self.play(self.stall)
            self.play(self.transition_to_go, delay=self.stall_length)

    def go(self):
        self.distance += self.velocity[0]
        self.clear_and_update_children()
        self.accelerate()
        self.time += 1
        if self.reset_queued:
            self.reset()
            self.halt()
            self.timer.stop()
            self.exit_available = True
            self.play(self.stall, delay=self.fall_pause)
            self.play(self.fade_in_arrow, delay=self.fall_pause)
            self.play(self.transition_to_go,
                      delay=self.stall_length + self.fall_pause)

    def stall(self):
        self.clear_and_update_children()

    def transition_to_go(self):
        self.halt()
        self.velocity[0] = self.velocity_range[0]
        self.timer.start()
        self.play(self.go)

    def fade_in_arrow(self):
        self.exit_arrow.fade(out=False)

    def exit(self):
        self.food.move(-self.entrance_speed)
        mask, rect = self.get_entrance_mask()
        self.food.display_surface = mask
        self.clear_and_update_children()
        self.display_surface.blit(mask, rect)
        if self.food.location.left <= -self.entrance_offset:
            self.restore_food_surface()
            self.halt()
            self.deactivate()
            self.get_game().home.activate()

    def queue_reset(self):
        self.reset_queued = True

    def is_going(self):
        return self.is_playing(self.go)

    def update(self):
        if self.active:
            Animation.update(self)

    def clear_and_update_children(self):
        self.clear()
        self.stars.update()
        self.planet.update()
        self.siphon.update()
        self.land.update()
        self.door.background.update()
        self.exit_arrow.update()
        self.guns.update()
        if not self.food.scope.active:
            self.food.update()
        self.door.foreground.update()
        self.drops.update()
        self.platforms.update()
        if self.food.scope.active:
            self.food.update()
        self.obstacles.update()
        self.window.update()

    def clear(self):
        self.display_surface.blit(self.background, (0, 0))

    def accelerate(self):
        time = self.time
        minimum, maximum = self.velocity_range
        self.velocity[0] =  minimum + time * maximum / (2000 + time)
        # self.print_velocity()

    def print_velocity(self):
        surface = Font(None, 24).render("%.2f" % self.velocity[0], False,
                                        (255, 255, 255))
        self.get_display_surface().blit(surface, (0, 0))
216.73.216.3
216.73.216.3
216.73.216.3
 
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!