from esp_hadouken.pgfw.GameChild import GameChild
from esp_hadouken.title.background.Sky import Sky
from esp_hadouken.title.background.Mask import Mask

class Background(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.sky = Sky(self)
        self.mask = Mask(self)

    def update(self):
        self.sky.update()
        self.mask.update()
from pygame import Surface, Color, PixelArray
from pygame.image import load

from esp_hadouken.pgfw.GameChild import GameChild

class Mask(Surface, GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_screen()
        self.transparent_color = 0xFF00FF
        self.load_configuration()
        self.init_surface()
        self.modify()

    def init_surface(self):
        Surface.__init__(self, self.display_surface.get_size())
        self.set_colorkey(self.transparent_color)
        self.blit(load(self.vector_path).convert(), (0, 0))

    def load_configuration(self):
        get = self.get_resource
        config = self.get_configuration("title")
        self.vector_path = get("title", "mask-vector-path")
        self.vector_color = Color(config["mask-vector-colors"][2])
        self.foreground_path = get("title", "mask-foreground-path")

    def modify(self):
        pixels = PixelArray(self)
        white = 0xFFFFFF
        pixels.replace(white, self.vector_color)
        reference = PixelArray(load(self.foreground_path).convert())
        for ii, column in enumerate(reference):
            for jj, pixel in enumerate(column):
                if pixel == 0xFFFFFF:
                    pixels[ii][jj] = self.transparent_color

    def update(self):
        self.draw()

    def draw(self):
        self.display_surface.blit(self, (0, 0))
from random import choice

from pygame import Color, PixelArray

from esp_hadouken.pgfw.GameChild import GameChild

class Blinker(GameChild):

    def __init__(self, parent, initial_freq, max_freq):
        GameChild.__init__(self, parent)
        self.frequency = initial_freq
        self.max_freq = max_freq
        self.iterations = 0
        self.set_palettes()

    def set_palettes(self):
        config = self.get_configuration("sprite")
        self.inner_palette = map(
            self.translate_hex_color, config["inner-palette"])
        self.outer_palette = map(
            self.translate_hex_color, config["outer-palette"])
        self.palette = (Color("black"), Color("white"))

    def translate_hex_color(self, color):
        return Color(color + "ff")

    def build_palette(self):
        return (choice(self.inner_palette), choice(self.outer_palette))

    def paint(self):
        image = self.parent.image
        pixels = PixelArray(image)
        old_palette = self.palette
        new_palette = self.build_palette()
        pixels.replace(old_palette[0], new_palette[0])
        pixels.replace(old_palette[1], new_palette[1])
        self.palette = new_palette
        image.unlock()

    def blink(self):
        iterations = self.iterations + 1
        if 1.0 / iterations <= self.frequency:
            self.paint()
            iterations = 0
        self.iterations = iterations
from math import floor
import copy

import pygame

from esp_hadouken.sprite.Blinker import Blinker
from esp_hadouken.pgfw.GameChild import GameChild

class Sprite(GameChild):

    def __init__(self, parent, image_path, display_surface, bounds=(None, None),
                 wrap=(False, False), initial_blink_freq=0, max_blink_freq=1):
        GameChild.__init__(self, parent)
        self.image_path = image_path
        self.display_surface = display_surface
        self.bounds = bounds
        self.wrap = wrap
        self.restricted_areas = []
        self.blinker = Blinker(self, initial_blink_freq, max_blink_freq)
        self.add_image()
        self.hide()

    def add_image(self):
        image = pygame.image.load(self.image_path).convert_alpha()
        self.rect = image.get_rect()
        self.old_rect = self.rect
        self.image = image

    def paint(self):
        self.blinker.paint()

    def move(self, x=0, y=0):
        self.old_rect = copy.copy(self.rect)
        if isinstance(x, tuple) or isinstance(x, list):
            x, y = x[0], x[1]
        if x < 0:
            x = floor(x)
        if y < 0:
            y = floor(y)
        rect = self.rect
        self.place(rect.left + x, rect.top + y)
        self.rect = self.accommodate_wrapping(rect)

    def place(self, x=None, y=None):
        rect = self.rect
        if type(x) is tuple or type(x) is list:
            x, y = x[0], x[1]
        if x is None:
            x = rect.left
        if y is None:
            y = rect.top
        self.rect.topleft = x, y

    def accommodate_wrapping(self, rect):
        horizontal, vertical = self.wrap
        scope = self.display_surface.get_rect()
        if vertical:
            if rect.top < -rect.h:
                rect.top += scope.h
            elif rect.top > scope.h:
                rect.top -= scope.h
        if horizontal:
            if rect.left < 0:
                rect.left += scope.w - rect.w - 1
            elif rect.right > scope.w:
                rect.right -= scope.w - rect.w - 1
        return rect

    def add_restricted_areas(self, rects):
        if type(rects) is not list:
            rects = [rects]
        self.restricted_areas += rects

    def flip(self):
        self.image = pygame.transform.flip(self.image, True, False)

    def resize(self, size):
        self.image = pygame.transform.scale(self.image, size)

    def show(self):
        self.visible = True

    def hide(self):
        self.visible = False

    def set_blink_frequency(self, frequency):
        self.blinker.frequency = frequency

    def update(self):
        if self.visible:
            self.blinker.blink()
            self.draw()

    def draw(self):
        self.display_surface.blit(self.image, self.rect)

    def erase(self):
        self.parent.clear(self.old_rect)
216.73.216.192
216.73.216.192
216.73.216.192
 
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