preamble
authorFrank DeMarco <frank.s.demarco@gmail.com>
Tue, 26 Aug 2014 16:00:20 +0000 (01:00 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Tue, 26 Aug 2014 16:00:20 +0000 (01:00 +0900)
config
shaken_and_spit_out/SSO.py
shaken_and_spit_out/pgfw/GameChild.py

diff --git a/config b/config
index 79ea7a7..af7765e 100644 (file)
--- a/config
+++ b/config
@@ -35,9 +35,9 @@ cloud = img/Safire-Translimitter.png
 [text]
 preface = It was a cybernetic adaptation/that allowed it the predilection/to
           attempt PSPPIT, continual/establishment of foundation in/the firmament
-intermediate = Good something/they that speak in proverbs say/come into the
-               city/let it be built/where the flies collect/on a live cadaver in
-               the road
+preamble = Good something/they that speak in proverbs say/come into the
+           city/let it be built/where the flies collect/on a live cadaver in
+           the road
 charsets = 0030-0031-0032-0033-0034-0035-0036-0037-0038-0039/2250-2251-2252-
            2253-2254-2255-2256-2257-2258-2259/2440-2441-2442-2443-2444-2445-
            2446-2447-2448-2449/235F-2295-2296-2297-2298-2299-229A-229B-229C-
index 130f149..3d30f7e 100644 (file)
@@ -12,6 +12,7 @@ from pygame.locals import *
 from shaken_and_spit_out.pgfw.Game import Game
 from shaken_and_spit_out.pgfw.GameChild import GameChild
 from shaken_and_spit_out.pgfw.Sprite import Sprite
+from shaken_and_spit_out.pgfw.Animation import Animation
 
 class SSO(Game):
 
@@ -31,8 +32,8 @@ class SSO(Game):
 
     def set_children(self):
         Game.set_children(self)
-        self.title = Title(self)
         self.floor = Floor(self)
+        self.title = Title(self)
         self.cloud = Cloud(self)
 
     def set_random_background(self):
@@ -49,8 +50,8 @@ class SSO(Game):
 
     def update(self):
         self.get_screen().blit(self.background, (0, 0))
-        self.title.update()
         self.cloud.update()
+        self.title.update()
         self.floor.update()
         # self.get_screen().fill((0, 0, 0))
         # self.get_screen().blit(self.message, (100, 100))
@@ -62,6 +63,7 @@ class Title(GameChild):
         GameChild.__init__(self, parent)
         self.delegate = self.get_delegate()
         self.preface = Preface(self)
+        self.preamble = Preamble(self)
         self.subscribe(self.respond)
         self.subscribe(self.respond, MOUSEBUTTONDOWN)
         self.deactivate()
@@ -80,10 +82,12 @@ class Title(GameChild):
     def activate(self):
         self.active = True
         self.preface.reset()
+        self.preamble.reset()
 
     def update(self):
         if self.active:
             self.preface.update()
+            self.preamble.update()
 
 
 class Preface(GameChild, Surface):
@@ -106,9 +110,8 @@ class Preface(GameChild, Surface):
         self.reset()
 
     def set_text(self):
-        lines = self.get_configuration("text", "preface").upper()
-        lines = str.replace(lines, "\n", " ")
-        lines = lines.upper().split("/")
+        lines = self.get_configuration("text", "preface",
+                                       False).upper().split("/")
         cc = 0
         for line in lines:
             if len(line) > cc:
@@ -188,6 +191,45 @@ class Preface(GameChild, Surface):
         self.ds.blit(self, (0, 0))
 
 
+class Preamble(Animation):
+
+    def __init__(self, parent):
+        Animation.__init__(self, parent, self.increment_plate_index, 4000)
+        plates = self.plates = []
+        font = Font(self.get_resource("display", "font"), 12)
+        font.set_bold(True)
+        for line in self.get_configuration("text", "preamble",
+                                           False).upper().split("/"):
+            plates.append([])
+            spaced = str(line[0])
+            for character in line[1:]:
+                spaced += " " + character
+            for ii, color in enumerate(((0, 255, 255), (0, 255, 255),
+                                        (255, 0, 0))):
+                text = Sprite(self)
+                text.add_frame(font.render(spaced, True, color))
+                fr = self.get_game().floor.location
+                text.location.midtop = fr.centerx + (-1, 1, 0)[ii], \
+                                       fr.bottom + 10
+                plates[-1].append(text)
+        self.reset()
+        self.play()
+
+    def increment_plate_index(self):
+        index = self.plate_index + 1
+        if index >= len(self.plates):
+            index = 0
+        self.plate_index = index
+
+    def reset(self):
+        self.plate_index = 0
+
+    def update(self):
+        Animation.update(self)
+        for text in self.plates[self.plate_index]:
+            text.update()
+
+
 class Floor(Sprite):
 
     def __init__(self, parent):
index 8808dce..1cccb1e 100644 (file)
@@ -18,13 +18,16 @@ class GameChild:
             current = current.parent
         return current
 
-    def get_configuration(self, section=None, option=None):
+    def get_configuration(self, section=None, option=None, linebreaks=True):
         config = self.game.configuration
+        if option is None and section is None:
+            return config
         if option and section:
-            return config.get(section, option)
-        if section:
-            return config.get_section(section)
-        return config
+            rvalue = config.get(section, option)
+            if not linebreaks and isinstance(rvalue, str):
+                rvalue = rvalue.replace("\n", " ")
+            return rvalue
+        return config.get_section(section)
 
     def get_input(self):
         return self.game.input