from random import choice, randrange

from pygame import Surface
from pygame.mixer import Sound

from _send.pgfw.Sprite import Sprite
from _send.Send import SoundEffect

class Cup(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.set_frame()
        self.set_color()
        self.direction = choice((1, -1))
        self.moving = True
        self.wall_audio = SoundEffect(self.get_resource("cup", "wall-audio"),
                                      .8)

    def set_frame(self):
        size = self.get_size()
        surface = Surface((size, size))
        self.add_frame(surface)
        self.place()
        self.align()

    def get_size(self):
        return self.parent.cup_scale * self.display_surface.get_height() * \
               (1 - self.get_configuration("sideline", "proportion") * 2)

    def place(self):
        sidelines = self.parent.parent.sidelines
        self.rect.top = randrange(sidelines[0].bottom,
                                  sidelines[1].top - self.rect.h)

    def align(self):
        self.rect.right = self.display_surface.get_rect().right

    def set_color(self):
        self.color = self.parent.get_foreground_color()
        self.paint()

    def paint(self):
        self.get_current_frame().fill(self.color)

    def stop(self):
        self.moving = False

    def update(self):
        if self.moving:
            self.move(dy=self.parent.speed * self.direction)
            self.collide()
        Sprite.update(self)

    def collide(self):
        for sideline in self.parent.parent.sidelines:
            if self.location.colliderect(sideline):
                self.direction *= -1
                self.move(dy=sideline.clip(self.location).h * self.direction)
                self.wall_audio.play()
from pygame import Color, Surface, Rect
from pygame.time import get_ticks
from pygame.draw import circle
from pygame.mixer import Sound

from _send.pgfw.GameChild import GameChild
from _send.Send import SoundEffect

class Charge(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.delegate = self.get_game().delegate
        self.display_surface = self.get_display_surface()
        self.charging_audio = SoundEffect(self.get_resource("charge",
                                                            "charging-audio"),
                                          .55)
        self.send_audio = SoundEffect(self.get_resource("charge",
                                                        "send-audio"), .1)
        self.load_configuration()
        self.subscribe(self.respond)
        self.reset()

    def load_configuration(self):
        config = self.get_configuration("charge")
        self.transparent_color = Color(*config["transparent-color"])
        self.colors = tuple(Color(color + "ff") for color in config["colors"])
        self.peak_time = config["peak-time"]
        self.size_limits = config["size-limits"]
        self.margin = config["margin"]

    def respond(self, event):
        fields = self.parent
        if not fields.loading and not fields.suppressing_input and \
               fields.get_current_field():
            if not self.sent and self.delegate.compare(event, "charge"):
                self.charging = True
                self.start = get_ticks()
            elif self.charging and self.delegate.compare(event, "charge", True):
                self.sent = True
                self.charging = False
                self.parent.get_current_field().ball.launch(self.get_strength())
                self.send_audio.play()

    def reset(self):
        self.charging = False
        self.start = None
        self.sent = False
        self.color_index = 0
        self.last_strength = None

    def get_strength(self):
        return float((get_ticks() - self.start) % self.peak_time) / \
               self.peak_time

    def update(self):
        if not self.sent and self.charging:
            self.increment_color_index()
            lower, upper = 4, 150
            if self.last_strength is None or \
                   self.last_strength > self.get_strength():
                self.charging_audio.play()
            strength = self.last_strength = self.get_strength()
            width = strength * (upper - lower) + lower
            lower, upper = 1, 22
            height = strength * (upper - lower) + lower
            rect = Rect(0, 0, width, height)
            rect.midbottom = self.parent.sidelines[1].midtop
            self.display_surface.fill(self.get_color(), rect)

    def increment_color_index(self):
        self.color_index += 1
        if self.color_index == len(self.colors):
            self.color_index = 0

    def get_color(self):
        return self.colors[self.color_index]
from pygame import Surface
from pygame.mixer import Sound

from _send.pgfw.Sprite import Sprite
from _send.Send import SoundEffect

class Ball(Sprite):

    def __init__(self, parent):
        Sprite.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.set_frame()
        self.set_color()
        self.adjust_for_size()
        self.reset()
        self.reflect_audio = SoundEffect(self.get_resource("ball",
                                                           "reflect-audio"),
                                         .35)

    def set_frame(self):
        size = self.get_size()
        surface = Surface((size, size))
        self.add_frame(surface)
        self.center()

    def get_size(self):
        return self.parent.ball_scale * self.display_surface.get_height() * \
               (1 - self.get_configuration("sideline", "proportion") * 2)

    def center(self):
        self.rect.centery = self.display_surface.get_rect().centery

    def set_color(self):
        self.color = self.parent.get_foreground_color()
        self.paint()

    def paint(self):
        self.get_current_frame().fill(self.color)

    def adjust_for_size(self):
        lower, upper = self.get_configuration("ball", "base-velocity-range")
        ratio = self.rect.w / float(self.get_configuration("ball", "base-size"))
        self.velocity_range = ratio * lower, ratio * upper
        self.deceleration = ratio * self.get_configuration("ball",
                                                           "base-deceleration")

    def reset(self):
        self.velocity = 0

    def launch(self, strength):
        lower, upper = self.velocity_range
        self.velocity = strength * (upper - lower) + lower
        self.direction = 1

    def update(self):
        if self.velocity:
            self.move(self.velocity * self.direction)
            if self.rect.right >= self.display_surface.get_rect().right:
                self.direction = -1
                self.move(self.display_surface.get_rect().right - \
                          self.rect.right)
                self.reflect_audio.play()
            self.velocity -= self.deceleration
            if self.velocity < 1 or self.rect.right < 0:
                self.velocity = 0
                self.parent.cup.stop()
                self.parent.parent.result.evaluate()
        Sprite.update(self)
        if self.rect.colliderect(self.parent.cup.location):
            self.display_surface.fill(self.parent.get_background_color(),
                                      self.rect.clip(self.parent.cup.location))
54.196.103.26
54.196.103.26
54.196.103.26
 
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 ↞