changeset 97:8ce25533406d

Fixed the gravity bug with new adds of creatures.
author Rene Dudfield <renesd@gmail.com>
date Sun, 08 Jul 2012 17:12:38 +0200
parents 42a4ef9956e4
children 7e4195d0ca17 61e822e1ff00
files zrpn/board.py zrpn/main.py
diffstat 2 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/zrpn/board.py	Sun Jul 08 17:01:24 2012 +0200
+++ b/zrpn/board.py	Sun Jul 08 17:12:38 2012 +0200
@@ -36,12 +36,20 @@
                         #thing_added(x, y, self.board[y][x], self.cells)
                         self.id_next += 1
 
-            #animations.extend(self.apply_gravity(turns))
-            #TODO: change net_adds to account for gravity, give correct x,y
+            animations.extend(self.apply_gravity(turns))
+            new_net_adds = []
+            for n in net_adds:
+                # find the x,y for the cells.
+                xy = self.get_x_y_for_cell(n[2])
+                if xy:
+                    n[0] = xy[0]
+                    n[1] = xy[1]
+                new_net_adds.append(n)
+            
 
             if not killed:
                 self.printit()
-                return animations, extra, net_adds
+                return animations, extra, new_net_adds
 
 
 
@@ -53,7 +61,11 @@
         for c in self.board:
             print (c)
 
-
+    def get_x_y_for_cell(self, cell):
+        for y, line in enumerate(self.cells):
+            for x, c in enumerate(line):
+                if c == cell:
+                    return x,y
 
     def apply_gravity(self, turn):
         animations = []
--- a/zrpn/main.py	Sun Jul 08 17:01:24 2012 +0200
+++ b/zrpn/main.py	Sun Jul 08 17:12:38 2012 +0200
@@ -34,10 +34,12 @@
                     animations.extend(self.board.kill_one((x, y)))
                     ans, extra, net_adds = self.board.update()
                     animations.extend(ans)
+
+                    for n in net_adds:
+                        self.display.add_zrpn(*n)
+                    
                     self.display.do_animations(animations)
 
-            for n in net_adds:
-                self.display.add_zrpn(*n)
             self.display.frame()
 
 class MainMenu(sgc.Menu):