Commits

illume committed ec1b1a4

Adding hacky support for small display versions of the grids/blocks. unfinished.

Comments (0)

Files changed (2)

alchemymadness/blocks.py

 BLOCK_W = 30
 BLOCK_H = 30
 
+SBLOCK_W = BLOCK_W / 2
+SBLOCK_H = BLOCK_H / 2
+
 class Block(DirtySprite):
-    rect = Rect(0, 0, 30, 30)
     changed = False
 
-    def __init__(self, color, *groups):
+    def __init__(self, color, small, *groups):
         super(Block, self).__init__(*groups)
 
+        self.small = small
+        if self.small:
+            self.rect = Rect(0, 0, SBLOCK_W, SBLOCK_W)
+        else:
+            self.rect = Rect(0, 0, BLOCK_W, BLOCK_W)
+
         self._image = pygame.Surface(self.rect.size) # Sprite image
         self._color = color  # Block color
         self.changed = True
     def grid_pos(self, pos, grid_rect):
         """ set the rect for the given (x,y) grid pos
         """
+        ox, oy, w, h = self.rect
+
         gx, gy = pos
-        x, y = gx * BLOCK_W, gy * BLOCK_H
+        x, y = gx * w, gy * h
         x += grid_rect[0]
         y += grid_rect[1]
-        self.rect = pygame.Rect(x, y, BLOCK_W, BLOCK_H)
-        self.changed = True
+        self.rect = pygame.Rect(x, y, w, h)
+        #print self.rect
+        #self.changed = True
         self.dirty = 1
 
 
         #     top, left is (0,0)
         self.grid_positions = [[0,0], [1,0], [2,0]]
 
-        self.blocks = [Block(c) for c in self.colors]
+        self.blocks = [Block(c, self.parent.small) for c in self.colors]
         self.on_moved()
 
     def on_moved(self):
         
 
     def action_move_left(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] < 0:
                 doit = False
         if not doit:
+            # oops!  out of bounds, so reverse moves.
             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
 class Grid(object):
     """ Contains Blocks()
     """
-    def __init__(self):
+    def __init__(self, small):
         super(Grid, self).__init__()
-        self.GRID_SIZE_W = GRID_SIZE_W
-        self.GRID_SIZE_H = GRID_SIZE_H
+        self.small = small
 
-        self.rect = pygame.Rect(100, 100, GRID_SIZE_W * BLOCK_W, GRID_SIZE_H * BLOCK_H)
+        if self.small:
+            self.GRID_SIZE_W = SGRID_SIZE_W
+            self.GRID_SIZE_H = SGRID_SIZE_H
+            self.rect = pygame.Rect(30, 20, SGRID_SIZE_W * SBLOCK_W, SGRID_SIZE_H * SBLOCK_H)
+        else:
+            self.GRID_SIZE_W = GRID_SIZE_W
+            self.GRID_SIZE_H = GRID_SIZE_H
+
+            self.rect = pygame.Rect(30, 20, GRID_SIZE_W * BLOCK_W, GRID_SIZE_H * BLOCK_H)
 
         self.restart()
     def restart(self):

alchemymadness/main.py

 
     pygame.init()
     screen = pygame.display.set_mode(SCREEN_SIZE)
+    pygame.display.set_caption("alchemymadness")
     clock = pygame.time.Clock()
     going = True
 
     # Initialise level
     pot = potion.Potion()
     pot.set_formula(3, 5, 3)
-    grd = blocks.Grid()
+    grd = blocks.Grid(small = False)
     blks = blocks.Blocks(grd)
     sprites = pygame.sprite.LayeredDirty(pot)
     for b in blks.blocks: