Merge branch 'master' of makar:/var/www/git/pgfw

Conflicts:
	pgfw/Setup.py
This commit is contained in:
Frank 2015-10-24 20:49:07 -04:00
commit 5bb193800f
6 changed files with 100 additions and 16 deletions

View File

@ -106,10 +106,10 @@ class Configuration(RawConfigParser):
set_option(section, "double-click-time-limit", ".5", False)
section = "keys"
add_section(section)
set_option(section, "up", "K_UP, K_w", False)
set_option(section, "right", "K_RIGHT, K_d", False)
set_option(section, "down", "K_DOWN, K_s", False)
set_option(section, "left", "K_LEFT, K_a", False)
set_option(section, "up", "K_UP", False)
set_option(section, "right", "K_RIGHT", False)
set_option(section, "down", "K_DOWN", False)
set_option(section, "left", "K_LEFT", False)
set_option(section, "capture-screen", "K_F9", False)
set_option(section, "toggle-fullscreen", "K_F11", False)
set_option(section, "reset-game", "K_F8", False)

View File

@ -94,7 +94,7 @@ class Input(GameChild):
if not self.suppressed:
axis = event.axis
value = event.value
if not value:
if -.01 < value < .01:
for command in "up", "right", "down", "left":
self.post_command(command, cancel=True)
if command not in self.any_press_ignored:

View File

@ -53,7 +53,8 @@ class Setup:
if self.contains_path(join(root, path), exclude):
removal.append(path)
for path in removal:
paths.remove(path)
if path in paths:
paths.remove(path)
return paths
def contains_path(self, path, container):

View File

@ -10,6 +10,7 @@ from pygame.locals import *
from Animation import Animation
from Vector import Vector
from extension import get_hue_shifted_surface
class Sprite(Animation):
@ -20,6 +21,7 @@ class Sprite(Animation):
self.alpha = 255
self.locations = []
self.framesets = [Frameset(self, framerate=framerate)]
self.frameset_index = 0
self.set_frameset(0)
self.locations.append(Location(self))
self.motion_overflow = Vector()
@ -39,11 +41,13 @@ class Sprite(Animation):
if frameset.name == identifier:
identifier = ii
break
self.frameset_index = identifier
self.register_interval()
self.update_location_size()
if self.get_current_frameset().length() > 1:
self.play()
if self.frameset_index != identifier:
self.frameset_index = identifier
self.register_interval()
self.update_location_size()
if self.get_current_frameset().length() > 1:
self.play()
self.get_current_frameset().reset()
def register_interval(self):
self.register(self.shift_frame,
@ -427,3 +431,25 @@ class Frameset:
def reverse(self):
self.reversed = not self.reversed
class BlinkingSprite(Sprite):
def __init__(self, parent, blink_rate, framerate=None):
Sprite.__init__(self, parent, framerate)
self.register(self.blink, interval=blink_rate)
self.play(self.blink)
def reset(self):
self.unhide()
def blink(self):
self.toggle_hidden()
class RainbowSprite(Sprite):
def __init__(self, parent, image, hue_shift=8, framerate=None):
Sprite.__init__(self, parent, framerate)
for hue in xrange(0, 360, hue_shift):
self.add_frame(get_hue_shifted_surface(image, hue))

View File

@ -6,9 +6,12 @@ class TimeFilter(GameChild):
def __init__(self, parent):
GameChild.__init__(self, parent)
self.ticks = self.unfiltered_ticks = self.last_ticks = get_ticks()
self.reset_ticks()
self.open()
def reset_ticks(self):
self.ticks = self.unfiltered_ticks = self.last_ticks = get_ticks()
def close(self):
self.closed = True

View File

@ -1,15 +1,17 @@
from random import randint
from math import sin, cos, atan2, radians, sqrt
from pygame import Surface
from pygame import Surface, PixelArray, Color
from pygame.mixer import get_num_channels, Channel
from pygame.locals import *
def get_step(start, end, speed):
x0, y0 = start
x1, y1 = end
angle = atan2(x1 - x0, y1 - y0)
angle = get_angle(start, end)
return speed * sin(angle), speed * cos(angle)
def get_angle(start, end):
return atan2(end[0] - start[0], end[1] - start[1])
def get_endpoint(start, angle, magnitude):
"""clockwise, 0 is up"""
x0, y0 = start
@ -128,3 +130,55 @@ def render_box(font, text, antialias, color, background=None, border=None,
bordered_surface.blit(surface, rect)
surface = bordered_surface
return surface
def get_color_swapped_surface(surface, current, replacement):
swapped = surface.copy()
pixels = PixelArray(swapped)
pixels.replace(current, replacement)
del pixels
return swapped
def get_busy_channel_count():
count = 0
for index in xrange(get_num_channels()):
count += Channel(index).get_busy()
return count
def get_hue_shifted_surface(base, offset):
surface = base.copy()
pixels = PixelArray(surface)
color = Color(0, 0, 0)
for x in xrange(surface.get_width()):
for y in xrange(surface.get_height()):
h, s, l, a = Color(*surface.unmap_rgb(pixels[x][y])).hsla
if a:
color.hsla = (h + offset) % 360, s, l, a
pixels[x][y] = color
del pixels
return surface
def fill_tile(surface, tile):
for x in xrange(0, surface.get_width(), tile.get_width()):
for y in xrange(0, surface.get_height(), tile.get_height()):
surface.blit(tile, (x, y))
def get_shadowed_text(text, font, offset, color, antialias=True, shadow_color=(0, 0, 0),
colorkey=(255, 0, 255)):
foreground = font.render(text, antialias, color)
background = font.render(text, antialias, shadow_color)
alpha = SRCALPHA if antialias else 0
surface = Surface((foreground.get_width() + offset[0],
foreground.get_height() + offset[1]), alpha)
if not antialias:
surface.set_colorkey(colorkey)
surface.fill(colorkey)
surface.blit(background, ((abs(offset[0]) + offset[0]) / 2,
(abs(offset[1]) + offset[1]) / 2))
surface.blit(foreground, ((abs(offset[0]) - offset[0]) / 2,
(abs(offset[1]) - offset[1]) / 2))
return surface
def get_hsla_color(hue, saturation=100, lightness=50, alpha=100):
color = Color(0, 0, 0, 0)
color.hsla = hue, saturation, lightness, alpha
return color