Example #1
0
def create_tile(value, x, y):
    '''This function creates the tiles by the given values from the json 
    file.
    '''
    slidable = False
    abyss = False
    tile = None
    obj = None

    if value[0] == "b":
        slidable = True
    if value[0] == ".":
        obj = objects.Brick(False)
    else:
        if len(value) == 2:
            if value[1] == "4":
                obj = objects.Star()
            elif value[1] == "3":
                obj = objects.Ruby()
            elif value[1] == "1":
                obj = objects.Brick(True)
            elif value[1] == "6":
                obj = objects.Hammer()
            else:
                obj = objects.Brick(False)
    tile = objects.Tile(slidable, obj, x, y)
    return tile
Example #2
0
def spawn_defence():
    for brick in global_var.bricks:
        if brick.yget() == 8:
            brick.clear()
            global_var.bricks.remove(brick)

    for i in range(16):
        global_var.bricks.append(objects.Brick(config.brick, i * 5, 8, 1, [0]))
Example #3
0
def restart_game():

    # display you lose
    global_var.gp.lose = 1
    #set lives back to 3
    global_var.gp.remaininglives = global_var.gp.lives

    # reset score
    global_var.gp.score = 0
    # reinitialize bricks
    objects.Brick(" ", 0, 0, 0).initialize_bricks()
Example #4
0
    def __init__(self):

        self.start_index = 0

        self.matrix = np.array([[" " for i in range(self.width)]
                                for j in range(self.height)])

        #keeps track of placement of bricks
        self.brickMatrix = np.array([[0 for i in range(self.width)]
                                     for j in range(self.height)])

        self._step = 1

        objects.Brick(" ", 0, 0, 0).initialize_bricks()
Example #5
0
def makeObject(obj, x=config.show_width / 2, y=config.show_height / 2):
    if obj == "brick":
        return objects.Brick(7, 3, x, y)
    if obj == "coin":
        return objects.Coin(7, 3, x, y)
    if obj == "spring":
        return objects.Spring(7, 3, x, y)
    if obj == "specialbrick":
        return objects.SpecialBrick(14, 3, x, y)
    if obj == "goomba":
        return objects.Goomba(3, 2, x, y)
    if obj == "spikey":
        return objects.Spikey(4, 2, x, y)
    if obj == "stalker":
        return objects.Stalker(4, 2, x, y)
    if obj == "cloud":
        return objects.Cloud(14, 4, x, y)
    if obj == "castle":
        return objects.Castle(41, 15, x, y)
    if obj == "bullet":
        return objects.Bullet(4, 1, x, y)
    if obj == "boss":
        return objects.Boss(8, 4, x, y)
Example #6
0
def newLevel(level_):
    global score
    if level_ > 0:
        score += (lives + 1) * 15
    currentColour = -1
    linesWithBricks = -1

    try:
        for iy, line in enumerate(level[level_]):
            y = (windowHeight // 30) * iy
            if 1 in line:
                linesWithBricks += 1
                if linesWithBricks % levels.colourLines[currentLevel] == 0:
                    currentColour += 1
                lineColour = levelColours[currentColour]
            for ix, brick in enumerate(line):
                if brick == 1:
                    x = (windowWidth // 10) * ix
                    bricks.append(
                        objects.Brick(x, y, pygame, surface, lineColour,
                                      windowWidth))
    except IndexError:  # This means that the last level has been completed and therefore the game is won
        setState(gameWon)
Example #7
0
        if lives == 0:
            pygame.draw.circle(surface, colours.red, (40 * lives + 25, 20),
                               ball.radius)
        elif lives == 1:
            pygame.draw.circle(surface, colours.orange, (40 * lives + 25, 20),
                               ball.radius)
        elif lives == 2:
            pygame.draw.circle(surface, colours.green, (40 * lives + 25, 20),
                               ball.radius)


# Brick/Level related things
currentLevel = -1
level = levels.level
sampleBrick = objects.Brick(1000, 1000, pygame, surface, "black", windowWidth)
levelColours = list(sampleBrick.colours.keys())

bricks = []


def newLevel(level_):
    global score
    if level_ > 0:
        score += (lives + 1) * 15
    currentColour = -1
    linesWithBricks = -1

    try:
        for iy, line in enumerate(level[level_]):
            y = (windowHeight // 30) * iy
Example #8
0
def brick_gen(level):
    for brick in global_var.bricks:
        brick.clear()
    for ball in global_var.balls:
        ball.clear()
    global_var.bricks = []

    if level == 1:
        global_var.bricks.append(
            objects.Brick(config.brick, 2, 5, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 2, 12, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 9, 5, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 9, 12, inf, config.prob_distr))
        for i in range(6):
            global_var.bricks.append(
                objects.Brick(config.brick, i * 7 + 15, 10, -inf,
                              config.prob_distr))

        for i in range(5):
            global_var.bricks.append(
                objects.Brick(config.brick, i * 7 + 18, 5, 2,
                              config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 39 + 17, 5, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 39 + 24, 5, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 39 + 17, 12, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 39 + 24, 12, inf, config.prob_distr))

    elif level == 2:
        global_var.bricks.append(
            objects.Brick(config.brick, 28, 10, -inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 35, 10, -inf, config.prob_distr))

        for i in range(1, 4):
            r = random.randint(2, 3)
            global_var.bricks.append(
                objects.Brick(config.brick, 28 - i * 8, 10 - i * 2, r,
                              config.prob_distr))
            global_var.bricks.append(
                objects.Brick(config.brick, 35 + i * 8, 10 - i * 2, r,
                              config.prob_distr))
        for i in range(1, 3):
            global_var.bricks.append(
                objects.Brick(config.brick, 28 - i * 8, 10 + i * 2, 1,
                              config.prob_distr))
            global_var.bricks.append(
                objects.Brick(config.brick, 35 + i * 8, 10 + i * 2, 1,
                              config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 25, 6, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 38, 6, inf, config.prob_distr))
    elif level == 3:
        spawn_boss()
        global_var.bricks.append(
            objects.Brick(config.brick, 25, 10, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 38, 10, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 2, 12, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 9, 12, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 39 + 17, 12, inf, config.prob_distr))
        global_var.bricks.append(
            objects.Brick(config.brick, 39 + 24, 12, inf, config.prob_distr))