This commit is contained in:
Frank DeMarco 2018-07-09 20:06:32 -04:00
parent 93af99ecf7
commit 8f7be5556b
2 changed files with 22 additions and 29 deletions

50
NS.py
View File

@ -25,7 +25,7 @@ from lib.pgfw.pgfw.Sprite import Sprite, RainbowSprite
from lib.pgfw.pgfw.Animation import Animation
from lib.pgfw.pgfw.Audio import SoundEffect
from lib.pgfw.pgfw.extension import (get_step, get_step_relative, get_delta, reflect_angle,
render_box)
render_box, get_hsla_color)
from lib.pgfw.pgfw.gfx_extension import aa_filled_polygon
class NS(Game, Animation):
@ -987,6 +987,9 @@ class Timer(GameChild):
TEXT = u"\u25F7"
BAR_POSITION = 448, 11
SIZE = 160
TOP = 120
RING_OFFSET = 8
def __init__(self, parent):
GameChild.__init__(self, parent)
@ -1012,40 +1015,29 @@ class Timer(GameChild):
self.time_remaining -= self.get_game().time_filter.get_last_frame_duration()
def update(self):
# self.background.update()
# self.label.update()
if self.time_remaining > 5500:
color = Color(0, 255, 0)
hue = 120
elif self.time_remaining > 3000:
color = Color("orange")
hue = 30
else:
color = Color("red")
hue = 0
ds = self.get_display_surface()
max_time = self.get_configuration("time", "timer-max-time")
size = 160
top = 120
image = Image.new("RGBA", (size, size))
shadow = Image.new("RGBA", (size, size))
remaining_ratio = float(self.time_remaining) / max_time
left = ds.get_width() - self.SIZE / 2
ds.blit(self.get_ring(get_hsla_color(hue, lightness=20, alpha=67), remaining_ratio),
(left, self.TOP + self.RING_OFFSET))
ds.blit(self.get_ring(get_hsla_color(hue, lightness=80, alpha=67), remaining_ratio),
(left, self.TOP - self.RING_OFFSET))
ds.blit(self.get_ring(get_hsla_color(hue, alpha=67), remaining_ratio), (left, self.TOP))
def get_ring(self, color, remaining):
image = Image.new("RGBA", (self.SIZE, self.SIZE))
draw = ImageDraw.Draw(image)
draw_shadow = ImageDraw.Draw(shadow)
draw.pieslice((0, 0, size - 1, size - 1), 90, float(self.time_remaining) / max_time * 180 + 90,
fill=(color.r, color.g, color.b, 128))
draw_shadow.pieslice((0, 0, size - 1, size - 1), 90, float(self.time_remaining) / max_time * 180 + 90,
fill=(0, 0, 0, 128))
draw.ellipse((40, 40, 120, 120), (0, 0, 0, 0))
draw_shadow.ellipse((40, 40, 120, 120), (0, 0, 0, 0))
surface = fromstring(image.tobytes(), image.size, image.mode)
surface_shadow = fromstring(shadow.tobytes(), shadow.size, shadow.mode)
ds.blit(surface_shadow, (ds.get_width() - size / 2, top + 8))
ds.blit(surface, (ds.get_width() - size / 2, top))
# mask = Surface(self.bar.get_size())
# mask.fill((128, 128, 128))
# width = min(mask.get_width(), mask.get_width() * float(self.time_remaining) /
# self.get_configuration("time", "timer-max-time"))
# mask.fill(color, (mask.get_width() - width, 0, width, mask.get_height()))
# surface = self.bar.copy()
# surface.blit(mask, (0, 0), None, BLEND_RGBA_MIN)
# self.get_display_surface().blit(surface, self.BAR_POSITION)
draw.pieslice((0, 0, self.SIZE - 1, self.SIZE - 1), 90, remaining * 180 + 90,
fill=(color.r, color.g, color.b, color.a))
draw.ellipse((self.SIZE / 4, self.SIZE / 4, self.SIZE / 4 * 3, self.SIZE / 4 * 3), (0, 0, 0, 0))
return fromstring(image.tobytes(), image.size, image.mode)
class Life(GameChild):

View File

@ -32,3 +32,4 @@
202333
278582
286504
179511