from esp_hadouken import levels

from Road import *

class Void(levels.Void.Void):

    def __init__(self, parent):
        levels.Void.Void.__init__(self, parent)
        self.read_configuration()
        self.road = Road(self)

    def read_configuration(self):
        config = self.get_configuration()
        prefix = "diortem-level-"
        self.padding = config[prefix + "void-padding"]
        self.segment_width_range = config[prefix + "segment-width-range"]
        self.segment_height_range = config[prefix + "segment-height-range"]
        self.shift_range = config[prefix + "shift-range"]
        self.leg_range = config[prefix + "leg-range"]
        self.scroll_speed = config[prefix + "scroll-speed"]

    def update_area(self):
        self.road.update()
from random import randint

from pygame import Surface, Color, Rect

from esp_hadouken.GameChild import *
from Segment import *

class Road(GameChild, Surface):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.init_surface()
        self.set_background()
        self.set_x_range()
        self.generate_segments()

    def init_surface(self):
        parent = self.parent
        width = parent.get_width()
        padding = parent.padding
        bandit_height = parent.parent.bandit.rect.h
        height = parent.get_height() - sum(padding) - bandit_height
        rect = Rect(0, padding[0] + bandit_height, width, height)
        Surface.__init__(self, rect.size)
        self.convert()
        self.rect = rect

    def set_background(self):
        background = Surface(self.get_size())
        background.fill(self.parent.opaque_color)
        background.convert()
        self.background = background

    def set_x_range(self):
        max_seg = self.parent.segment_width_range[1]
        self.x_range = max_seg / 2, self.get_width() - max_seg / 2

    def generate_segments(self):
        self.segments = []
        self.leg = Leg(self)
        y = self.get_height()
        while y > 0:
            self.add_segment(y)
            y -= self.segments[0].rect.h

    def add_segment(self, bottom=None):
        leg = self.leg
        segments = self.segments
        if leg.is_complete():
            leg = Leg(self)
        if bottom is None:
            bottom = segments[0].rect.top
        x = segments[0].rect.centerx if segments else 0
        segments.insert(0, Segment(self, leg, bottom, x))
        leg.advance()
        self.leg = leg

    def update(self):
        self.set_clip()
        self.clear()
        self.update_segments()
        self.draw()

    def set_clip(self):
        parent = self.parent
        y = parent.get_clip().top - parent.padding[0] - parent.parent.bandit.rect.h
        Surface.set_clip(self, Rect((0, y), parent.get_clip().size))

    def clear(self):
        self.blit(self.background, (0, 0))

    def update_segments(self):
        if self.segments[0].rect.top >= -self.parent.segment_height_range[1]:
            self.add_segment()
        for segment in self.segments:
            if segment.rect.top > self.get_height():
                self.segments.remove(segment)
            else:
                segment.update()

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


class Leg:

    dirs = [-1, 1]

    def __init__(self, road):
        self.road = road
        self.length = randint(*road.parent.leg_range)
        self.direction = self.dirs[randint(0, len(self.dirs) - 1)]
        self.index = 0

    def advance(self):
        self.index += 1
        self.shift = randint(*self.road.parent.shift_range) * self.direction

    def change_direction(self):
        dirs = self.dirs
        direction = self.direction
        if direction == dirs[0]:
            direction = dirs[1]
        else:
            direction = dirs[0]
        self.direction = direction

    def is_complete(self):
        return self.index >= self.length
from operator import sub
from random import randint

from pygame import Surface, Rect, Color, transform, draw

from esp_hadouken.GameChild import *

class Segment(GameChild):

    def __init__(self, parent, leg, bottom, x):
        GameChild.__init__(self, parent)
        self.init_rect(leg, bottom, x)
        self.color = parent.parent.transparent_color

    def init_rect(self, leg, bottom, x):
        parent = self.parent
        rect = Rect(0, 0, 0, randint(*parent.parent.segment_height_range))
        x_range = parent.x_range
        if x is None:
            x = randint(*x_range)
        else:
            x += leg.direction * randint(*parent.parent.shift_range)
        if x < x_range[0] or x > x_range[1]:
            leg.change_direction()
            if x < x_range[0]:
                x = x_range[0]
            else:
                x = x_range[1]
        rect.centerx = x
        rect.bottom = bottom
        self.rect = rect

    def update(self):
        self.update_width()
        self.recenter()
        self.scroll()
        self.draw()

    def update_width(self):
        parent = self.parent
        rect = self.rect
        pos = float(rect.bottom) / parent.get_height()
        centerx = rect.centerx
        width_r = parent.parent.segment_width_range
        rect.w = pos * -sub(*width_r) + width_r[0]
        rect.centerx = centerx

    def recenter(self):
        rect = self.rect
        right_bound = self.parent.get_width()
        if rect.left < 0:
            rect.left = 0
        elif rect.right > right_bound:
            rect.right = right_bound

    def scroll(self):
        self.rect.top += self.parent.parent.scroll_speed

    def draw(self):
        draw.rect(self.parent, self.color, self.rect)
from random import randint

from pygame import Surface, Color

from esp_hadouken.levels.Void import *
from Barrier import *

class Gauntlet(Void):

    step_count = 0

    def __init__(self, parent):
        Void.__init__(self, parent)
        self.read_configuration()
        self.set_area()
        self.generate_barriers()

    def read_configuration(self):
        config = self.get_configuration()
        prefix = "horse-level-"
        self.padding = config[prefix + "void-padding"]
        self.size_range = config[prefix + "size-range"]
        self.step_limit = config[prefix + "step-limit"]

    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

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

    def generate_barriers(self):
        self.barriers = barriers = []
        y = 0
        while y < self.area.get_height():
            sibling = None if not barriers else barriers[-1]
            barriers.append(Barrier(self, y, sibling))
            y += barriers[-1].get_height()

    def update_area(self):
        self.update_step_count()
        self.clear_area()
        self.update_barriers()
        self.draw_area()

    def update_step_count(self):
        count = self.step_count + 1
        if count > self.step_limit:
            count = 0
            self.toggle_barrier_headings()
        self.step_count = count

    def toggle_barrier_headings(self):
        for barrier in self.barriers:
            barrier.toggle_heading()

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

    def update_barriers(self):
        for barrier in self.barriers:
            barrier.update()

    def draw_area(self):
        self.blit(self.area, (0, self.y_range[0]))
54.174.51.80
54.174.51.80
54.174.51.80
 
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


↠ RSS Feed ↞