fade
[sso] / shaken_and_spit_out / SSO.py
index 2e04314..d917079 100644 (file)
@@ -2,7 +2,7 @@ from os import listdir
 from glob import glob
 from random import choice
 
-from pygame import cursors
+from pygame import cursors, PixelArray, Surface, Color
 from pygame.mouse import set_cursor
 from pygame.font import Font
 from pygame.image import load
@@ -54,12 +54,16 @@ class Title(GameChild):
 
     def __init__(self, parent):
         GameChild.__init__(self, parent)
+        self.delegate = self.get_delegate()
+        self.preface = Preface(self)
         self.subscribe(self.respond)
         self.subscribe(self.respond, MOUSEBUTTONDOWN)
         self.deactivate()
 
     def respond(self, event):
-        if self.active:
+        if self.delegate.compare(event, "reset-game"):
+            self.activate()
+        elif self.active:
             if event.type == MOUSEBUTTONDOWN and event.button == 1:
                 print "left-click"
 
@@ -68,7 +72,34 @@ class Title(GameChild):
 
     def activate(self):
         self.active = True
+        self.preface.reset()
 
     def update(self):
         if self.active:
-            pass
+            self.preface.update()
+
+
+class Preface(GameChild, Surface):
+
+    def __init__(self, parent):
+        GameChild.__init__(self, parent)
+        ds = self.ds = self.get_display_surface()
+        w, h = ds.get_width(), int(round(ds.get_width() / 1.618))
+        Surface.__init__(self, (w, h), SRCALPHA)
+        self.background = Surface((w, h))
+        self.background.fill((0, 0, 0))
+        mask = self.mask = Surface((w, h), SRCALPHA)
+        pixels = PixelArray(mask)
+        for y in xrange(h):
+            alpha = int(round(255 - (float(y) / h) * 255))
+            for x in xrange(w):
+                pixels[x][y] = Color(255, 255, 255, alpha)
+        del pixels
+
+    def reset(self):
+        pass
+
+    def update(self):
+        self.blit(self.background, (0, 0))
+        self.blit(self.mask, (0, 0), None, BLEND_RGBA_MIN)
+        self.ds.blit(self, (0, 0))