from random import choice
from lib.pgfw.pgfw.Sprite import Sprite

class Gun(Sprite):

    def __init__(self, parent, path):
        Sprite.__init__(self, parent)
        self.load_from_path(path, True)
        self.set_framerate(self.get_configuration("gun", "framerate"))
        self.reset()

    def reset(self):
        self.hide()
        self.unfollow()

    def hide(self):
        self.visible = False

    def unfollow(self):
        self.following = False

    def show(self):
        self.visible = True

    def follow(self, food):
        self.food = food
        self.following = True

    def update(self):
        if self.visible:
            if self.following:
                self.location.centerx = self.food.location.centerx
            Sprite.update(self)
from os import listdir
from os.path import join

from pygame import Surface

from lib.pgfw.pgfw.GameChild import GameChild
from food_spring.gun.Gun import Gun

class GunLibrary(GameChild, list):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.load_configuration()
        self.set_guns()

    def load_configuration(self):
        config = self.get_configuration("gun")
        self.root = config["path"]

    def set_guns(self):
        for ii in xrange(4):
            self.append(Guns(self, self.get_resource(join(self.root, str(ii)))))


class Guns(GameChild, list):

    def __init__(self, parent, root):
        GameChild.__init__(self, parent)
        for path in sorted(listdir(root)):
            self.append(Gun(self, join(root, path)))
        self.reset()

    def reset(self):
        for gun in self:
            gun.reset()
            gun.unfollow()

    def hide(self, exclude=None):
        for gun in self:
            gun.hide()
        if exclude is not None:
            self[exclude].show()

    def update(self):
        for gun in self:
            gun.update()
from pygame import Surface

from lib.pgfw.pgfw.Animation import Animation
from food_spring.introduction.Epithet import Epithet

class Introduction(Animation):

    def __init__(self, parent):
        Animation.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.audio = self.get_audio()
        self.delegate = self.get_delegate()
        self.audio_path = self.get_resource("introduction", "audio")
        self.set_background()
        self.epithet = Epithet(self)
        self.spanky = parent.spanky
        self.reset()
        self.deactivate()
        self.subscribe(self.respond)

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

    def respond(self, event):
        if self.active:
            if self.delegate.compare(event, "any"):
                self.deactivate()
                self.parent.title.queue_activation()

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

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

    def activate(self):
        self.active = True
        self.audio.play_bgm(self.audio_path)
        self.spanky.location.midbottom = \
                                       self.display_surface.get_rect().midbottom

    def update(self):
        if self.active:
            self.clear()
            Animation.update(self)
            self.parent.gaia.swapper.update()
            self.epithet.update()
            self.spanky.update()

    def clear(self):
        for rect in (self.parent.gaia.swapper.rect, self.spanky.location):
            self.display_surface.blit(self.background, rect, rect)
        self.epithet.clear()
from random import randint

from pygame import Rect, Surface, Color
from pygame.font import Font

from lib.pgfw.pgfw.GameChild import GameChild
from lib.pgfw.pgfw.Sprite import Sprite

class Epithet(GameChild, Rect):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.load_configuration()
        self.init_rect()
        self.set_glyphs()

    def load_configuration(self):
        config = self.get_configuration("epithet")
        self.font_path = self.get_resource("display", "font-path")
        self.width = config["width"]
        self.margin = config["margin"]
        self.text = config["text"]
        self.color = config["color"]
        self.i_color = config["i-color"]
        self.t_color = config["t-color"]
        self.font_size = config["font-size"]
        self.it_size = config["it-size"]

    def init_rect(self):
        Rect.__init__(self, 0, 0, self.width, 0)
        self.midtop = self.get_display_surface().get_rect().centerx, self.margin

    def set_glyphs(self):
        glyphs = []
        for ii, character in enumerate(self.text):
            if character != " ":
                color = None
                if character in "IT":
                    size = self.it_size
                    italic = True
                    bold = True
                    if character == "I":
                        color = self.i_color
                    elif character == "T":
                        color = self.t_color
                else:
                    size = self.font_size
                    italic = False
                    bold = False
                glyphs.append(Glyph(self, character, color, size, bold, italic,
                                    ii))
        self.glyphs = glyphs

    def update(self):
        for glyph in self.glyphs:
            glyph.update()

    def clear(self):
        parent = self.parent
        for glyph in self.glyphs:
            for location in glyph.locations:
                parent.display_surface.blit(parent.background, location,
                                            location)


class Glyph(Sprite):

    def __init__(self, parent, character, color, size, bold, italic, ii):
        Sprite.__init__(self, parent, randint(40, 120))
        self.set_frames(character, size, color, bold, italic)
        self.place(ii)
        self.add_location(offset=(-5, 8))

    def set_frames(self, character, size, color, bold, italic):
        color = Color(0, 0, 0)
        background_color = Color(0, 0, 0)
        count = 30
        font = Font(self.parent.font_path, size)
        font.set_italic(italic)
        font.set_bold(bold)
        for ii in xrange(count):
            hue = randint(0, 255)
            color.hsla = hue, 100, 50, randint(30, 100)
            background_hue = hue + 128
            if background_hue > 255:
                background_hue -= 255
            background_color.hsla = background_hue, 100, 50, randint(30, 100)
            frame = font.render(character, True, color, background_color)
            if not ii % (count / 6):
                surface = Surface(frame.get_size())
                surface.set_colorkey((0, 0, 0))
                midpoint = frame.get_width() / 2
                surface.blit(frame, (midpoint, 0))
                surface.blit(frame, (-midpoint, 0))
                frame = surface
            self.add_frame(frame)

    def place(self, ii):
        parent = self.parent
        offset = int(parent.w * float(ii) / (len(parent.text) - 1))
        self.location.center = parent.left + offset, parent.top
54.224.166.141
54.224.166.141
54.224.166.141
 
June 5, 2016

↠ RSS Feed ↞