spin
192
NS.py
|
@ -4,7 +4,7 @@ from random import randint, choice
|
|||
from math import pi
|
||||
from copy import copy
|
||||
from glob import iglob
|
||||
from os.path import basename
|
||||
from os.path import basename, join
|
||||
from threading import Thread
|
||||
from serial import Serial
|
||||
from PIL import Image, ImageDraw
|
||||
|
@ -803,7 +803,7 @@ class Platform(GameChild):
|
|||
|
||||
class Light(Animation):
|
||||
|
||||
MAX_GLOW_INDEX = 16
|
||||
MAX_GLOW_INDEX = 25
|
||||
INTRODUCTION_OFFSET = 80
|
||||
|
||||
def __init__(self, parent, color, position):
|
||||
|
@ -875,19 +875,31 @@ class Light(Animation):
|
|||
return self.points
|
||||
|
||||
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 = []
|
||||
for point in self.get_points():
|
||||
shifted.append((point[0], point[1] - ii))
|
||||
ratio = 1 - float(ii + 1) / (self.MAX_GLOW_INDEX + 1)
|
||||
alpha = int(ratio * 255)
|
||||
color = Color(self.color.r, self.color.g, self.color.b, alpha)
|
||||
ds = self.get_display_surface()
|
||||
intermediate = Surface(ds.get_size(), SRCALPHA)
|
||||
lines(intermediate,
|
||||
get_hsla_color(int(color.hsla[0]), int(color.hsla[1]), int(color.hsla[2]), int(ratio * 100)),
|
||||
True, shifted, 5)
|
||||
ds.blit(intermediate, (0, 0))
|
||||
shifted.append((point[0], point[1] - y))
|
||||
# ratio = 1 - float(y + 1) / (self.MAX_GLOW_INDEX + 1)
|
||||
# alpha = int(ratio * 255)
|
||||
# color = Color(self.color.r, self.color.g, self.color.b, alpha)
|
||||
# ds = self.get_display_surface()
|
||||
# intermediate = Surface(ds.get_size(), SRCALPHA)
|
||||
if self.position == NS.LSW:
|
||||
saturation = 0
|
||||
else:
|
||||
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):
|
||||
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.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)
|
||||
for sprite in self.kool_man, self.visitor, self.spoopy:
|
||||
sprite.location.topleft = 100, 0
|
||||
self.health = Health(self)
|
||||
self.sword = Sword(self)
|
||||
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.advance_prompt = AdvancePrompt(self)
|
||||
self.backgrounds = [Sprite(self), Sprite(self), Sprite(self)]
|
||||
self.backgrounds[0].load_from_path(self.get_resource("local/bg001.png"))
|
||||
self.backgrounds[1].load_from_path(self.get_resource("local/bg002.png"))
|
||||
self.backgrounds[2].load_from_path(self.get_resource("local/bg003.png"))
|
||||
self.backgrounds[0].load_from_path(self.get_resource("bg/bg001.png"))
|
||||
self.backgrounds[1].load_from_path(self.get_resource("bg/bg002.png"))
|
||||
self.backgrounds[2].load_from_path(self.get_resource("bg/bg003.png"))
|
||||
|
||||
def cancel_flash(self):
|
||||
if self.level_index == 0:
|
||||
|
@ -1467,73 +1481,76 @@ class Boss(Animation):
|
|||
|
||||
class Sword(Animation):
|
||||
|
||||
OFFSET = 10
|
||||
SHIFT = 15
|
||||
SPRITE_COUNT = 6
|
||||
|
||||
def __init__(self, parent):
|
||||
Animation.__init__(self, parent)
|
||||
swords = self.swords = []
|
||||
for path in ("Sword_kool_man.png", "Sword_visitor.png", "Sword_spoopy.png"):
|
||||
swords.append([])
|
||||
image = load(self.get_resource(path)).convert_alpha()
|
||||
for _ in xrange(6):
|
||||
sprite = Sprite(self)
|
||||
sprite.add_frame(image)
|
||||
for angle in 270, 315, 45:
|
||||
sprite.add_frame(rotate(image, angle))
|
||||
sprite.add_frameset([0], name="vertical")
|
||||
sprite.add_frameset([1], name="horizontal")
|
||||
sprite.add_frameset([2], name="rdiagonal")
|
||||
sprite.add_frameset([3], name="ldiagonal")
|
||||
sprite.set_frameset("vertical")
|
||||
sprite.location.center = self.get_display_surface().get_rect().center
|
||||
swords[-1].append(sprite)
|
||||
# for _ in xrange(self.SPRITE_COUNT):
|
||||
# sprite = Sprite(self)
|
||||
# sprite.load_from_path(self.get_resource("kool/"), True, query="[0-9]-*.png")
|
||||
# for ii in xrange(6):
|
||||
# sprite.add_frameset(ii)
|
||||
# sprite.location.topleft = 114, 0
|
||||
# sprites.append(sprite)
|
||||
for root in "Sword_kool_man/", "Sword_visitor/", "Sword_spoopy/":
|
||||
swords.append([[], [], [], [], [], []])
|
||||
for path in sorted(iglob(join(self.get_resource(root), "*.png"))):
|
||||
base = load(self.get_resource(path)).convert_alpha()
|
||||
for position in xrange(6):
|
||||
if position == NS.N or position == NS.S:
|
||||
rotated = rotate(base, 270)
|
||||
elif position == NS.NW:
|
||||
rotated = rotate(base, 45)
|
||||
elif position == NS.NE:
|
||||
rotated = rotate(base, 310)
|
||||
else:
|
||||
rotated = base
|
||||
surface = rotated.copy()
|
||||
colors = self.get_game().platform.get_color_pair_from_edge(position)
|
||||
color_a = Color(colors[0].r, colors[0].g, colors[0].b, 255)
|
||||
color_b = Color(colors[1].r, colors[1].g, colors[1].b, 255)
|
||||
rect = surface.get_rect()
|
||||
if position == NS.N or position == NS.S:
|
||||
surface.fill(color_a, (0, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
||||
surface.fill(color_b, (rect.centerx, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
||||
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)
|
||||
|
||||
def reset(self):
|
||||
self.halt(self.brandish)
|
||||
self.halt(self.lower)
|
||||
self.next_index = 0
|
||||
self.sprites = self.swords[self.get_game().boss.level_index]
|
||||
for sword in self.swords:
|
||||
for sprite in sword:
|
||||
sprite.hide()
|
||||
self.sprites = []
|
||||
|
||||
def brandish(self):
|
||||
sprite = self.sprites[self.next_index]
|
||||
sprite.sword_position = position = self.parent.unbrandished.pop(0)
|
||||
self.next_index += 1
|
||||
sprite.unhide()
|
||||
position = self.parent.unbrandished.pop(0)
|
||||
offset = -self.SHIFT
|
||||
for ii, queued in enumerate(self.parent.queue):
|
||||
offset += self.SHIFT * (queued == position)
|
||||
if len(self.parent.unbrandished) == len(self.parent.queue) - ii - 1:
|
||||
break
|
||||
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):
|
||||
sprite.set_frameset("vertical")
|
||||
sprite.location.centery = dsr.centery - 100
|
||||
sprite.location.centery = dsr.centery - 100 + offset
|
||||
if position == NS.W:
|
||||
sprite.location.centerx = dsr.centerx - 100
|
||||
sprite.location.centerx = dsr.centerx - 100 - offset
|
||||
else:
|
||||
sprite.location.centerx = dsr.centerx + 100
|
||||
sprite.location.centerx = dsr.centerx + 100 - offset
|
||||
elif position in (NS.N, NS.S):
|
||||
sprite.set_frameset("horizontal")
|
||||
sprite.location.centerx = dsr.centerx
|
||||
sprite.location.centerx = dsr.centerx - offset
|
||||
if position == NS.N:
|
||||
# sprite.location.centery = dsr.centery - 200
|
||||
sprite.location.centery = dsr.centery - 170
|
||||
sprite.location.centery = dsr.centery - 170 + offset
|
||||
else:
|
||||
sprite.location.centery = dsr.centery
|
||||
sprite.location.centery = dsr.centery + offset
|
||||
else:
|
||||
if position == NS.NW:
|
||||
sprite.set_frameset("ldiagonal")
|
||||
else:
|
||||
sprite.set_frameset("rdiagonal")
|
||||
sprite.location.center = dsr.centerx, dsr.centery - 100
|
||||
# sprite.set_frameset(position + 1)
|
||||
sprite.location.center = dsr.centerx - offset, dsr.centery - 100
|
||||
self.sprites.append(sprite)
|
||||
self.get_game().sfx["brandish"].play()
|
||||
self.play(self.lower, delay=400, play_once=True)
|
||||
if len(self.parent.unbrandished) > 0:
|
||||
|
@ -1541,52 +1558,25 @@ class Sword(Animation):
|
|||
play_once=True)
|
||||
|
||||
def lower(self):
|
||||
# self.hide()
|
||||
if len(self.parent.unbrandished) == 0:
|
||||
self.next_index = 0
|
||||
self.parent.brandish_complete = True
|
||||
|
||||
def block(self):
|
||||
for sprite in self.sprites:
|
||||
if not sprite.is_hidden():
|
||||
sprite.hide()
|
||||
break
|
||||
if len(self.sprites):
|
||||
self.sprites.pop(0)
|
||||
|
||||
def update(self):
|
||||
Animation.update(self)
|
||||
display_count = 0
|
||||
offset = [self.OFFSET] * 6
|
||||
for sprite in self.sprites:
|
||||
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:
|
||||
location = sprite.location.move(offset[sprite.sword_position],
|
||||
-offset[sprite.sword_position])
|
||||
if sprite.sword_position == NS.N or sprite.sword_position == NS.S:
|
||||
surface.fill(color_a, (0, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
||||
surface.fill(color_b, (rect.centerx, 0, rect.w / 2, rect.h), BLEND_RGBA_MIN)
|
||||
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)
|
||||
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()
|
||||
for ii, sprite in enumerate(reversed(self.sprites)):
|
||||
if ii == len(self.sprites) - 1:
|
||||
substitute = None
|
||||
else:
|
||||
mask = self.masks[int(float(ii + 1) / len(self.sprites) * len(self.masks))]
|
||||
frame = sprite.get_current_frame()
|
||||
copy = frame.copy()
|
||||
copy.blit(mask, (0, 0), None, BLEND_RGBA_MIN)
|
||||
substitute = copy
|
||||
sprite.update(substitute=substitute)
|
||||
|
||||
|
||||
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 |