Falling cards animated
authorJoachim Breitner <mail@joachim-breitner.de>
Thu, 10 May 2007 09:08:53 +0000 (09:08 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Thu, 10 May 2007 09:08:53 +0000 (09:08 +0000)
cairoboard.py
engine.py

index 92a58cb..08f6078 100644 (file)
@@ -370,15 +370,27 @@ class CairoBlackHole:
     def __init__(self, fabric, bh):
         self.fabric = fabric
         self.bh = bh
+        self.falling_card = None
+        self.falling_d = 0
+
+    def fall_card(self, card):
+        def update():
+            self.falling_d += 0.03
+            if self.falling_d > 1:
+                self.falling_d = 1
+                self.falling_card = None
+            self.fabric.redraw()
+            return self.falling_d < 1
+
+        self.falling_d = 0
+        self.falling_card = card
+        gobject.timeout_add(40, update)
 
     def draw(self, window):
         cr = window.cairo_create()
         cr.translate(BH_X, BH_Y)
         cr.scale(SCALE, SCALE)
 
-        cr.rectangle(-1, -1, 2, 2)
-        cr.clip()
-
         cr.set_source_rgb(0,0,0)
         cr.arc(0, 0, 0.8, 0, 2*math.pi)
         cr.fill()
@@ -391,6 +403,13 @@ class CairoBlackHole:
         cr.show_text(str(self.bh.count))
         cr.fill()
 
+        if self.falling_card:
+            matrix = cr.get_matrix()
+            cr.scale((1-self.falling_d * self.falling_d),(1-self.falling_d*self.falling_d))
+            cr.rotate(4*(self.falling_d * self.falling_d))
+            self.falling_card.guiinfo.draw(cr)
+            cr.set_matrix(matrix)
+
 
 
 # vim:ts=4:sw=4:sts=4:et
index b217069..7e62080 100644 (file)
--- a/engine.py
+++ b/engine.py
@@ -195,7 +195,8 @@ class BlackHole(Slot):
         # Time to set the ship
         global state
         state = SHIPPING
-
+        if self.guiinfo:
+            self.guiinfo.fall_card(card)
 
     def can_drop_card(self,card):
         return True