Beispiel #1
0
def load_level(levelnumber, game_objects):
    opencfg = configparser.ConfigParser()
    opencfg.read("levels/" + levelnumber + ".ini")

    # ast.literal_eval приводит строку к простым типам питона
    # (в данном случае в список позиций - туплу, в которой тупла)
    trees_list = ast.literal_eval(opencfg.get("GameObjects", 'trees'))
    # заполняем массив деревьев с помощью генераторного выражения
    game_objects.trees = [
        GameObjects.Tree(batch, current_cell) for current_cell in trees_list
    ]

    game_objects.bricks = [
        GameObjects.Brick(batch, current_cell)
        for current_cell in ast.literal_eval(
            opencfg.get("GameObjects", 'bricks'))
    ]
    game_objects.boxes = [
        GameObjects.Box(batch, current_cell)
        for current_cell in ast.literal_eval(
            opencfg.get("GameObjects", 'boxes'))
    ]
    game_objects.box_targets = [
        GameObjects.BoxTarget(batch, current_cell)
        for current_cell in ast.literal_eval(
            opencfg.get("GameObjects", 'box_targets'))
    ]

    return game_objects
Beispiel #2
0
# player.image.anchor_y = 0

arrsize = arr.size

for row in range(len(arr)):
    for column in range(len(arr[row])):
        current_cell = row, column
        cur_cell_val = arr[current_cell]
        if cur_cell_val >= 10:
            box_targets.append(GameObjects.BoxTarget(
                layer2, current_cell))  # кидаем во второй слой
            cur_cell_val -= 10
        if cur_cell_val == 2:
            trees.append(GameObjects.Tree(batch, current_cell))
        if cur_cell_val == 3:
            bricks.append(GameObjects.Brick(batch, current_cell))
        if cur_cell_val == 4:
            boxes.append(GameObjects.Box(batch, current_cell))
        elif arr[current_cell] == 1:
            # player = GameObjects.Player(row, column, None)
            player.move(
                current_cell
            )  # работает только потому, что изначально у игрока позиция 0,0

window = pyglet.window.Window(width=(CELL_SIZE * 10),
                              height=(CELL_SIZE * 10),
                              caption="Gecko Soko")
window.set_mouse_visible(True)

fps_display = pyglet.window.FPSDisplay(window)
fps_display.label.y = 0