Commits

illume committed 8ba0824

fixed out of bounds movement for a single Blocks() instance

Comments (0)

Files changed (1)

alchemymadness/blocks.py

         self.on_moved()
 
     def on_moved(self):
+        i = 0
         for b, pos in zip(self.blocks, self.grid_positions):
+            #print "on_moved {}".format(i)
             b.grid_pos(pos, self.parent.rect)
+            i += 1
 
+        #print "-" * 20
 
     def update(self, time):
         pass
         
 
     def action_move_left(self):
+        doit = True
         for b in self.grid_positions:
             b[0] -= 1
             if b[0] < 0:
-                b[0] = 0
+                doit = False
+        if not doit:
+            for b in self.grid_positions:
+                b[0] += 1
+                
         self.on_moved()
 
     def action_move_right(self):
+        # if any of them are going out of bounds, we don't move.
+        doit = True
         for b in self.grid_positions:
             b[0] += 1
             if b[0] >= GRID_SIZE_W:
-                b[0] = GRID_SIZE_W - 1
+                doit = False
+        if not doit:
+            for b in self.grid_positions:
+                b[0] -= 1
+
         self.on_moved()
 
 
     def action_move_up(self):
+        doit = True
         for b in self.grid_positions:
             b[1] -= 1
             if b[1] < 0:
-                b[1] = 0
+                doit = False
+        if not doit:
+            for b in self.grid_positions:
+                b[1] += 1
+                
         self.on_moved()
 
     def action_move_down(self):
+        doit = True
         for b in self.grid_positions:
             b[1] += 1
             if b[1] >= GRID_SIZE_H:
-                b[1] = GRID_SIZE_H - 1
+                doit = False
+        if not doit:
+            for b in self.grid_positions:
+                b[1] -= 1
+                
         self.on_moved()
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.