from xenographic_wall.pgfw.Configuration import TypeDeclarations
from xenographic_wall.pgfw.Game import Game
from xenographic_wall.Introduction import Introduction
from xenographic_wall.world.World import World

class XenographicWall(Game):

    def __init__(self):
        Game.__init__(self, type_declarations=Types())
        self.introduction.activate()

    def set_children(self):
        Game.set_children(self)
        self.introduction = Introduction(self)
        self.world = World(self)

    def update(self):
        self.introduction.update()
        self.world.update()


class Types(TypeDeclarations):

    additional_defaults = \
        {"intro": \
         {"path": ["mask", "cord", "starfield", "sunburst"],
          "int": ["frame-duration", "starfield-max-alpha",
                  "prompt-visible-frames", "reset-delay"],
          "int-list": ["cord-y-range", "zoom-upper-left",
                       "zoom-region-dimensions"],
          "float": ["cord-speed", "zoom-step-ratio", "sunburst-delay",
                    "zoom-delay", "starfield-fade-step"]},
         "scope": \
         {"int": ["diameter", "ring-count", "flash-length"],
          "list": ["colors", "flash-colors"],
          "float": ["glow-step"]},
         "world": \
         {"path": "audio",
          "int-list": ["dimensions", "frame-border", "scroll-speed"]},
         "mushrooms": \
         {"int": "count", "list": "images", "path": "path"},
         "creature": \
         {"path": "root"}}
from pygame import mouse, Color, Surface, Rect

from xenographic_wall.pgfw.GameChild import GameChild
from xenographic_wall.world.scope.Scope import Scope
from xenographic_wall.world.mushrooms.Mushrooms import Mushrooms
from xenographic_wall.creatures.Creatures import Creatures

class World(GameChild, Surface):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.init_surface()
        self.deactivate()
        self.initialize_clip()
        self.scope = Scope(self)
        self.mushrooms = Mushrooms(self)
        self.set_frame()
        self.subscribe_to(self.get_custom_event_id(), self.respond_to_event)
        self.creatures = Creatures(self)
        self.reset()

    def init_surface(self):
        size = self.get_configuration().get("world", "dimensions")
        Surface.__init__(self, size)

    def deactivate(self):
        self.active = False

    def respond_to_event(self, evt):
        if self.is_command(evt, "cancel-introduction"):
            self.activate()
        elif self.is_command(evt, "reset-game"):
            self.reset()

    def activate(self):
        self.active = True
        self.scope.activate()
        self.get_audio().play_bgm(self.get_resource("world", "audio"))
        mouse.set_pos(self.get_screen().get_rect().center)

    def get_mouse_pos(self):
        pos = mouse.get_pos()
        clip = self.get_clip()
        return pos[0] + clip.left, pos[1] + clip.top

    def initialize_clip(self):
        clip = Rect((0, 0), self.get_screen().get_size())
        clip.center = self.get_rect().center
        self.set_clip(clip)

    def set_frame(self):
        border = self.get_configuration("world", "frame-border")
        screen = self.get_screen()
        frame = Rect((0, 0), screen.get_size())
        frame.w -= border[0]
        frame.h -= border[1]
        frame.center = screen.get_rect().center
        self.frame = frame

    def reset(self):
        self.deactivate()
        self.scope.reset()
        self.initialize_clip()
        self.creatures.reset()

    def update(self):
        if self.active:
            self.clear()
            self.update_clip()
            self.scope.update()
            self.mushrooms.update()
            self.creatures.update()
            self.draw()

    def clear(self):
        self.fill(Color("black"))

    def update_clip(self):
        x, y = mouse.get_pos()
        frame = self.frame
        move = self.move_clip
        dx, dy = 0, 0
        if not frame.collidepoint((x, y)):
            if y < frame.top:
                dy = y - frame.top
            elif y > frame.bottom:
                dy = y - frame.bottom
            if x < frame.left:
                dx = x - frame.left
            elif x > frame.right:
                dx = x - frame.right
            mx, my = self.get_configuration("world", "scroll-speed")
            move(dx / mx, dy / my)

    def move_clip(self, x=0, y=0):
        clip = self.get_clip()
        bound = self.get_rect()
        original_center = clip.center
        clip.top += y
        if clip.top < bound.top:
            clip.top = bound.top
        elif clip.bottom > bound.bottom:
            clip.bottom = bound.bottom
        clip.left += x
        if clip.left < bound.left:
            clip.left = bound.left
        elif clip.right > bound.right:
            clip.right = bound.right
        self.set_clip(clip)
        new_center = clip.center
        return new_center[0] - original_center[0], \
               new_center[1] - original_center[1]

    def draw(self):
        screen = self.get_screen()
        screen.blit(self, (0, 0), self.get_clip())
from random import randrange

from pygame import Surface, Color, Rect

from xenographic_wall.pgfw.GameChild import GameChild

class Mushroom(GameChild, Surface):

    transparent_color = Color("magenta")

    def __init__(self, parent, group, images):
        GameChild.__init__(self, parent)
        self.group = group
        self.images = images
        self.init_surface()
        self.place()
        self.eaten = False
        self.bitten = False

    def init_surface(self):
        image = self.images[0]
        Surface.__init__(self, image.get_size())
        self.clear()
        self.set_colorkey(self.transparent_color)
        self.blit(image, (0, 0))

    def clear(self):
        self.fill(self.transparent_color)

    def place(self):
        world = self.parent.parent
        size = self.get_size()
        x_bound = world.get_width() - size[0]
        y_bound = world.get_height() - size[1]
        self.rect = Rect((randrange(0, x_bound), randrange(0, y_bound)), size)

    def eat(self):
        self.eaten = True

    def bite(self):
        self.clear()
        self.blit(self.images[1], (0, 0))
        self.bitten = True
        sound = self.get_configuration("mushrooms", "bite-sound")
        self.get_audio().play_fx(sound, self.get_x_ratio())

    def get_x_ratio(self):
        return float(self.rect.centerx) / self.parent.parent.get_width()
        
    def update(self):
        self.draw()

    def draw(self):
        self.parent.parent.blit(self, self.rect)
216.73.216.31
216.73.216.31
216.73.216.31
 
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