This commit is contained in:
Frank DeMarco 2017-12-25 05:30:10 -05:00
parent 0a54991051
commit 5cf76fad2f
2 changed files with 66 additions and 14 deletions

80
NS.py
View File

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
from random import randint, choice from random import randint, choice
from math import pi from math import pi
from copy import copy from copy import copy
@ -5,7 +7,7 @@ from copy import copy
from pygame import Surface, Color from pygame import Surface, Color
from pygame.mixer import Sound from pygame.mixer import Sound
from pygame.image import load from pygame.image import load
from pygame.transform import rotate from pygame.transform import rotate, flip
from pygame.time import get_ticks from pygame.time import get_ticks
from pygame.font import Font from pygame.font import Font
from pygame.gfxdraw import aapolygon from pygame.gfxdraw import aapolygon
@ -754,11 +756,12 @@ class Chemtrails(GameChild):
GameChild.__init__(self, parent) GameChild.__init__(self, parent)
self.image = load(self.get_resource("Chemtrails.png")).convert_alpha() self.image = load(self.get_resource("Chemtrails.png")).convert_alpha()
self.life = Life(self) self.life = Life(self)
self.timer = Timer(self)
def reset(self): def reset(self):
self.deactivate() self.deactivate()
self.life.reset() self.life.reset()
self.timer_remaining = self.TIME_LIMIT self.timer.reset()
def deactivate(self): def deactivate(self):
self.active = False self.active = False
@ -767,7 +770,7 @@ class Chemtrails(GameChild):
self.active = True self.active = True
def challenge(self): def challenge(self):
self.timer_remaining = self.TIME_LIMIT self.timer.reset()
self.queue_index = 0 self.queue_index = 0
def update(self): def update(self):
@ -775,30 +778,31 @@ class Chemtrails(GameChild):
self.orient() self.orient()
if not self.get_game().introduction.active: if not self.get_game().introduction.active:
if self.get_game().boss.queue: if self.get_game().boss.queue:
self.timer_remaining -= self.get_game().time_filter.get_last_frame_duration() self.timer.tick()
self.attack() self.attack()
if self.timer_remaining < 0: if self.timer.time_remaining < 0:
self.life.decrease() self.life.decrease()
if not self.get_game().game_over: if not self.get_game().game_over:
self.timer_remaining = self.TIME_LIMIT self.timer.reset()
self.get_game().boss.combo() self.get_game().boss.combo()
font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 24) # 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")) # text = font.render("%.2f" % max(0, self.timer_remaining / 1000.0), True, Color("white"))
rect = text.get_rect() # rect = text.get_rect()
ds = self.get_display_surface() # ds = self.get_display_surface()
rect.topright = ds.get_rect().topright # rect.topright = ds.get_rect().topright
ds.blit(text, rect) # ds.blit(text, rect)
self.timer.update()
self.life.update() self.life.update()
def attack(self): def attack(self):
boss = self.get_game().boss boss = self.get_game().boss
queue = boss.queue queue = boss.queue
if self.orientation == queue[self.queue_index]: if self.orientation == queue[self.queue_index]:
self.timer_remaining += self.TIME_ADDITION self.timer.add_time(self.TIME_ADDITION)
boss.health.decrease(5) boss.health.decrease(5)
self.queue_index += 1 self.queue_index += 1
if self.queue_index == len(queue): if self.queue_index == len(queue):
self.timer_remaining = self.TIME_LIMIT self.timer.reset()
self.get_game().boss.combo() self.get_game().boss.combo()
self.get_game().platform.reset_lights() self.get_game().platform.reset_lights()
@ -849,6 +853,54 @@ class Chemtrails(GameChild):
self.orientation = None 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): class Life(GameChild):
SPACING = 30 SPACING = 30

BIN
resource/Timer_label.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B