From b94d9b49c32fc8cbd9868c1e80208e0d308329a3 Mon Sep 17 00:00:00 2001 From: Frank DeMarco Date: Tue, 10 Jul 2018 00:57:27 -0400 Subject: [PATCH] bar --- NS.py | 45 ++++++++++++++++-------- config | 2 +- resource/HUD_boss_health_background.png | Bin 0 -> 191 bytes resource/HUD_boss_health_foreground.png | Bin 0 -> 478 bytes 4 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 resource/HUD_boss_health_background.png create mode 100644 resource/HUD_boss_health_foreground.png diff --git a/NS.py b/NS.py index 1a2fd2e..769afc3 100644 --- a/NS.py +++ b/NS.py @@ -25,8 +25,10 @@ from lib.pgfw.pgfw.GameChild import GameChild 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, get_hsla_color) +from lib.pgfw.pgfw.extension import ( + get_step, get_step_relative, get_delta, reflect_angle, + render_box, get_hsla_color, get_hue_shifted_surface +) from lib.pgfw.pgfw.gfx_extension import aa_filled_polygon class NS(Game, Animation): @@ -1608,11 +1610,19 @@ class Health(GameChild): TEXT = "BOSS" BAR_POSITION = 23, 11 BACKGROUND_ALPHA = 125 + OFFSET = 11 def __init__(self, parent): GameChild.__init__(self, parent) + # self.background = Sprite(self) + # self.background.load_from_path(self.get_resource("HUD_background.png"), True) self.background = Sprite(self) - self.background.load_from_path(self.get_resource("HUD_background.png"), True) + self.background.load_from_path(self.get_resource("HUD_boss_health_background.png"), True) + dsr = self.get_display_surface().get_rect() + self.background.location.center = dsr.centerx, self.OFFSET + self.foreground = Sprite(self) + self.foreground.load_from_path(self.get_resource("HUD_boss_health_foreground.png"), True) + self.foreground.location.center = dsr.centerx, self.OFFSET self.label = Sprite(self) font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 24) text = font.render(self.TEXT, True, Color("white")) @@ -1635,20 +1645,27 @@ class Health(GameChild): def update(self): self.background.update() - self.label.update() + # self.label.update() if self.amount > 50: - color = 0, 255, 0 + shift = 0 elif self.amount > 25: - color = Color("orange") + shift = -70 else: - color = Color("red") - mask = Surface(self.bar.get_size(), SRCALPHA) - mask.fill((128, 128, 128)) - mask.fill(color, (0, 0, int(mask.get_width() * (self.amount / 100.0)), - 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) + shift = -120 + # mask = Surface(self.bar.get_size(), SRCALPHA) + # mask.fill((128, 128, 128)) + # mask.fill(color, (0, 0, int(mask.get_width() * (self.amount / 100.0)), + # 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) + ratio = self.amount / 100.0 + ds = self.get_display_surface() + ds.set_clip((self.foreground.location.left, self.foreground.location.top, + int(self.foreground.location.w * ratio), self.foreground.location.h)) + surface = get_hue_shifted_surface(self.foreground.get_current_frame(), shift) + ds.blit(surface, self.foreground.location.topleft) + ds.set_clip(None) class Ending(Animation): diff --git a/config b/config index e2fa475..bb9d862 100644 --- a/config +++ b/config @@ -9,7 +9,7 @@ data-exclude = local/, *.pyc [display] caption = Electric Scrapeboard -show-framerate = False +show-framerate = yes dimensions = 640, 480 fullscreen = no diff --git a/resource/HUD_boss_health_background.png b/resource/HUD_boss_health_background.png new file mode 100644 index 0000000000000000000000000000000000000000..494996f80aa66fb2776e25013ff68097c98aba69 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0y~yV9Eos`8n8tWbAzBqd=<7)5S5Q;?~={D+Lc2@VGi^ zpWQKW%3QZQz5xz=a(`#WW@LPEb6E8;@mwVj14G^BYq#d-tKMK>Fk)KgBF*67wr6Sv zGsB6F?Ptvy7*aGYn=v%-r~&Ob#LK|&kc~m%4gOu`+MvU&L@ZNWAfx1)@pm4 zJpcdzfC72dQ07d|T+Fx8v-zMFuA=SNPB?P_00005^R9tRCMT!LxOog{x^7D{VO^nJLrK{61y2#F#Mi zni??1d0eF|kyh)#ea3>@&G<4F)DkOdEp7i^md^7ceadRagqhdWfHCGjo3qxIWp9lp zg4&Dgv0Ta4CuUw#1IC!G&n48_P$RJ`pfJ~k+n-0#6?gXm0000K%(|LBxZRDfV{NGq z6ZG7pe*z)R)0CIpr_7#SwKFEnyru?>@qb;VERk00hMJi{&M&f^j(1)74v#ELTDWf+ zEr~H<<~227jB~h3St700Eo(@U!gtxWYY!IQ-X=*p=F0>C0000>VKX@H1Yaij26aBn U1Ez)9y8r+H07*qoM6N<$g6u5VHUIzs literal 0 HcmV?d00001