spin
190
NS.py
|
@ -4,7 +4,7 @@ from random import randint, choice
|
||||||
from math import pi
|
from math import pi
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from glob import iglob
|
from glob import iglob
|
||||||
from os.path import basename
|
from os.path import basename, join
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from serial import Serial
|
from serial import Serial
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
@ -803,7 +803,7 @@ class Platform(GameChild):
|
||||||
|
|
||||||
class Light(Animation):
|
class Light(Animation):
|
||||||
|
|
||||||
MAX_GLOW_INDEX = 16
|
MAX_GLOW_INDEX = 25
|
||||||
INTRODUCTION_OFFSET = 80
|
INTRODUCTION_OFFSET = 80
|
||||||
|
|
||||||
def __init__(self, parent, color, position):
|
def __init__(self, parent, color, position):
|
||||||
|
@ -875,19 +875,31 @@ class Light(Animation):
|
||||||
return self.points
|
return self.points
|
||||||
|
|
||||||
def draw_glow(self):
|
def draw_glow(self):
|
||||||
for ii in reversed(xrange(0, self.glow_index, 1)):
|
for ii, y in enumerate(xrange(0, self.glow_index, 3)):
|
||||||
shifted = []
|
shifted = []
|
||||||
for point in self.get_points():
|
for point in self.get_points():
|
||||||
shifted.append((point[0], point[1] - ii))
|
shifted.append((point[0], point[1] - y))
|
||||||
ratio = 1 - float(ii + 1) / (self.MAX_GLOW_INDEX + 1)
|
# ratio = 1 - float(y + 1) / (self.MAX_GLOW_INDEX + 1)
|
||||||
alpha = int(ratio * 255)
|
# alpha = int(ratio * 255)
|
||||||
color = Color(self.color.r, self.color.g, self.color.b, alpha)
|
# color = Color(self.color.r, self.color.g, self.color.b, alpha)
|
||||||
ds = self.get_display_surface()
|
# ds = self.get_display_surface()
|
||||||
intermediate = Surface(ds.get_size(), SRCALPHA)
|
# intermediate = Surface(ds.get_size(), SRCALPHA)
|
||||||
lines(intermediate,
|
if self.position == NS.LSW:
|
||||||
get_hsla_color(int(color.hsla[0]), int(color.hsla[1]), int(color.hsla[2]), int(ratio * 100)),
|
saturation = 0
|
||||||
True, shifted, 5)
|
else:
|
||||||
ds.blit(intermediate, (0, 0))
|
saturation = int((self.color.hsla[1] + 80) % 100)
|
||||||
|
if not ii % 2:
|
||||||
|
lightness = 0
|
||||||
|
else:
|
||||||
|
lightness = 40
|
||||||
|
lines(
|
||||||
|
self.get_display_surface(),
|
||||||
|
get_hsla_color(
|
||||||
|
int(self.color.hsla[0]), saturation, lightness
|
||||||
|
),
|
||||||
|
True, shifted, 3
|
||||||
|
)
|
||||||
|
# ds.blit(intermediate, (0, 0))
|
||||||
|
|
||||||
def in_orientation(self, orientation):
|
def in_orientation(self, orientation):
|
||||||
if self.position == NS.LNW:
|
if self.position == NS.LNW:
|
||||||
|
@ -1097,6 +1109,8 @@ class Boss(Animation):
|
||||||
self.kool_man = RainbowSprite(self, load(self.get_resource("Kool_man_waah.png")).convert_alpha(), 30)
|
self.kool_man = RainbowSprite(self, load(self.get_resource("Kool_man_waah.png")).convert_alpha(), 30)
|
||||||
self.visitor = RainbowSprite(self, load(self.get_resource("Visitor.png")).convert_alpha(), 30)
|
self.visitor = RainbowSprite(self, load(self.get_resource("Visitor.png")).convert_alpha(), 30)
|
||||||
self.spoopy = RainbowSprite(self, load(self.get_resource("Spoopy.png")).convert_alpha(), 30)
|
self.spoopy = RainbowSprite(self, load(self.get_resource("Spoopy.png")).convert_alpha(), 30)
|
||||||
|
for sprite in self.kool_man, self.visitor, self.spoopy:
|
||||||
|
sprite.location.topleft = 100, 0
|
||||||
self.health = Health(self)
|
self.health = Health(self)
|
||||||
self.sword = Sword(self)
|
self.sword = Sword(self)
|
||||||
self.register(self.brandish, self.cancel_flash, self.show_introduction_dialogue,
|
self.register(self.brandish, self.cancel_flash, self.show_introduction_dialogue,
|
||||||
|
@ -1109,9 +1123,9 @@ class Boss(Animation):
|
||||||
self.spoopy_avatar = load(self.get_resource("Spoopy_avatar.png")).convert()
|
self.spoopy_avatar = load(self.get_resource("Spoopy_avatar.png")).convert()
|
||||||
self.advance_prompt = AdvancePrompt(self)
|
self.advance_prompt = AdvancePrompt(self)
|
||||||
self.backgrounds = [Sprite(self), Sprite(self), Sprite(self)]
|
self.backgrounds = [Sprite(self), Sprite(self), Sprite(self)]
|
||||||
self.backgrounds[0].load_from_path(self.get_resource("local/bg001.png"))
|
self.backgrounds[0].load_from_path(self.get_resource("bg/bg001.png"))
|
||||||
self.backgrounds[1].load_from_path(self.get_resource("local/bg002.png"))
|
self.backgrounds[1].load_from_path(self.get_resource("bg/bg002.png"))
|
||||||
self.backgrounds[2].load_from_path(self.get_resource("local/bg003.png"))
|
self.backgrounds[2].load_from_path(self.get_resource("bg/bg003.png"))
|
||||||
|
|
||||||
def cancel_flash(self):
|
def cancel_flash(self):
|
||||||
if self.level_index == 0:
|
if self.level_index == 0:
|
||||||
|
@ -1467,73 +1481,76 @@ class Boss(Animation):
|
||||||
|
|
||||||
class Sword(Animation):
|
class Sword(Animation):
|
||||||
|
|
||||||
OFFSET = 10
|
SHIFT = 15
|
||||||
SPRITE_COUNT = 6
|
SPRITE_COUNT = 6
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
Animation.__init__(self, parent)
|
Animation.__init__(self, parent)
|
||||||
swords = self.swords = []
|
swords = self.swords = []
|
||||||
for path in ("Sword_kool_man.png", "Sword_visitor.png", "Sword_spoopy.png"):
|
for root in "Sword_kool_man/", "Sword_visitor/", "Sword_spoopy/":
|
||||||
swords.append([])
|
swords.append([[], [], [], [], [], []])
|
||||||
image = load(self.get_resource(path)).convert_alpha()
|
for path in sorted(iglob(join(self.get_resource(root), "*.png"))):
|
||||||
for _ in xrange(6):
|
base = load(self.get_resource(path)).convert_alpha()
|
||||||
sprite = Sprite(self)
|
for position in xrange(6):
|
||||||
sprite.add_frame(image)
|
if position == NS.N or position == NS.S:
|
||||||
for angle in 270, 315, 45:
|
rotated = rotate(base, 270)
|
||||||
sprite.add_frame(rotate(image, angle))
|
elif position == NS.NW:
|
||||||
sprite.add_frameset([0], name="vertical")
|
rotated = rotate(base, 45)
|
||||||
sprite.add_frameset([1], name="horizontal")
|
elif position == NS.NE:
|
||||||
sprite.add_frameset([2], name="rdiagonal")
|
rotated = rotate(base, 310)
|
||||||
sprite.add_frameset([3], name="ldiagonal")
|
else:
|
||||||
sprite.set_frameset("vertical")
|
rotated = base
|
||||||
sprite.location.center = self.get_display_surface().get_rect().center
|
surface = rotated.copy()
|
||||||
swords[-1].append(sprite)
|
colors = self.get_game().platform.get_color_pair_from_edge(position)
|
||||||
# for _ in xrange(self.SPRITE_COUNT):
|
color_a = Color(colors[0].r, colors[0].g, colors[0].b, 255)
|
||||||
# sprite = Sprite(self)
|
color_b = Color(colors[1].r, colors[1].g, colors[1].b, 255)
|
||||||
# sprite.load_from_path(self.get_resource("kool/"), True, query="[0-9]-*.png")
|
rect = surface.get_rect()
|
||||||
# for ii in xrange(6):
|
if position == NS.N or position == NS.S:
|
||||||
# sprite.add_frameset(ii)
|
surface.fill(color_a, (0, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
||||||
# sprite.location.topleft = 114, 0
|
surface.fill(color_b, (rect.centerx, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
||||||
# sprites.append(sprite)
|
else:
|
||||||
|
surface.fill(color_a, (0, 0, rect.w, rect.h / 2), BLEND_RGBA_MIN)
|
||||||
|
surface.fill(color_b, (0, rect.centery, rect.w, rect.h / 2), BLEND_RGBA_MIN)
|
||||||
|
swords[-1][position].append(surface)
|
||||||
|
masks = self.masks = []
|
||||||
|
for alpha in xrange(16, 255, 16):
|
||||||
|
surface = Surface((300, 300), SRCALPHA)
|
||||||
|
surface.fill((255, 255, 255, alpha))
|
||||||
|
masks.append(surface)
|
||||||
self.register(self.brandish, self.lower)
|
self.register(self.brandish, self.lower)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.halt(self.brandish)
|
self.halt(self.brandish)
|
||||||
self.halt(self.lower)
|
self.halt(self.lower)
|
||||||
self.next_index = 0
|
self.next_index = 0
|
||||||
self.sprites = self.swords[self.get_game().boss.level_index]
|
self.sprites = []
|
||||||
for sword in self.swords:
|
|
||||||
for sprite in sword:
|
|
||||||
sprite.hide()
|
|
||||||
|
|
||||||
def brandish(self):
|
def brandish(self):
|
||||||
sprite = self.sprites[self.next_index]
|
position = self.parent.unbrandished.pop(0)
|
||||||
sprite.sword_position = position = self.parent.unbrandished.pop(0)
|
offset = -self.SHIFT
|
||||||
self.next_index += 1
|
for ii, queued in enumerate(self.parent.queue):
|
||||||
sprite.unhide()
|
offset += self.SHIFT * (queued == position)
|
||||||
|
if len(self.parent.unbrandished) == len(self.parent.queue) - ii - 1:
|
||||||
|
break
|
||||||
dsr = self.get_display_surface().get_rect()
|
dsr = self.get_display_surface().get_rect()
|
||||||
|
sprite = Sprite(self)
|
||||||
|
for frame in self.swords[self.parent.level_index][position]:
|
||||||
|
sprite.add_frame(frame)
|
||||||
if position in (NS.W, NS.E):
|
if position in (NS.W, NS.E):
|
||||||
sprite.set_frameset("vertical")
|
sprite.location.centery = dsr.centery - 100 + offset
|
||||||
sprite.location.centery = dsr.centery - 100
|
|
||||||
if position == NS.W:
|
if position == NS.W:
|
||||||
sprite.location.centerx = dsr.centerx - 100
|
sprite.location.centerx = dsr.centerx - 100 - offset
|
||||||
else:
|
else:
|
||||||
sprite.location.centerx = dsr.centerx + 100
|
sprite.location.centerx = dsr.centerx + 100 - offset
|
||||||
elif position in (NS.N, NS.S):
|
elif position in (NS.N, NS.S):
|
||||||
sprite.set_frameset("horizontal")
|
sprite.location.centerx = dsr.centerx - offset
|
||||||
sprite.location.centerx = dsr.centerx
|
|
||||||
if position == NS.N:
|
if position == NS.N:
|
||||||
# sprite.location.centery = dsr.centery - 200
|
sprite.location.centery = dsr.centery - 170 + offset
|
||||||
sprite.location.centery = dsr.centery - 170
|
|
||||||
else:
|
else:
|
||||||
sprite.location.centery = dsr.centery
|
sprite.location.centery = dsr.centery + offset
|
||||||
else:
|
else:
|
||||||
if position == NS.NW:
|
sprite.location.center = dsr.centerx - offset, dsr.centery - 100
|
||||||
sprite.set_frameset("ldiagonal")
|
self.sprites.append(sprite)
|
||||||
else:
|
|
||||||
sprite.set_frameset("rdiagonal")
|
|
||||||
sprite.location.center = dsr.centerx, dsr.centery - 100
|
|
||||||
# sprite.set_frameset(position + 1)
|
|
||||||
self.get_game().sfx["brandish"].play()
|
self.get_game().sfx["brandish"].play()
|
||||||
self.play(self.lower, delay=400, play_once=True)
|
self.play(self.lower, delay=400, play_once=True)
|
||||||
if len(self.parent.unbrandished) > 0:
|
if len(self.parent.unbrandished) > 0:
|
||||||
|
@ -1541,52 +1558,25 @@ class Sword(Animation):
|
||||||
play_once=True)
|
play_once=True)
|
||||||
|
|
||||||
def lower(self):
|
def lower(self):
|
||||||
# self.hide()
|
|
||||||
if len(self.parent.unbrandished) == 0:
|
if len(self.parent.unbrandished) == 0:
|
||||||
self.next_index = 0
|
|
||||||
self.parent.brandish_complete = True
|
self.parent.brandish_complete = True
|
||||||
|
|
||||||
def block(self):
|
def block(self):
|
||||||
for sprite in self.sprites:
|
if len(self.sprites):
|
||||||
if not sprite.is_hidden():
|
self.sprites.pop(0)
|
||||||
sprite.hide()
|
|
||||||
break
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
Animation.update(self)
|
Animation.update(self)
|
||||||
display_count = 0
|
for ii, sprite in enumerate(reversed(self.sprites)):
|
||||||
offset = [self.OFFSET] * 6
|
if ii == len(self.sprites) - 1:
|
||||||
for sprite in self.sprites:
|
substitute = None
|
||||||
if not sprite.is_hidden():
|
|
||||||
display_count += 1
|
|
||||||
offset[sprite.sword_position] -= self.OFFSET
|
|
||||||
display_index = 0
|
|
||||||
for sprite in reversed(self.sprites):
|
|
||||||
if not sprite.is_hidden():
|
|
||||||
display_index += 1
|
|
||||||
alpha = int(float(display_index) / display_count * 255)
|
|
||||||
surface = sprite.get_current_frame().copy()
|
|
||||||
rect = surface.get_rect()
|
|
||||||
colors = self.get_game().platform.get_color_pair_from_edge(sprite.sword_position)
|
|
||||||
color_a = colors[0].r, colors[0].g, colors[0].b, alpha
|
|
||||||
color_b = colors[1].r, colors[1].g, colors[1].b, alpha
|
|
||||||
# color_a = 255, 255, 255, alpha
|
|
||||||
# color_b = 255, 255, 255, alpha
|
|
||||||
if sprite.sword_position == NS.NE:
|
|
||||||
location = sprite.location.move(*([offset[sprite.sword_position]] * 2)).topleft
|
|
||||||
else:
|
else:
|
||||||
location = sprite.location.move(offset[sprite.sword_position],
|
mask = self.masks[int(float(ii + 1) / len(self.sprites) * len(self.masks))]
|
||||||
-offset[sprite.sword_position])
|
frame = sprite.get_current_frame()
|
||||||
if sprite.sword_position == NS.N or sprite.sword_position == NS.S:
|
copy = frame.copy()
|
||||||
surface.fill(color_a, (0, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
copy.blit(mask, (0, 0), None, BLEND_RGBA_MIN)
|
||||||
surface.fill(color_b, (rect.centerx, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
substitute = copy
|
||||||
else:
|
sprite.update(substitute=substitute)
|
||||||
surface.fill(color_a, (0, 0, rect.w, rect.h / 2), BLEND_RGBA_MIN)
|
|
||||||
surface.fill(color_b, (0, rect.centery, rect.w, rect.h / 2), BLEND_RGBA_MIN)
|
|
||||||
surface.fill((255, 255, 255, alpha), None, BLEND_RGBA_MIN)
|
|
||||||
self.get_display_surface().blit(surface, location)
|
|
||||||
offset[sprite.sword_position] += self.OFFSET
|
|
||||||
# sprite.update()
|
|
||||||
|
|
||||||
|
|
||||||
class Health(GameChild):
|
class Health(GameChild):
|
||||||
|
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 358 B |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 9.8 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 358 B |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 337 B |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 337 B |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 371 B |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 9.6 KiB |
After Width: | Height: | Size: 7.1 KiB |