from esp_hadouken.pgfw.Sprite import Sprite

class Toy(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.load_from_path(self.get_resource("toy", "path"), True)
        self.set_framerate(self.get_configuration("toy", "framerate"))
from os.path import exists, join, basename
from sys import argv

from pygame import mixer

import Game

class GameChild:

    def __init__(self, parent=None):
        self.parent = parent

    def get_game(self):
        current = self
        while not isinstance(current, Game.Game):
            current = current.parent
        return current

    def get_configuration(self):
        return self.get_game().get_configuration()

    def get_input(self):
        return self.get_game().get_input()

    def get_screen(self):
        return self.get_game().display.get_screen()

    def get_timer(self):
        return self.get_game().timer

    def get_audio(self):
        return self.get_game().audio

    def get_delegate(self):
        return self.get_game().delegate

    def get_resource(self, key):
        config = self.get_configuration()
        path = config[key]
        installed_path = join(config["resources-install-path"], path)
        if exists(installed_path) and self.use_installed_resource():
            return installed_path
        elif exists(path):
            return path

    def use_installed_resource(self):
        if "-l" in argv:
            return False
        return True

    def get_pause_screen(self):
        return self.get_game().pause_screen

    def get_high_scores(self):
        return self.get_game().high_scores

    def get_glyph_palette(self):
        return self.get_game().glyph_palette

    def subscribe_to(self, kind, callback):
        self.get_game().delegate.add_subscriber(kind, callback)

    def unsubscribe_from(self, kind, callback):
        self.get_game().delegate.remove_subscriber(kind, callback)

    def is_debug_mode(self):
        return "-d" in argv
from time import time

from pygame.locals import *

from esp_hadouken.pgfw.GameChild import *
from esp_hadouken.pgfw.Input import *

class Timer(GameChild, dict):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.max_time = self.get_configuration("timer", "max-time")
        self.subscribe_to_events()
        self.reset()

    def subscribe_to_events(self):
        self.subscribe(self.respond_to_event)

    def respond_to_event(self, event):
        if event.command == "reset":
            self.reset()

    def reset(self):
        self.clear_current_interval()
        self.concealed = False
        dict.__init__(self, {"octo": 0, "horse": 0, "diortem": 0, "circulor": 0,
                             "tooth": 0})

    def clear_current_interval(self):
        self.start_time = None
        self.pause_length = 0
        self.pause_start_time = None
        self.paused = False
        self.current_level = None

    def start(self, level):
        self.start_time = time()
        self.current_level = level

    def pause(self):
        if self.start_time:
            paused = self.paused
            if self.paused:
                self.pause_length += time() - self.pause_start_time
            else:
                self.pause_start_time = time()
            self.paused = not paused

    def stop(self):
        start = self.start_time
        level = self.current_level
        if None not in (start, level):
            interval = time() - start - self.pause_length
            self[level] += interval
        self.clear_current_interval()

    def total(self):
        if self.concealed:
            return self.max_time
        return sum(self.values())

    def conceal(self):
        self.concealed = True
import pygame
from pygame.locals import *

from GameChild import *

class EventDelegate(GameChild):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.subscribers = dict()
        self.disable()
        if self.is_debug_mode():
            print "Event ID range: %i - %i" % (NOEVENT, NUMEVENTS)

    def enable(self):
        self.enabled = True

    def disable(self):
        self.enabled = False

    def dispatch_events(self):
        if self.enabled:
            subscribers = self.subscribers
            for event in pygame.event.get():
                kind = event.type
                if kind in subscribers:
                    for subscriber in subscribers[kind]:
                        if self.is_debug_mode():
                            print "Passing %s to %s" % (event, subscriber)
                        subscriber(event)
        else:
            pygame.event.pump()

    def add_subscriber(self, kind, callback):
        if self.is_debug_mode():
            print "Subscribing %s to %i" % (callback, kind)
        subscribers = self.subscribers
        if kind not in subscribers:
            subscribers[kind] = list()
        subscribers[kind].append(callback)

    def remove_subscriber(self, kind, callback):
        self.subscribers[kind].remove(callback)
from pygame import image

from GameChild import *

class PauseScreen(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.load_image()

    def load_image(self):
        self.img = image.load(self.get_resource("pause-image-path"))

    def show(self):
        self.get_screen().blit(self.img, (0, 0))
216.73.216.141
216.73.216.141
216.73.216.141
 
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