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))
54.224.168.206
54.224.168.206
54.224.168.206
 
September 30, 2015


Edge of Life is a form I made with Babycastles and Mouth Arcade for an event in New York called Internet Yami-ichi, a flea market of internet-ish goods. We set up our table to look like a doctor's office and pharmacy and offered free examinations and medication prescriptions, a system described by one person as "a whole pharmacy and medical industrial complex".

Diagnoses were based on responses to the form and observations by our doctor during a short examination. The examination typically involved bizarre questions, toy torpedoes being thrown at people and a plastic bucket over the patient's head. The form combined ideas from Myers-Briggs Type Indicators, Codex Seraphinianus and chain-mail personality tests that tell you which TV show character you are. In our waiting room, we had Lake of Roaches installed in a stuffed bat (GIRP bat). It was really fun!

The icons for the food pyramid are from Maple Story and the gun icons are from the dingbat font Outgunned. I'm also using Outgunned to generate the items in Food Spring.


↠ RSS Feed ↞