from pygame import image, Color

from esp_hadouken.GameChild import *
from esp_hadouken.Font import *

class Score(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.pos = self.get_configuration()["ending-plate-position"]
        self.set_plate()

    def set_plate(self):
        path = self.get_resource("ending-plate-path")
        self.plate = image.load(path).convert_alpha()

    def render_score(self):
        config = self.get_configuration()
        color = Color(config["ending-score-color"])
        size = config["ending-score-size"]
        score = Font(self, size).render(self.build_text(), True, color)
        rect = score.get_rect()
        rect.center = self.plate.get_rect().center
        self.plate.blit(score, rect)

    def build_text(self):
        return "%i:%02i" % divmod(int(self.get_timer().total()), 60)

    def update(self):
        if self.active:
            self.set_plate()
            self.render_score()
            self.draw()

    def draw(self):
        self.parent.blit(self.plate, self.pos)

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False
from pygame import Surface, Color
from pygame.locals import *

from esp_hadouken.GameChild import *
from Cell import *

class NamePrompt(GameChild, Surface):

    cell_count = 3
    transparent_color = Color("brown")

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.init_surface()
        self.subscribe_to_events()
        self.add_cells()
        self.deactivate()

    def init_surface(self):
        size = self.get_configuration()["scoreboard-prompt-dimensions"]
        Surface.__init__(self, size)
        self.set_transparent()
        rect = self.get_rect()
        rect.center = self.parent.get_rect().center
        self.rect = rect

    def set_transparent(self):
        color = self.transparent_color
        self.set_colorkey(color)
        self.fill(color)

    def subscribe_to_events(self):
        self.subscribe_to(KEYDOWN, self.respond_to_key)

    def respond_to_key(self, event):
        if self.active:
            key = event.key
            if key >= K_a and key <= K_z:
                self.get_active_cell().set_char(key)
                self.change_active_cell(1)
                self.parent.update()
            elif key == K_BACKSPACE:
                if self.get_active_cell().is_blank():
                    self.change_active_cell(-1)
                self.get_active_cell().reset()
                self.parent.update()

    def get_active_cell(self):
        return self.cells[self.active_cell_index]

    def change_active_cell(self, increment):
        limit = len(self.cells) - 1
        index = self.active_cell_index + increment
        if index > limit:
            index = limit
        elif index < 0:
            index = 0
        self.active_cell_index = index

    def add_cells(self):
        cells = []
        for ii in range(self.cell_count):
            cells.append(Cell(self, ii))
        self.cells = cells
        self.active_cell_index = 0

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False

    def update(self):
        if self.active:
            self.draw()

    def draw(self):
        self.parent.blit(self, self.rect)

    def get_initials(self):
        return "".join(map(str, self.cells))
from pygame import Surface, Color
from pygame.locals import *

from esp_hadouken.GameChild import *
from esp_hadouken.Font import *

class Cell(GameChild, Surface):

    def __init__(self, parent, index):
        GameChild.__init__(self, parent)
        self.index = index
        self.init_surface()
        self.reset()

    def __str__(self):
        return chr(self.char).upper()

    def init_surface(self):
        size = self.get_configuration()["scoreboard-prompt-dimensions"]
        margin = self.get_margin()
        width = size[0] / self.parent.cell_count - margin
        Surface.__init__(self, (width, size[1]))
        rect = self.get_rect()
        rect.left = (self.get_width() + margin) * self.index + margin / 2
        self.rect = rect

    def get_margin(self):
        return self.get_configuration()["scoreboard-prompt-margin"]

    def reset(self):
        self.set_char(self.get_blank_char())

    def get_blank_char(self):
        return ord(self.get_configuration()["scoreboard-prompt-blank-char"])

    def set_char(self, char):
        self.char = char
        self.set_color()
        self.draw()

    def set_color(self):
        char = self.char
        if char == self.get_blank_char():
            color = Color(
                self.get_configuration()["scoreboard-prompt-blank-color"])
        else:
            color = self.get_glyph_palette()[char - K_a]
        self.color = color

    def activate(self):
        self.active = True

    def deactivate(self):
        self.active = False

    def draw(self):
        self.fill(self.color)
        self.render_char()
        self.parent.blit(self, self.rect)

    def render_char(self):
        config = self.get_configuration()
        size = config["scoreboard-prompt-text-size"]
        color = Color(config["scoreboard-prompt-text-color"])
        text = Font(self, size).render(str(self), True, color)
        rect = text.get_rect()
        rect.center = self.get_rect().center
        self.blit(text, rect)

    def is_blank(self):
        return self.char == self.get_blank_char()
52.15.143.223
52.15.143.223
52.15.143.223
 
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