from pygame import Surface
from pygame.locals import *
from pygame.image import load

from esp_hadouken.pgfw.GameChild import GameChild

class Glass(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_screen()
        self.load_image()

    def load_image(self):
        self.image = load(self.get_resource("title", "glass-path")).convert()

    def update(self):
        self.display_surface.blit(self.image, (0, 0), None, BLEND_MAX)
from pygame.locals import *
from pygame.image import load
from pygame.font import Font

from esp_hadouken.pgfw.GameChild import GameChild
from esp_hadouken.pgfw.Input import Input
from esp_hadouken.Toy import Toy
from esp_hadouken.title.background.Background import Background
from esp_hadouken.title.menu.Menu import Menu
from esp_hadouken.title.Glass import Glass

class Title(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.leave_limit = self.get_screen().get_rect().right
        self.audio_path = self.get_resource("title", "audio-path")
        self.toy_position = self.get_configuration("title", "toy-position")
        self.delegate = self.get_delegate()
        self.deactivate()
        self.set_children()
        self.place_toy()
        self.subscribe(self.respond)

    def deactivate(self):
        self.active = False

    def set_children(self):
        self.toy = Toy(self)
        self.background = Background(self)
        self.glass = Glass(self)
        self.menu = Menu(self)

    def place_toy(self):
        self.toy.rect.topleft = self.toy_position

    def respond(self, event):
        compare = self.delegate.compare
        if compare(event, "reset-game"):
            self.activate()
        elif compare(event, "main-menu-selection", option="play"):
            self.deactivate()
        elif compare(event, "main-menu-selection", option="records"):
            self.deactivate()

    def activate(self):
        self.active = True
        self.start_music()

    def start_music(self):
        self.get_audio().play_bgm(self.audio_path)

    def update(self):
        if self.active:
            self.background.update()
            self.toy.update()
            self.glass.update()
            self.menu.update()
from pygame import Rect

from esp_hadouken.pgfw.GameChild import GameChild
from esp_hadouken.title.menu.Option import Option

class Menu(Rect, GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_screen()
        self.fx = self.get_configuration("main-menu", "select-fx")
        self.delegate = self.get_delegate()
        self.init_rect()
        self.add_options()
        self.subscribe(self.respond)

    def init_rect(self):
        Rect.__init__(self, (0, 0), self.get_configuration("main-menu", "size"))
        self.center = self.display_surface.get_rect().center

    def add_options(self):
        self.options = [Option(self, ii) for ii in range(2)]

    def respond(self, event):
        if self.parent.active:
            compare = self.delegate.compare
            if compare(event, ["left", "right"]):
                play = self.get_audio().play_fx
                post = self.delegate.post
                name = "main-menu-selection"
                if compare(event, "left"):
                    play(self.fx[0])
                    post(name, option="play")
                elif compare(event, "right"):
                    play(self.fx[1])
                    post(name, option="records")

    def apply_to_options(self, name):
        for option in self.options:
            getattr(option, name)()

    def update(self):
        self.apply_to_options("update")
from random import randint

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

from esp_hadouken.pgfw.Sprite import Sprite

class Option(Sprite):

    def __init__(self, parent, index):
        Sprite.__init__(self, parent)
        self.index = index
        self.load_configuration()
        self.set_framerate(self.framerate)
        self.add_frames()
        self.place()

    def load_configuration(self):
        config = self.get_configuration("main-menu")
        self.framerate = config["framerate"]
        self.width = config["option-width"]
        self.frame_count = config["frame-count"]
        self.text_color = config["text-color"]
        self.text_size = config["text-size"]
        self.text = config["option-text"]
        self.background_color_range = config["background-color-range"]
        self.font_path = self.get_resource("main-menu", "font-path")

    def add_frames(self):
        size = self.width, self.parent.h
        for ii in range(self.frame_count):
            surface = Surface(size)
            self.randomize(surface)
            self.add_text(surface)
            self.add_frame(surface)

    def randomize(self, surface):
        pixels = PixelArray(surface)
        for ii, column in enumerate(pixels):
            for jj, pixel in enumerate(column):
                pixels[ii][jj] = self.build_random_color()

    def build_random_color(self):
        color = self.background_color_range
        return randint(*color), randint(*color), randint(*color)

    def add_text(self, parent):
        index, color, antialias = self.index, self.text_color, True
        font = Font(self.font_path, self.text_size)
        if index == 0:
            surface = font.render(self.text[0], antialias, color)
        elif index == 1:
            surface = font.render(self.text[1], antialias, color)
        rect = surface.get_rect()
        rect.center = parent.get_rect().center
        parent.blit(surface, rect)

    def place(self):
        index = self.index
        if index == 0:
            self.rect.topleft = self.parent.topleft
        elif index == 1:
            self.rect.topright = self.parent.topright
from math import pi

from pygame import Surface, Rect
from pygame.draw import arc

from esp_hadouken.pgfw.Sprite import Sprite

class Sky(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.load_configuration()
        self.add_frames()
        self.set_framerate(self.framerate)

    def load_configuration(self):
        config = self.get_configuration("title")
        self.framerate = config["sky-framerate"]
        self.step = config["sky-arc-step"]
        self.arc_thickness = config["sky-arc-thickness"]
        self.arc_color = config["sky-arc-color"]
        self.color = config["sky-color"]

    def add_frames(self):
        for ii in 0, 1:
            offset = -ii * self.step / 2
            surface = Surface(self.display_surface.get_size())
            surface.fill(self.color)
            self.draw_arcs(surface, offset)
            self.add_frame(surface)

    def draw_arcs(self, surface, offset):
        step = self.step
        reference = self.display_surface.get_rect()
        limit = reference.w
        rect = Rect(0, 0, step + offset, step + offset)
        center = reference.centerx, reference.bottom
        rect.center = center
        start_angle = pi / 2
        thickness = self.arc_thickness
        color = self.arc_color
        while rect.w / 2 <= limit:
            arc(surface, color, rect, start_angle, 0, thickness)
            rect.w += step
            rect.h += step
            rect.center = center
216.73.216.58
216.73.216.58
216.73.216.58
 
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