This commit is contained in:
Frank DeMarco 2018-06-21 16:07:11 -04:00
parent 9f074a70ab
commit bda97667fc
1 changed files with 29 additions and 22 deletions

51
NS.py
View File

@ -1412,6 +1412,8 @@ class Boss(Animation):
class Sword(Animation): class Sword(Animation):
OFFSET = 10
def __init__(self, parent): def __init__(self, parent):
Animation.__init__(self, parent) Animation.__init__(self, parent)
image = load(self.get_resource("Sword.png")).convert_alpha() image = load(self.get_resource("Sword.png")).convert_alpha()
@ -1483,31 +1485,36 @@ class Sword(Animation):
def update(self): def update(self):
Animation.update(self) Animation.update(self)
display_count = 0 display_count = 0
displayed_positions = [] offset = [self.OFFSET] * 6
displayed_sprites = []
for sprite in self.sprites: for sprite in self.sprites:
if not sprite.is_hidden(): if not sprite.is_hidden():
if sprite.sword_position not in displayed_positions: display_count += 1
display_count += 1 offset[sprite.sword_position] -= self.OFFSET
displayed_positions.append(sprite.sword_position)
displayed_sprites.append(sprite)
display_index = 0 display_index = 0
for sprite in reversed(displayed_sprites): for sprite in reversed(self.sprites):
display_index += 1 if not sprite.is_hidden():
alpha = int(float(display_index) / display_count * 255) display_index += 1
frame = sprite.get_current_frame() alpha = int(float(display_index) / display_count * 255)
surface = frame.copy() frame = sprite.get_current_frame()
rect = surface.get_rect() surface = frame.copy()
colors = self.get_game().platform.get_color_pair_from_edge(sprite.sword_position) rect = surface.get_rect()
color_a = colors[0].r, colors[0].g, colors[0].b, alpha colors = self.get_game().platform.get_color_pair_from_edge(sprite.sword_position)
color_b = colors[1].r, colors[1].g, colors[1].b, alpha color_a = colors[0].r, colors[0].g, colors[0].b, alpha
if sprite.sword_position == NS.N or sprite.sword_position == NS.S: color_b = colors[1].r, colors[1].g, colors[1].b, alpha
surface.fill(color_a, (0, 0, rect.w / 2, rect.h), BLEND_RGBA_MULT) if sprite.sword_position == NS.NE:
surface.fill(color_b, (rect.centerx, 0, rect.w / 2, rect.h), BLEND_RGBA_MULT) location = sprite.location.move(*([offset[sprite.sword_position]] * 2)).topleft
else: else:
surface.fill(color_a, (0, 0, rect.w, rect.h / 2), BLEND_RGBA_MULT) location = sprite.location.move(offset[sprite.sword_position],
surface.fill(color_b, (0, rect.centery, rect.w, rect.h / 2), BLEND_RGBA_MULT) -offset[sprite.sword_position])
self.get_display_surface().blit(surface, sprite.location.topleft) 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_MULT)
surface.fill(color_b, (rect.centerx, 0, rect.w / 2, rect.h), BLEND_RGBA_MULT)
self.get_display_surface().blit(surface, location)
else:
surface.fill(color_a, (0, 0, rect.w, rect.h / 2), BLEND_RGBA_MULT)
surface.fill(color_b, (0, rect.centery, rect.w, rect.h / 2), BLEND_RGBA_MULT)
self.get_display_surface().blit(surface, location)
offset[sprite.sword_position] += self.OFFSET
# sprite.update() # sprite.update()