Example #1
0
  def __init__(self, surface):
    """Intilize the board"""
    #Set up the surface and groups
    self.surface = surface
    self.brickGroup = sprite.Group()
    self.paddleGroup = sprite.Group()
    self.ballGroup = sprite.Group()
    BRICK_GROUP = self.brickGroup
    
    #Setup the top score field
    global LEVEL
    LEVEL += 1
    
    self.scoreLL = pygame.Surface((1280, 32), flags=pygame.SRCALPHA)
    self.scoreLL.fill((0,0,0,100))
    self.scoreFont = pygame.font.Font(None, 24)

    self.livesText = self.scoreFont.render("Lives: %i" % LIVES, 0, (210,210,210))
    self.scoreText = self.scoreFont.render("%i Pts" % SCORE, 0, (210,210,210))
    self.levelText = self.scoreFont.render("Level %i" % LEVEL, 0, (210,210,210))
    
    #Load images into cache
    self.blankBrick = img.load(surface, brickFile)
    self.paddleImage = img.load(surface, paddleFile)
    self.ballImage = img.load(surface, ballFile)
    
    #Create brick types
    img.CACHE['brick0'] = self.blankBrick.copy()
    img.CACHE['brick1'] = self.blankBrick.copy()
    img.CACHE['brick2'] = self.blankBrick.copy()
    img.CACHE['brick3'] = self.blankBrick.copy()
    img.CACHE['brick0'].fill(c_RED, special_flags=pygame.BLEND_RGB_MIN)
    img.CACHE['brick1'].fill(c_ORANGE, special_flags=pygame.BLEND_RGB_MIN)
    img.CACHE['brick2'].fill(c_YELLOW, special_flags=pygame.BLEND_RGB_MIN)
    img.CACHE['brick3'].fill(c_BLACK, special_flags=pygame.BLEND_RGB_MIN)
    
    #Load the level
    self.load()
    physics.init(self.ballGroup, self.brickGroup, self.paddleGroup)
Example #2
0
  def load(self):
    """Load images into sprites, and organize them by groups"""
    
    #load map from file
    config = ConfigParser.RawConfigParser()
    config.read(os.path.join('content','maps','%i.map' % LEVEL))
    levelMap = []
    for i in range(0,6):
      try:
        brickList = map( int, config.get(DIFFICULTY, str(i)).split(',') )
        levelMap.append(brickList)
      except: pass
    self.map = levelMap
   
    #Load background and sound for the stage
    self.music = config.get('info', 'music')
    self.wallPaper = img.load(self.surface, os.path.join('content','images','bg','%s.jpg' % config.get('info', 'bg')))
    
    #Load the bricks from the map
    total = 0
    offsetXY = [0,32]
    
 
    for r in self.map:    #For every row in the map
      offsetXY[0] = 128
      offsetXY[1] += 16
      

      for c in r:       #For every column in the row
        brick = sprite.Sprite(img.CACHE['brick%i' % c], offsetXY)
        brick.custom['i'] = c
        brick.add(self.brickGroup)
        offsetXY[0] += 64
    
    #Add paddle and ball    
    paddle = sprite.Sprite(self.paddleImage, [608, 700])
    paddle.add(self.paddleGroup)
    
    ball = sprite.Sprite(self.ballImage, [662, 684])
    ball.custom['v'] = [0,1]
    ball.add(self.ballGroup)