scoreboard
authorFrank DeMarco <frank.s.demarco@gmail.com>
Sun, 27 Apr 2014 21:35:35 +0000 (06:35 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Sun, 27 Apr 2014 21:35:35 +0000 (06:35 +0900)
config
scale_sieve/ScaleSieve.py

diff --git a/config b/config
index d8916f9..84fb38e 100644 (file)
--- a/config
+++ b/config
@@ -11,6 +11,9 @@ visible = no
 quit = K_ESCAPE
 advance = K_RETURN
 
+[score]
+path = high-scores
+
 [interpolate]
 volume = C 0.0 0.0, 16.0 0.61, 80.0 1.0
 scale = C 0.0 40.0, 400.0 140.0
index 1c225e1..9b5ea69 100644 (file)
@@ -55,8 +55,8 @@ class Title(GameChild):
         font.set_italic(True)
         font.set_bold(True)
         self.captions = captions = Sprite(self), Sprite(self)
-        colors = (255, 204, 0), (0, 68, 170), (255, 255, 255), (128, 128, 128), \
-                 (220, 119, 41)
+        colors = (0, 68, 170), (255, 255, 255), (128, 128, 128), \
+                 (220, 119, 41), (255, 80, 80), (0, 90, 110)
         texts = ["", ""]
         for ii, text in \
                 enumerate(self.get_configuration("display",
@@ -85,7 +85,6 @@ class Title(GameChild):
 
     def activate(self):
         self.active = True
-        self.scoreboard.activate()
 
     def deactivate(self):
         self.active = False
@@ -167,14 +166,39 @@ class Shift(GameChild):
         return self.nodeset.get_y(self.time) * self.direction
 
 
-class Scoreboard(Strip):
+class Scoreboard(GameChild, Surface):
 
     def __init__(self, parent):
-        Strip.__init__(self, parent)
-        surface = Surface((380, 80))
-        surface.fill((255, 255, 255))
-        self.add_frame(surface)
-        self.location.center = self.display_surface.get_rect().centerx, 350
+        GameChild.__init__(self, parent)
+        Surface.__init__(self, (380, 80))
+        self.display_surface = self.get_display_surface()
+        self.fill((255, 255, 255))
+        self.rect = self.get_rect()
+        self.rect.center = self.display_surface.get_rect().centerx, 350
+        self.load()
+
+    def load(self):
+        scores = []
+        for line in file(self.get_resource("score", "path"), "r"):
+            fields = line.split()
+            scores.append((float(fields[0]), int(fields[1])))
+        self.sprites = sprites = []
+        font_path = self.get_resource("display", "score-font-path")
+        y = 0
+        for ii, score in enumerate(sorted(scores, key=lambda score: score[1],
+                                          reverse=True)[:3]):
+            font = Font(font_path, [40, 24, 16][ii])
+            sprites.append(Sprite(self))
+            sprites[ii].add_frame(font.render(str(score[1]) + "¥", True, (0, 0, 0),
+                                              (255, 255, 255)))
+            sprites[ii].location.midtop = self.rect.w / 2, y
+            y += sprites[ii].location.h
+            sprites[ii].display_surface = self
+
+    def update(self):
+        self.display_surface.blit(self, self.rect)
+        for sprite in self.sprites:
+            sprite.update()
 
 
 class Sieve(Strip):