from random import randint
from operator import sub

from pygame import Surface

from esp_hadouken.GameChild import *

class Barrier(GameChild, Surface):

    dir_r, dir_l = 1, -1

    def __init__(self, parent, y, sibling=None):
        GameChild.__init__(self, parent)
        self.y = y
        self.sibling = sibling
        self.init_surface()

    def init_surface(self):
        size = self.determine_size()
        Surface.__init__(self, (size, size))
        self.fill(self.parent.transparent_color)
        self.set_rect()

    def determine_size(self):
        parent = self.parent
        size_range = parent.size_range
        pos = float(self.y) / -sub(*parent.y_range)
        return pos * -sub(*size_range) + size_range[0]

    def set_rect(self):
        rect = self.get_rect()
        rect.top = self.y
        sibling = self.sibling
        if not sibling:
            growth = self.dir_r
            rect.top = self.y
            rect.left = self.generate_initial_x()
        else:
            growth = sibling.growth
            if growth == self.dir_r:
                rect.left = sibling.rect.right
                if rect.right > self.parent.get_width():
                    growth = self.dir_l
                    rect.right = sibling.rect.left
            if growth == self.dir_l:
                rect.right = sibling.rect.left
                if rect.left < 0:
                    growth = self.dir_r
                    rect.left = sibling.rect.right
        self.growth = growth
        self.rect = rect
        self.x = rect.left
        self.set_heading()
        self.set_step()

    def generate_initial_x(self):
        parent = self.parent
        return randint(0, parent.get_width() - parent.size_range[0])

    def set_heading(self):
        if self.rect.centerx > self.parent.get_width() / 2:
            heading = self.dir_l
        else:
            heading = self.dir_r
        self.heading = heading

    def set_step(self):
        parent = self.parent
        center = parent.get_width() / 2
        rnge = abs((self.rect.centerx - center) * 2)
        self.step = float(rnge) / parent.step_limit

    def toggle_heading(self):
        heading = self.heading
        if heading == self.dir_l:
            heading = self.dir_r
        else:
            heading = self.dir_l
        self.heading = heading

    def update(self):
        self.move()
        self.draw()

    def move(self):
        self.x += self.heading * self.step
        self.rect.left = self.x
        
    def draw(self):
        self.parent.area.blit(self, self.rect)
from esp_hadouken.levels.Level import *
from Gauntlet import *

class Horse(Level):

    def __init__(self, parent):
        Level.__init__(self, parent)

    def set_void(self):
        self.void = Gauntlet(self)
from random import randint
from operator import sub

from pygame import draw

from esp_hadouken.GameChild import *

class Bubble(GameChild):

    def __init__(self, parent, y=None):
        GameChild.__init__(self, parent)
        self.y = y
        self.set_x()

    def set_x(self):
        self.x = self.parent.get_width() / 2

    def update(self):
        self.y += self.parent.scroll_speed
        self.set_radius()

    def set_radius(self):
        parent = self.parent
        radius_range = parent.radius_range
        pos = float(self.y) / -sub(*parent.y_range)
        self.radius = int(pos * -sub(*radius_range) + radius_range[0])

    def draw(self):
        parent = self.parent
        center = self.x, self.y
        draw.circle(parent.area, parent.transparent_color, center, self.radius)
from random import randint

from pygame import Color, Surface

from esp_hadouken import levels
from Bubble import *

class Void(levels.Void.Void):

    def __init__(self, parent):
        levels.Void.Void.__init__(self, parent)
        self.iterations = 0
        self.read_configuration()
        self.set_area()
        self.show()

    def read_configuration(self):
        config = self.get_configuration()
        self.switch_frequency = config["tooth-level-switch-frequency"]
        self.scroll_speed = config["tooth-level-scroll-speed"]
        self.padding = config["tooth-level-void-padding"]
        self.radius_range = config["tooth-level-radius-range"]
        self.spawn_range = config["tooth-level-spawn-range"]

    def set_area(self):
        self.set_y_range()
        y_range = self.y_range
        height = y_range[1] - y_range[0]
        area = Surface((self.parent.get_width(), height)).convert()
        self.area_bg = Surface(area.get_size()).convert()
        self.area = area
        self.generate_bubbles()

    def set_y_range(self):
        padding = self.padding
        parent = self.parent
        start = parent.bandit.rect.bottom + padding[0]
        end = parent.get_height() - padding[1]
        self.y_range = start, end

    def generate_bubbles(self):
        self.bubbles = []
        y = self.get_height()
        while y > -self.radius_range[0]:
            self.add_bubble(y)
            y -= self.next_spawn + self.radius_range[0]

    def add_bubble(self, y=None):
        if y is None:
            y = -self.radius_range[0]
        self.bubbles.insert(0, Bubble(self, y))
        self.next_spawn = randint(*self.spawn_range)

    def toggle(self):
        if self.visible:
            self.hide()
        else:
            self.show()

    def show(self):
        self.visible = True

    def hide(self):
        self.visible = False

    def update_area(self):
        self.update_bubbles()
        iterations = self.iterations + 1
        if 1.0 / iterations <= self.switch_frequency:
            self.toggle()
            iterations = 0
        if self.visible:
            self.clear_area()
            self.draw_area()
        self.iterations = iterations

    def update_bubbles(self):
        bubbles = self.bubbles
        radius_range = self.radius_range
        if bubbles[0].y - radius_range[0] > self.next_spawn:
            self.add_bubble()
        for bubble in bubbles:
            if bubble.y > self.y_range[1] + radius_range[1]:
                bubbles.remove(bubble)
            else:
                bubble.update()

    def clear_area(self):
        self.area.blit(self.area_bg, (0, 0))

    def draw_area(self):
        self.draw_bubbles()
        self.blit(self.area, (0, self.y_range[0]))

    def draw_bubbles(self):
        for bubble in self.bubbles:
            bubble.draw()
216.73.216.142
216.73.216.142
216.73.216.142
 
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