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
216.73.216.101
216.73.216.101
216.73.216.101
 
August 12, 2013

I've been researching tartan/plaid recently for decoration in my updated version of Ball & Cup, now called Send. I want to create the atmosphere of a sports event, so I plan on drawing tartan patterns at the vertical edges of the screen as backgrounds for areas where spectator ants generate based on player performance. I figured I would make my own patterns, but after browsing tartans available in the official register, I decided to use existing ones instead.

I made a list of the tartans that had what I thought were interesting titles and chose 30 to base the game's levels on. I sequenced them, using their titles to form a loose narrative related to the concept of sending. Here are three tartans in the sequence (levels 6, 7 and 8) generated by an algorithm I inferred by looking at examples that reads a tartan specification and draws its pattern using a simple dithering technique to blend the color stripes.


Acadia


Eve


Spice Apple

It would be wasting an opportunity if I didn't animate the tartans, so I'm thinking about animations for them. One effect I want to try is making them look like water washing over the area where the ants are spectating. I've also recorded some music for the game. Here are the loops for the game over and high scores screens.

Game Over

High Scores