Anonymous avatar Anonymous committed a352039

Added background image and some example code for the potion.

Comments (0)

Files changed (3)

alchemymadness/main.py

 import pygame
 from pygame.locals import *
 
+import skelutil
+
 import potion
 
-SCREEN_SIZE = (640, 480)
+SCREEN_SIZE = (800, 600)
 
 
 def main():
     going = True
 
     screen.fill((0,0,0))
-    background = pygame.surface.Surface(SCREEN_SIZE)
+    background = pygame.image.load(skelutil.data_dir("bg.png")).convert_alpha()
 
     # Tetris area
     pygame.draw.rect(background, (0,0,255),
     pot = potion.Potion()
     pot.set_formula(10, 20, 30)
 
+    #TEST
+    pot.add_color((0,0,255))
+
     while going:
         time = clock.tick(30)
-        screen.blit(background, (0,0))
 
         rects = []
         events = pygame.event.get()
         for e in events:
+            if e.type == KEYDOWN and e.key == K_SPACE:
+                pot.add_color((255,0,0))
+                screen.fill(pot.col, pot.rect)
+                rects.append(pot.rect)
             if e.type == QUIT or e.type == KEYDOWN and e.key == K_ESCAPE:
                 going = False
 
+        screen.blit(background, (0,0))
         pygame.display.update(rects)
 
     # End game

alchemymadness/potion.py

     formula = (0,0,0)  # Target formula
     col = (0,0,0)  # Current formula
     max_chems = 0  # Target number of chems
-    rect = Rect(300, 300, 300, 200)
+    start_y = 470
+    rect = Rect(450, 470, 170, 113)
 
     def set_formula(self, r=0, g=0, b=0):
         """Set the target formula for the level."""
         self.chems = 0
         self.formula = (r, g, b)
         self.max_chems = sum(self.formula)
+        # Offset the rect to be at bottom of potion
+        self.rect.y = self.start_y + self.rect.h
 
     def add_color(self, col):
         """
                     self.col[1] + col[1]/float(self.chems),
                     self.col[2] + col[2]/float(self.chems))
 
+        # Update position
+        n = self.chems / float(self.max_chems)
+        self.rect.y = self.start_y + self.rect.h*(1-n)
+
     def get_score(self):
         """Returns a score based on accuracy of the formula."""
         pass

alchemymadness/skelutil.py

-
+import os
 
 _DATA_DIR = None
 def data_dir(*args):
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.