diff --git a/NS.py b/NS.py index 110039e..723f728 100644 --- a/NS.py +++ b/NS.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from random import randint, choice from math import pi from copy import copy @@ -5,7 +7,7 @@ from copy import copy from pygame import Surface, Color from pygame.mixer import Sound from pygame.image import load -from pygame.transform import rotate +from pygame.transform import rotate, flip from pygame.time import get_ticks from pygame.font import Font from pygame.gfxdraw import aapolygon @@ -754,11 +756,12 @@ class Chemtrails(GameChild): GameChild.__init__(self, parent) self.image = load(self.get_resource("Chemtrails.png")).convert_alpha() self.life = Life(self) + self.timer = Timer(self) def reset(self): self.deactivate() self.life.reset() - self.timer_remaining = self.TIME_LIMIT + self.timer.reset() def deactivate(self): self.active = False @@ -767,7 +770,7 @@ class Chemtrails(GameChild): self.active = True def challenge(self): - self.timer_remaining = self.TIME_LIMIT + self.timer.reset() self.queue_index = 0 def update(self): @@ -775,30 +778,31 @@ class Chemtrails(GameChild): self.orient() if not self.get_game().introduction.active: if self.get_game().boss.queue: - self.timer_remaining -= self.get_game().time_filter.get_last_frame_duration() + self.timer.tick() self.attack() - if self.timer_remaining < 0: + if self.timer.time_remaining < 0: self.life.decrease() if not self.get_game().game_over: - self.timer_remaining = self.TIME_LIMIT + self.timer.reset() self.get_game().boss.combo() - font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 24) - text = font.render("%.2f" % max(0, self.timer_remaining / 1000.0), True, Color("white")) - rect = text.get_rect() - ds = self.get_display_surface() - rect.topright = ds.get_rect().topright - ds.blit(text, rect) + # font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 24) + # text = font.render("%.2f" % max(0, self.timer_remaining / 1000.0), True, Color("white")) + # rect = text.get_rect() + # ds = self.get_display_surface() + # rect.topright = ds.get_rect().topright + # ds.blit(text, rect) + self.timer.update() self.life.update() def attack(self): boss = self.get_game().boss queue = boss.queue if self.orientation == queue[self.queue_index]: - self.timer_remaining += self.TIME_ADDITION + self.timer.add_time(self.TIME_ADDITION) boss.health.decrease(5) self.queue_index += 1 if self.queue_index == len(queue): - self.timer_remaining = self.TIME_LIMIT + self.timer.reset() self.get_game().boss.combo() self.get_game().platform.reset_lights() @@ -849,6 +853,54 @@ class Chemtrails(GameChild): self.orientation = None +class Timer(GameChild): + + TEXT = u"\u25F7" + BAR_POSITION = 448, 11 + MAX_TIME = 12000 + START_TIME = 8000 + + def __init__(self, parent): + GameChild.__init__(self, parent) + self.background = Sprite(self) + image = load(self.get_resource("HUD_background.png")).convert_alpha() + image = flip(image, True, False) + self.background.add_frame(image) + self.background.location.topright = self.get_display_surface().get_rect().topright + self.bar = load(self.get_resource("HUD_bar.png")).convert_alpha() + self.bar = flip(self.bar, True, False) + self.label = Sprite(self) + self.label.load_from_path(self.get_resource("Timer_label.png"), True) + dsr = self.get_display_surface().get_rect() + self.label.location.topright = dsr.right - 2, 5 + + def reset(self): + self.time_remaining = self.START_TIME + + def add_time(self, amount): + self.time_remaining += amount + + def tick(self): + 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 = 0, 255, 0 + elif self.time_remaining > 3000: + color = Color("orange") + else: + color = Color("red") + mask = Surface(self.bar.get_size()) + mask.fill((128, 128, 128)) + width = min(mask.get_width(), mask.get_width() * self.time_remaining / float(self.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) + + class Life(GameChild): SPACING = 30 diff --git a/resource/Timer_label.png b/resource/Timer_label.png new file mode 100644 index 0000000..a78a0ae Binary files /dev/null and b/resource/Timer_label.png differ