# Block Breaker Game
# Chapter 9

import sys, time, random, math, pygame
from pygame.locals import *
from MyLibrary import *

levels = (
    (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),

    (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
     2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2,
     2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2,
     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
     2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2,
     2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2,
     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),

    (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
     3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3,
     3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3,
     3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3,
     3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
     3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
     3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3,
     3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3,
     3, 3, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3,
     3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
)


# this function increments the level
def goto_next_level():
    global level, levels
    level += 1
    if level > len(levels) - 1: level = 0
    load_level()


# this function updates the blocks in play
def update_blocks():
    global block_group, waiting
    if len(block_group) == 0:  # all blocks gone?
        goto_next_level()
        waiting = True
    block_group.update(ticks, 50)


# this function sets up the blocks for the level
def load_level():
    global level, block, block_image, block_group, levels

    block_image = pygame.image.load("blocks.png").convert_alpha()