Szymon Wróblewski avatar Szymon Wróblewski committed 2661df1

Added block class, removed obsolete images

Comments (0)

Files changed (5)

alchemymadness/blocks.py

 
 import resources
 
+class Block(DirtySprite):
+    rect = Rect(0, 0, 30, 30)
+    changed = False
+
+    def __init__(self, color, *groups):
+        super(Block, self).__init__(*groups)
+
+        self._image = pygame.Surface(self.rect.size) # Sprite image
+        self._color = color  # Block color
+        self.changed = True
+        self.dirty = 1
+
+    @property
+    def image(self):
+        if self.changed:
+            self._image = resources.block.copy()
+            self._image.fill(self._color, special_flags=pygame.locals.BLEND_RGBA_MULT)
+        return self._image
+
+    @property
+    def color(self):
+        return self._color
+
+    @color.setter
+    def color(self, value):
+        self._color = value
+        self.changed = True
 
 class Blocks(DirtySprite):
-    
+
     def __init__(self, *groups):
         super(Blocks, self).__init__(*groups)
 
 
         self.colors = [(255,0,0), (0,255,0), (0,0,255)]
-        
+
         # how do we handle location, and rotation? We say where the grid it is on.
         #     top, left is (0,0)
         self.grid_positions = [[0,0], [1,0], [2,0]]
 
         # what is our image?
         self.dirty = 1
-    
+
 
     def update(self, time):
         pass
Add a comment to this file

alchemymadness/data/block.png

Added
New image

alchemymadness/main.py

 
 import resources
 import potion
+import block
 
 SCREEN_SIZE = (800, 600)
 
     screen = pygame.display.set_mode(SCREEN_SIZE)
     clock = pygame.time.Clock()
     going = True
-    
+
     resources.init()
 
     screen.fill((0,0,0))
     # Initialise level
     pot = potion.Potion()
     pot.set_formula(3, 5, 3)
-    sprites = pygame.sprite.LayeredDirty(pot)
+    bl = block.Block((255,0,0))
+    sprites = pygame.sprite.LayeredDirty(pot, bl)
 
     #TEST
     pot.add_color((0,0,255))
         # Update sprites
         sprites.clear(screen, resources.background)
         sprites.update(time)
-        
+
         # Draw sprites
         rects = sprites.draw(screen)
         pygame.display.update(rects)
-        
+
 
     # End game
     score = pot.get_score()

alchemymadness/potion.py

     rect = Rect(450, 470, 170, 113)
     image_rect = Rect((0, rect.y), rect.size)
     target_y = None
-    
-    
+    changed = False
+
+
     def __init__(self, *groups):
+        """
+        Init potion sprite.
+
+        Args:
+          groups to add sprite to
+
+        """
         super(Potion, self).__init__(*groups)
         # Image with transparency
         self.t_image = resources.background.subsurface(self.rect)
         # Sprite image
         self._image = pygame.Surface(self.rect.size)
-        self.dirty = 1
-    
+        self.changed = True
+
     @property
     def image(self):
-        if self.dirty == 1:
+        if self.changed:
             self._image.fill((0,0,0))
             self._image.fill(self.col, self.image_rect)
             self._image.blit(self.t_image, (0,0))
                 self.target_y = None
         # Lerp colours
         if self.target_col is not None:
-            self.dirty = 1
+            self.changed = True
             diff = (self.diff_col[0] * (time/500.),
                     self.diff_col[1] * (time/500.),
                     self.diff_col[2] * (time/500.))

alchemymadness/resources.py

 import skelutil
 
 background = None
-red_block = green_block = blue_block = None
-red_small_block = green_small_block = blue_small_block = None
-block = small_block = None
+block = None
 
 def init():
-    global background, red_block, green_block, blue_block
-    global red_small_block, green_small_block, blue_small_block
-    global block, small_block
+    global background, block
     background = pygame.image.load(skelutil.data_dir("bg.png")).convert_alpha()
-    red_block = pygame.image.load(skelutil.data_dir("red.png")).convert_alpha()
-    green_block = pygame.image.load(skelutil.data_dir("green.png")).convert_alpha()
-    blue_block = pygame.image.load(skelutil.data_dir("blue.png")).convert_alpha()
-    red_small_block = pygame.image.load(skelutil.data_dir("red_.png")).convert_alpha()
-    green_small_block = pygame.image.load(skelutil.data_dir("green_.png")).convert_alpha()
-    blue_small_block = pygame.image.load(skelutil.data_dir("blue_.png")).convert_alpha()
-    block = (red_block, green_block, blue_block)
-    small_block = (red_small_block, green_small_block, blue_small_block)
-    
-    
+    block = pygame.image.load(skelutil.data_dir("block.png")).convert_alpha()
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.