score
This commit is contained in:
parent
ce51eb0845
commit
970484e64f
63
NS.py
63
NS.py
|
@ -20,7 +20,8 @@ from lib.pgfw.pgfw.Game import Game
|
||||||
from lib.pgfw.pgfw.GameChild import GameChild
|
from lib.pgfw.pgfw.GameChild import GameChild
|
||||||
from lib.pgfw.pgfw.Sprite import Sprite, RainbowSprite
|
from lib.pgfw.pgfw.Sprite import Sprite, RainbowSprite
|
||||||
from lib.pgfw.pgfw.Animation import Animation
|
from lib.pgfw.pgfw.Animation import Animation
|
||||||
from lib.pgfw.pgfw.extension import get_step, get_step_relative, get_delta, reflect_angle
|
from lib.pgfw.pgfw.extension import (get_step, get_step_relative, get_delta, reflect_angle,
|
||||||
|
render_box)
|
||||||
from lib.pgfw.pgfw.gfx_extension import aa_filled_polygon
|
from lib.pgfw.pgfw.gfx_extension import aa_filled_polygon
|
||||||
|
|
||||||
class SoundEffect(GameChild, Sound):
|
class SoundEffect(GameChild, Sound):
|
||||||
|
@ -77,7 +78,10 @@ class NS(Game, Animation):
|
||||||
self.chemtrails = Chemtrails(self)
|
self.chemtrails = Chemtrails(self)
|
||||||
self.boss = Boss(self)
|
self.boss = Boss(self)
|
||||||
self.last_press = get_ticks()
|
self.last_press = get_ticks()
|
||||||
|
self.register(self.blink_score, interval=500)
|
||||||
|
self.play(self.blink_score)
|
||||||
self.reset()
|
self.reset()
|
||||||
|
self.most_recent_time = None
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
def load_sfx(self):
|
def load_sfx(self):
|
||||||
|
@ -86,6 +90,7 @@ class NS(Game, Animation):
|
||||||
sfx[basename(path.split(".")[0])] = SoundEffect(self, path)
|
sfx[basename(path.split(".")[0])] = SoundEffect(self, path)
|
||||||
|
|
||||||
def reset(self, leave_wipe_running=False):
|
def reset(self, leave_wipe_running=False):
|
||||||
|
self.score_hidden = False
|
||||||
self.idle_elapsed = 0
|
self.idle_elapsed = 0
|
||||||
self.suppressing_input = False
|
self.suppressing_input = False
|
||||||
self.title.reset()
|
self.title.reset()
|
||||||
|
@ -98,6 +103,12 @@ class NS(Game, Animation):
|
||||||
self.platform.reset()
|
self.platform.reset()
|
||||||
self.dialogue.reset()
|
self.dialogue.reset()
|
||||||
|
|
||||||
|
def set_most_recent_time(self, score):
|
||||||
|
self.most_recent_time = score
|
||||||
|
|
||||||
|
def blink_score(self):
|
||||||
|
self.score_hidden = not self.score_hidden
|
||||||
|
|
||||||
def suppress_input(self):
|
def suppress_input(self):
|
||||||
self.suppressing_input = True
|
self.suppressing_input = True
|
||||||
# self.platform.unpress()
|
# self.platform.unpress()
|
||||||
|
@ -182,6 +193,38 @@ class Title(GameChild):
|
||||||
def activate_introduction(self):
|
def activate_introduction(self):
|
||||||
self.deactivate()
|
self.deactivate()
|
||||||
self.get_game().introduction.activate()
|
self.get_game().introduction.activate()
|
||||||
|
self.get_game().set_most_recent_time(None)
|
||||||
|
|
||||||
|
def draw_scores(self):
|
||||||
|
step = 75
|
||||||
|
ds = self.get_display_surface()
|
||||||
|
lines = map(int, file(self.get_resource("scores")).readlines())
|
||||||
|
entries = ["BEST"] + sorted(lines)[:9]
|
||||||
|
for ii, entry in enumerate(entries):
|
||||||
|
if ii == 0 or ii == 5:
|
||||||
|
y = 30
|
||||||
|
font = Font(self.get_resource(Dialogue.FONT_PATH), 18)
|
||||||
|
if ii > 0:
|
||||||
|
text = self.get_formatted_time(entry)
|
||||||
|
else:
|
||||||
|
text = entry
|
||||||
|
message = render_box(font, text, True, Color(255, 255, 255),
|
||||||
|
Color(128, 128, 128), Color(0, 0, 0), padding=2)
|
||||||
|
message.set_alpha(200)
|
||||||
|
rect = message.get_rect()
|
||||||
|
rect.top = y
|
||||||
|
if ii < 5:
|
||||||
|
rect.left = -1
|
||||||
|
else:
|
||||||
|
rect.right = ds.get_width() + 1
|
||||||
|
if not entry == self.get_game().most_recent_time or not self.get_game().score_hidden:
|
||||||
|
ds.blit(message, rect)
|
||||||
|
y += step
|
||||||
|
|
||||||
|
def get_formatted_time(self, entry):
|
||||||
|
minutes, milliseconds = divmod(int(entry), 60000)
|
||||||
|
seconds, fraction = divmod(milliseconds, 1000)
|
||||||
|
return "%i:%02i.%i" % (minutes, seconds, fraction / 100)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.active:
|
if self.active:
|
||||||
|
@ -222,6 +265,7 @@ class Title(GameChild):
|
||||||
self.text.set_frameset("full")
|
self.text.set_frameset("full")
|
||||||
self.border.update()
|
self.border.update()
|
||||||
self.text.update()
|
self.text.update()
|
||||||
|
self.draw_scores()
|
||||||
|
|
||||||
|
|
||||||
class Dialogue(Animation):
|
class Dialogue(Animation):
|
||||||
|
@ -398,7 +442,7 @@ class Introduction(Animation):
|
||||||
|
|
||||||
def activate_boss(self):
|
def activate_boss(self):
|
||||||
self.deactivate()
|
self.deactivate()
|
||||||
self.get_game().boss.start_level(2)
|
self.get_game().boss.start_level(0)
|
||||||
|
|
||||||
def start_wipe(self):
|
def start_wipe(self):
|
||||||
self.get_game().wipe.start(self.activate_boss)
|
self.get_game().wipe.start(self.activate_boss)
|
||||||
|
@ -1057,6 +1101,7 @@ class Boss(Animation):
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.level_index = 0
|
self.level_index = 0
|
||||||
self.kills = 0
|
self.kills = 0
|
||||||
|
self.time_elapsed = 0
|
||||||
self.deactivate()
|
self.deactivate()
|
||||||
self.cancel_flash()
|
self.cancel_flash()
|
||||||
self.halt(self.cancel_flash)
|
self.halt(self.cancel_flash)
|
||||||
|
@ -1263,10 +1308,15 @@ class Boss(Animation):
|
||||||
self.visitor.set_frameset(0)
|
self.visitor.set_frameset(0)
|
||||||
elif self.level_index == 2:
|
elif self.level_index == 2:
|
||||||
self.spoopy.set_frameset(0)
|
self.spoopy.set_frameset(0)
|
||||||
|
self.add_score()
|
||||||
self.player_defeated = not win
|
self.player_defeated = not win
|
||||||
self.kills += not win
|
self.kills += not win
|
||||||
self.play(self.show_end_dialogue, delay=3000, play_once=True)
|
self.play(self.show_end_dialogue, delay=3000, play_once=True)
|
||||||
|
|
||||||
|
def add_score(self):
|
||||||
|
self.get_game().set_most_recent_time(self.time_elapsed)
|
||||||
|
file(self.get_resource("scores"), "a").write(str(self.time_elapsed) + "\n")
|
||||||
|
|
||||||
def show_end_dialogue(self):
|
def show_end_dialogue(self):
|
||||||
dialogue = self.get_game().dialogue
|
dialogue = self.get_game().dialogue
|
||||||
dialogue.activate()
|
dialogue.activate()
|
||||||
|
@ -1326,6 +1376,8 @@ class Boss(Animation):
|
||||||
else:
|
else:
|
||||||
self.get_game().wipe.start(self.transition_to_battle)
|
self.get_game().wipe.start(self.transition_to_battle)
|
||||||
self.advance_prompt.cancel_first_press()
|
self.advance_prompt.cancel_first_press()
|
||||||
|
else:
|
||||||
|
self.time_elapsed += self.get_game().time_filter.get_last_frame_duration()
|
||||||
Animation.update(self)
|
Animation.update(self)
|
||||||
if self.level_index == 0:
|
if self.level_index == 0:
|
||||||
self.kool_man.update()
|
self.kool_man.update()
|
||||||
|
@ -1532,6 +1584,13 @@ class Ending(Animation):
|
||||||
self.advance_prompt.cancel_first_press()
|
self.advance_prompt.cancel_first_press()
|
||||||
self.get_display_surface().blit(self.tony, (0, 0))
|
self.get_display_surface().blit(self.tony, (0, 0))
|
||||||
self.slime_bag.update()
|
self.slime_bag.update()
|
||||||
|
font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 36)
|
||||||
|
text = font.render(self.get_game().title.get_formatted_time(self.get_game().most_recent_time),
|
||||||
|
True, Color("black"))
|
||||||
|
rect = text.get_rect()
|
||||||
|
ds = self.get_display_surface()
|
||||||
|
rect.midtop = ds.get_rect().centerx, 320
|
||||||
|
ds.blit(text, rect)
|
||||||
self.get_game().dialogue.update()
|
self.get_game().dialogue.update()
|
||||||
if not wipe.is_playing() and not self.is_playing(self.start):
|
if not wipe.is_playing() and not self.is_playing(self.start):
|
||||||
self.advance_prompt.update()
|
self.advance_prompt.update()
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
||||||
|
5999999
|
Loading…
Reference in New Issue