from esp_hadouken.levels.Level import *
from Void import *

class Tooth(Level):

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

    def set_void(self):
        self.void = Void(self)
from esp_hadouken.levels.Level import *
from Void import *

class Octo(Level):

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

    def set_void(self):
        self.void = Void(self)

    def set_dot(self):
        Level.set_dot(self, (None, (0, self.get_height())), (True, False))
from random import randint

from pygame import Surface

from esp_hadouken import levels
from Barrier import *

class Void(levels.Void.Void):

    def __init__(self, parent):
        levels.Void.Void.__init__(self, parent)
        self.frame_width = self.parent.get_width()
        self.read_configuration()
        self.init_barriers()

    def read_configuration(self):
        config = self.get_configuration()
        self.barrier_height = config["octo-level-barrier-height"]
        self.min_gap = config["octo-level-min-gap"]
        self.spawn_range = config["octo-level-spawn-range"]
        self.void_padding = config["octo-level-void-padding"]
        self.scroll_speed = config["octo-level-scroll-speed"]

    def init_barriers(self):
        self.set_y_range()
        y_range = self.y_range
        y = y_range[0]
        barriers = []
        y = self.generate_spawn_distance()
        while y < y_range[1]:
            barriers.append(Barrier(self, y))
            y += self.generate_spawn_distance()
        self.barriers = barriers
        self.next_spawn = self.generate_spawn_distance()

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

    def generate_spawn_distance(self):
        return randint(*self.spawn_range)

    def update_area(self):
        barriers = self.barriers
        if barriers[0].y - self.y_range[0] > self.next_spawn:
            barriers.insert(0, Barrier(self, self.y_range[0]))
            self.next_spawn = self.generate_spawn_distance()
        for barrier in barriers:
            if barrier.y > self.y_range[1]:
                barriers.remove(barrier)
            else:
                barrier.update()
from random import randint

from pygame import Surface, Color, Rect

from esp_hadouken.GameChild import *

class Barrier(GameChild, Surface):

    transparent_color = Color("magenta")

    def __init__(self, parent, y=0):
        GameChild.__init__(self, parent)
        Surface.__init__(self, (parent.frame_width, parent.barrier_height))
        self.set_colorkey(self.transparent_color)
        self.convert()
        self.y = y
        self.set_gap()

    def set_gap(self):
        gap = Surface(self.get_size())
        gap.fill(self.transparent_color)
        self.gap_center = randint(0, self.get_width())
        self.gap = gap.convert()

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

    def blit_gap(self):
        gap = self.gap
        width = self.calculate_width()
        position = (self.gap_center - width / 2, 0)
        area = Rect(0, 0, width, gap.get_height())
        self.blit(gap, position, area)
        self.blit_overflow(width, position[0])

    def calculate_width(self):
        y_range = self.parent.y_range
        ratio = (self.y - y_range[0]) / float(y_range[1] - y_range[0])
        min_gap = self.parent.min_gap
        return int(min_gap + (self.get_width() - min_gap) * ratio)

    def blit_overflow(self, width, x):
        gap = self.gap
        frame_width = self.parent.frame_width
        if x < 0 or x + width > frame_width:
            if x < 0:
                overflow = 0 - x
                position = (frame_width - overflow, 0)
            else:
                overflow = x + width - frame_width
                position = (0, 0)
            self.blit(gap, position, Rect(0, 0, overflow, self.get_height()))

    def draw(self):
        self.parent.blit(self, (0, self.y))
from math import pi, sin, cos
from random import random, randint

from pygame import time, draw, Rect

from esp_hadouken import levels

class Trap(levels.Void.Void):

    def __init__(self, parent):
        levels.Void.Void.__init__(self, parent)
        self.read_configuration()
        self.reset()

    def read_configuration(self):
        config = self.get_configuration()
        prefix = "circulor-level-"
        self.radius_range = config[prefix + "radius-range"]
        self.trap_duration = config[prefix + "trap-duration"]
        self.speed = config[prefix + "speed"]
        self.thickness = config[prefix + "trap-thickness"]

    def reset(self):
        self.center = None
        self.total_elapsed = 0
        self.last_ticks = time.get_ticks()
        self.angle = random() * pi * 2

    def update_area(self):
        if self.parent.trapped:
            self.place()
            self.collide()
            if self.total_elapsed >= self.trap_duration:
                self.parent.trapped = False
                self.parent.escaped = True
            else:
                self.update_total_elapsed()
            self.draw_circle()

    def place(self):
        center = self.get_center()
        x_del, y_del = self.calculate_deltas()
        self.center = center[0] + x_del, center[1] + y_del

    def get_center(self):
        center = self.center
        if not center:
            center = self.parent.dot.rect.center
        return center

    def calculate_deltas(self):
        ang, distance = self.angle, self.speed
        return sin(ang) * distance, cos(ang) * distance

    def collide(self):
        angle = self.angle
        x, y = self.center
        radius = self.get_radius()
        rect = Rect(x - radius, y - radius, radius * 2, radius * 2)
        bandit = self.parent.bandit.rect
        if rect.colliderect(bandit):
            if bandit.left - rect.right > rect.top - bandit.bottom:
                angle = -angle
                rect.right = bandit.left
            else:
                angle = pi - angle
                rect.top = bandit.bottom
        field = self.parent.rect
        if rect.right > field.w or rect.left < 0:
            angle = -angle
            if rect.right > field.w:
                rect.right = field.w
            else:
                rect.left = 0
        if rect.top < 0 or rect.bottom > field.h:
            angle = pi - angle
            if rect.top < 0:
                rect.top = 0
            else:
                rect.bottom = field.h
        self.angle = angle
        self.center = rect.center

    def update_total_elapsed(self):
        current_ticks = time.get_ticks()
        self.total_elapsed += current_ticks - self.last_ticks
        self.last_ticks = current_ticks

    def draw_circle(self):
        center = tuple(map(int, self.center))
        color = self.opaque_color
        draw.circle(self, color, center, self.get_radius(), self.thickness)

    def get_radius(self):
        radius_r = self.radius_range
        pos = float(self.total_elapsed) / self.trap_duration
        return int(pos * (radius_r[1] - radius_r[0]) + radius_r[0])
216.73.216.59
216.73.216.59
216.73.216.59
 
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