Esempio n. 1
0
def fill_map(tileSetFolder, tileCoords):
    yMin, yMax = 0, 15
    xMin, xMax = 36, 51
    squareX, squareY = tileCoords
    while True:
        draw_tileSet(tileSetFolder)
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYUP
                                      and event.key == K_ESCAPE):
                quit()
            elif event.type == KEYDOWN:

                if event.key in [K_UP, K_w]:
                    if squareY != yMin:
                        squareY -= 1
                    else:
                        squareY = yMax

                elif event.key in [K_LEFT, K_a]:
                    if squareX != xMin:
                        squareX -= 1
                    else:
                        squareX = xMax

                elif event.key in [K_RIGHT, K_d]:
                    if squareX != xMax:
                        squareX += 1
                    else:
                        squareX = xMin

                elif event.key in [K_DOWN, K_s]:
                    if squareY != yMax:
                        squareY += 1
                    else:
                        squareY = yMin

                elif event.key == K_SPACE:
                    tiles = []
                    for x in range(32):
                        column = []
                        for y in range(32):
                            tile = Tile(setParams)
                            tileFile = tileFile = 'tiles' + sep + tileSetFolder + sep + '%i_%i.png' % (
                                squareX + 1 - 36, squareY + 1)
                            tile.set_base_tile(tileFile)
                            tile.set_location(x, y)
                            column.append(tile)
                        tiles.append(column)
                    return tiles, (squareX, squareY)

                elif event.key == K_q:
                    return None, (squareX, squareY)
            else:
                continue

        highlight_square(squareX - 36, squareY, mapArea=False)
        pygame.display.update()
        FPSCLOCK.tick(FPS)
Esempio n. 2
0
def set_tiles(mainMapData, mainMapImages, area, mapData, mapImages,
              tileCoords):
    yMin, yMax = 0, 8
    xMin, xMax = 36, 43
    squareX, squareY = tileCoords
    mapX, mapY = area[0][0]

    while True:
        x = squareX - xMin
        y = squareY
        draw_mapSquares(mapImages)
        for event in pygame.event.get():

            if event.type == QUIT or (event.type == KEYUP
                                      and event.key == K_ESCAPE):
                quit()
            elif event.type == KEYDOWN:

                if event.key in [K_UP, K_w]:
                    if squareY != yMin:
                        squareY -= 1
                    else:
                        squareY = yMax

                elif event.key in [K_LEFT, K_a]:
                    if squareX != xMin:
                        squareX -= 1
                    else:
                        squareX = xMax

                elif event.key in [K_RIGHT, K_d]:
                    if squareX != xMax:
                        squareX += 1
                    else:
                        squareX = xMin

                elif event.key in [K_DOWN, K_s]:
                    if squareY != yMax:
                        squareY += 1
                    else:
                        squareY = yMin

                elif event.key == K_SPACE:
                    mapSquareID = mapSquare_at(x, y)
                    mainMapData[mapX][mapY] = mapData[mapSquareID]
                    mainMapData[mapX][mapY].place_on_map_at(mapX, mapY)
                    mainMapImages[mapX][mapY] = mapImages[mapSquareID]

                    return mainMapData, mainMapImages, (squareX, squareY)

                elif event.key == K_q:
                    return mainMapData, mainMapImages, (squareX, squareY)

                else:
                    continue

            else:
                continue

        highlight_square(x, y, mapArea=False)
        pygame.display.update()
        FPSCLOCK.tick(FPS)
Esempio n. 3
0
def main():
    global DISPLAYSURF, FPSCLOCK, FPS
    pygame.init()
    FPSCLOCK = pygame.time.Clock()
    FPS = 15

    global XMARGIN, YMARGIN, BOXSIZE, FONTSIZE
    width, height = pygame.display.Info().current_w, pygame.display.Info(
    ).current_h

    windowHeight = int(0.8 * height)
    windowWidth = int(1.9 * windowHeight)

    XMARGIN = YMARGIN = int(windowHeight / 40)
    BOXSIZE = int((windowHeight - 2 * YMARGIN) / 36)
    FONTSIZE = int(0.8 * BOXSIZE)

    DISPLAYSURF = pygame.display.set_mode((windowWidth, windowHeight))
    pygame.display.set_caption('Map Maker')

    squareX = squareY = 0
    yMin, yMax = 0, 4
    xMin, xMax = 0, 4
    mouseX = mouseY = 0
    tileCoords = (36, 0)

    mapSquares = [x[2] for x in os.walk('mapSquares')][0]
    mapSquares.sort()

    # left, top = left_top_coords_of_box(0, 17, mapArea=False)
    # surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE)
    # DISPLAYSURF.blit(surf, prevRect)

    # left, top = left_top_coords_of_box(4, 17, mapArea=False)
    # surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE)
    # DISPLAYSURF.blit(surf, nextRect)

    mapImages = []
    mapData = []

    for file in mapSquares:
        filename = 'mapSquares' + sep + file
        if 'main_map' in file:
            pass
        elif 'png' in file:
            mapImages.append(load_image(filename))
        elif 'pickle' in file:
            mapData.append(load_map_square(filename))

    # print(mapData)

    draw_mapSquares(mapImages)
    pygame.display.update()

    area = []

    global mapCoords
    mapCoords = []
    mainMap = []
    mainMapData = []
    for x in range(5):
        column1 = []
        column2 = []
        column3 = []
        for y in range(5):
            column1.append((x, y))
            column2.append(None)
            column3.append(None)
        mapCoords.append(column1)
        mainMap.append(column2)
        mainMapData.append(column3)

    mainMapImages = mainMap

    while True:
        DISPLAYSURF.fill(BLACK)

        # left, top = left_top_coords_of_box(2, 17, mapArea=False)
        # text = '%s/%i' % (str(tileSetNum+1).zfill(2), len(tileSets))
        # surf, rect = make_text(text, WHITE, BLACK, left, top, size=FONTSIZE)
        # DISPLAYSURF.blit(surf, rect)

        # left, top = left_top_coords_of_box(0, 17, mapArea=False)
        # surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE)
        # DISPLAYSURF.blit(surf, prevRect)

        # left, top = left_top_coords_of_box(4, 17, mapArea=False)
        # surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE)
        # DISPLAYSURF.blit(surf, nextRect)

        left, top = left_top_coords_of_box(12, 34, mapArea=True)
        surf, saveRect = make_text('Save',
                                   WHITE,
                                   BLACK,
                                   left,
                                   top,
                                   size=FONTSIZE)
        DISPLAYSURF.blit(surf, saveRect)

        draw_map(mainMapImages)
        draw_mapSquares(mapImages)

        for event in pygame.event.get():
            keys = pygame.key.get_pressed()
            if not keys[K_LSHIFT]:
                xStart, xEnd = squareX, squareX + 1
                yStart, yEnd = squareY, squareY + 1

            if event.type == QUIT or (event.type == KEYUP
                                      and event.key == K_ESCAPE):
                quit()
            elif event.type == KEYDOWN:
                if event.key in [K_UP, K_w]:
                    if squareY != yMin:
                        squareY -= 1
                    else:
                        squareY = yMax
                    if keys[K_LSHIFT]:

                        yStart -= 1

                elif event.key in [K_LEFT, K_a]:
                    if squareX != xMin:
                        squareX -= 1
                    else:
                        squareX = xMax
                    if keys[K_LSHIFT]:
                        xStart -= 1

                elif event.key in [K_RIGHT, K_d]:
                    if squareX != xMax:
                        squareX += 1
                    else:
                        squareX = xMin
                    if keys[K_LSHIFT]:
                        xEnd += 1

                elif event.key in [K_DOWN, K_s]:
                    if squareY != yMax:
                        squareY += 1
                    else:
                        squareY = yMin
                    if keys[K_LSHIFT]:
                        yEnd += 1

                elif event.key == K_SPACE:
                    columns = mapCoords[xStart:xEnd]
                    area = [y[yStart:yEnd] for y in columns]
                    highlight_area(area)
                    mainMapData, mainMapImages, tileCoords = set_tiles(
                        mainMapData, mainMapImages, area, mapData, mapImages,
                        tileCoords)

            elif event.type == MOUSEBUTTONUP:
                mouseX, mouseY = event.pos

                if saveRect.collidepoint(mouseX, mouseY):
                    # print(mainMapData)
                    # print('\n\n')
                    # print(mainMapImages)
                    save(mainMapData)

                else:
                    pass

            else:
                continue

        columns = mapCoords[xStart:xEnd]
        area = [y[yStart:yEnd] for y in columns]
        highlight_area(area)
        FPSCLOCK.tick(FPS)
Esempio n. 4
0
def main():
    global DISPLAYSURF, FPSCLOCK, FPS
    pygame.init()
    FPSCLOCK = pygame.time.Clock()
    FPS = 15

    global XMARGIN, YMARGIN, BOXSIZE, FONTSIZE
    width, height = pygame.display.Info().current_w, pygame.display.Info(
    ).current_h

    windowHeight = int(0.8 * height)
    windowWidth = int(1.9 * windowHeight)

    XMARGIN = YMARGIN = int(windowHeight / 40)
    BOXSIZE = int((windowHeight - 2 * YMARGIN) / 36)
    FONTSIZE = int(0.8 * BOXSIZE)

    DISPLAYSURF = pygame.display.set_mode((windowWidth, windowHeight))
    pygame.display.set_caption('Map Square Maker')

    global setParams
    setParams = {}
    setParams['isWalkable'] = True
    setParams['isRunnable'] = True
    setParams['isBikeable'] = True
    setParams['isSurfable'] = False
    draw_set_params()

    squareX = squareY = 0
    yMin, yMax = 0, 31
    xMin, xMax = 0, 31
    mouseX = mouseY = 0
    tileCoords = (36, 0)
    xStart, xEnd = squareX, squareX + 1
    yStart, yEnd = squareY, squareY + 1

    tileSets = [x[1] for x in os.walk('tiles')][0]
    tileSets.sort()
    tileSetNum = 0
    tileSetFolder = tileSets[tileSetNum]

    left, top = left_top_coords_of_box(0, 17, mapArea=False)
    surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE)
    DISPLAYSURF.blit(surf, prevRect)

    left, top = left_top_coords_of_box(4, 17, mapArea=False)
    surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE)
    DISPLAYSURF.blit(surf, nextRect)

    try:
        mapSquare = load_map_square(sys.argv[1]).tiles
    except:
        mapSquare = fill_map(tileSetFolder, tileCoords)[0]

    mapImages = load_map(mapSquare)

    draw_map(mapImages)

    area = []

    global mapCoords
    mapCoords = []
    for x in range(len(mapSquare)):
        column = []
        for y in range(len(mapSquare)):
            column.append((x, y))
        mapCoords.append(column)

    while True:
        DISPLAYSURF.fill(BLACK)

        tileSetFolder = tileSets[tileSetNum]

        left, top = left_top_coords_of_box(2, 17, mapArea=False)
        text = '%s/%i' % (str(tileSetNum + 1).zfill(2), len(tileSets))
        surf, rect = make_text(text, WHITE, BLACK, left, top, size=FONTSIZE)
        DISPLAYSURF.blit(surf, rect)

        left, top = left_top_coords_of_box(0, 17, mapArea=False)
        surf, prevRect = make_text('Prev',
                                   WHITE,
                                   BLACK,
                                   left,
                                   top,
                                   size=FONTSIZE)
        DISPLAYSURF.blit(surf, prevRect)

        left, top = left_top_coords_of_box(4, 17, mapArea=False)
        surf, nextRect = make_text('Next',
                                   WHITE,
                                   BLACK,
                                   left,
                                   top,
                                   size=FONTSIZE)
        DISPLAYSURF.blit(surf, nextRect)

        left, top = left_top_coords_of_box(12, 34, mapArea=True)
        surf, saveRect = make_text('Save',
                                   WHITE,
                                   BLACK,
                                   left,
                                   top,
                                   size=FONTSIZE)
        DISPLAYSURF.blit(surf, saveRect)

        draw_map(mapImages)
        draw_tileSet(tileSetFolder)

        paramRects = draw_set_params()

        for event in pygame.event.get():
            keys = pygame.key.get_pressed()
            if not keys[K_LSHIFT]:
                xStart, xEnd = squareX, squareX + 1
                yStart, yEnd = squareY, squareY + 1

            if event.type == QUIT or (event.type == KEYUP
                                      and event.key == K_ESCAPE):
                quit()
            elif event.type == KEYDOWN:
                if event.key in [K_UP, K_w]:
                    if squareY != yMin:
                        squareY -= 1
                    else:
                        squareY = yMax
                    if keys[K_LSHIFT]:

                        yStart -= 1

                elif event.key in [K_LEFT, K_a]:
                    if squareX != xMin:
                        squareX -= 1
                    else:
                        squareX = xMax
                    if keys[K_LSHIFT]:
                        xStart -= 1

                elif event.key in [K_RIGHT, K_d]:
                    if squareX != xMax:
                        squareX += 1
                    else:
                        squareX = xMin
                    if keys[K_LSHIFT]:
                        xEnd += 1

                elif event.key in [K_DOWN, K_s]:
                    if squareY != yMax:
                        squareY += 1
                    else:
                        squareY = yMin
                    if keys[K_LSHIFT]:
                        yEnd += 1

                elif event.key == K_SPACE:
                    columns = mapCoords[xStart:xEnd]
                    area = [y[yStart:yEnd] for y in columns]
                    highlight_area(area)
                    mapSquare, tileCoords = set_tiles(mapSquare, area,
                                                      tileSetFolder,
                                                      tileCoords)
                    mapImages = load_map(mapSquare)

                elif event.key == K_b:
                    columns = mapCoords[xStart:xEnd]
                    area = [y[yStart:yEnd] for y in columns]
                    highlight_area(area)
                    mapSquare, tileCoords = set_decoration(
                        mapSquare, area, tileSetFolder, tileCoords)
                    mapImages = load_map(mapSquare)

                elif keys[K_LCTRL] and event.key == K_f:
                    mapArea, tileCoords = fill_map(tileSetFolder, tileCoords)
                    if mapArea != None:
                        mapSquare = mapArea
                        mapImages = load_map(mapSquare)

                elif keys[K_LCTRL] and event.key == K_e:
                    columns = mapCoords[xStart:xEnd]
                    area = [y[yStart:yEnd] for y in columns]
                    highlight_area(area)
                    edit_tile_params(mapSquare, area)

                elif keys[K_LCTRL] and event.key == K_r:
                    mapSquare[squareX][squareY].rotate()
                    mapImages[squareX][squareY] = mapSquare[squareX][
                        squareY].draw(BOXSIZE)

                elif keys[K_LCTRL] and event.key == K_h:
                    mapSquare[squareX][squareY].flip_horizontal()
                    mapImages[squareX][squareY] = mapSquare[squareX][
                        squareY].draw(BOXSIZE)

                elif keys[K_LCTRL] and event.key == K_v:
                    mapSquare[squareX][squareY].flip_vertical()
                    mapImages[squareX][squareY] = mapSquare[squareX][
                        squareY].draw(BOXSIZE)

            elif event.type == MOUSEBUTTONUP:
                mouseX, mouseY = event.pos
                tileCoords = (36, 0)
                if nextRect.collidepoint(mouseX, mouseY):
                    tileSetNum += 1
                    if tileSetNum == len(tileSets):
                        tileSetNum = 0

                elif prevRect.collidepoint(mouseX, mouseY):
                    tileSetNum -= 1
                    if tileSetNum < 0:
                        tileSetNum = len(tileSets) - 1

                elif saveRect.collidepoint(mouseX, mouseY):
                    save(mapSquare)

                else:
                    paramKeys = list(setParams.keys())
                    for i in range(len(setParams)):
                        if paramRects[i].collidepoint(mouseX, mouseY):
                            setParams[
                                paramKeys[i]] = not setParams[paramKeys[i]]

            else:
                continue
        columns = mapCoords[xStart:xEnd]
        area = [y[yStart:yEnd] for y in columns]
        draw_tile_params(mapSquare, area)
        highlight_area(area)
        FPSCLOCK.tick(FPS)
Esempio n. 5
0
def set_tiles(mapSquare, area, tileSetFolder, tileCoords):
    yMin, yMax = 0, 15
    xMin, xMax = 36, 51
    squareX, squareY = tileCoords

    xStart, xEnd = squareX - 36, squareX + 1 - 36
    yStart, yEnd = squareY, squareY + 1

    while True:
        draw_tileSet(tileSetFolder)
        for event in pygame.event.get():
            keys = pygame.key.get_pressed()
            if not keys[K_LSHIFT]:
                xStart, xEnd = squareX - 36, squareX + 1 - 36
                yStart, yEnd = squareY, squareY + 1

            if event.type == QUIT or (event.type == KEYUP
                                      and event.key == K_ESCAPE):
                quit()
            elif event.type == KEYDOWN:

                if event.key in [K_UP, K_w]:
                    if squareY != yMin:
                        squareY -= 1
                    else:
                        squareY = yMax
                    if keys[K_LSHIFT]:
                        yStart -= 1

                elif event.key in [K_LEFT, K_a]:
                    if squareX != xMin:
                        squareX -= 1
                    else:
                        squareX = xMax
                    if keys[K_LSHIFT]:
                        xStart -= 1

                elif event.key in [K_RIGHT, K_d]:
                    if squareX != xMax:
                        squareX += 1
                    else:
                        squareX = xMin
                    if keys[K_LSHIFT]:
                        xEnd += 1

                elif event.key in [K_DOWN, K_s]:
                    if squareY != yMax:
                        squareY += 1
                    else:
                        squareY = yMin
                    if keys[K_LSHIFT]:
                        yEnd += 1

                elif event.key == K_SPACE:

                    columns = mapCoords[xStart:xEnd]
                    selected = [y[yStart:yEnd] for y in columns]
                    sWidth = len(selected)
                    sHeight = len(selected[0])

                    aWidth = len(area)
                    aHeight = len(area[0])

                    if (sWidth, sHeight) == (aWidth, aHeight):
                        for x in range(sWidth):
                            for y in range(sHeight):
                                tile = Tile(setParams)
                                tileFile = 'tiles' + sep + tileSetFolder + sep + '%i_%i.png' % (
                                    selected[x][y][0] + 1,
                                    selected[x][y][1] + 1)
                                tile.set_base_tile(tileFile)
                                locX, locY = area[x][y]
                                tile.set_location(locX, locY)
                                mapSquare[locX][locY] = tile

                    elif sWidth == sHeight == 1:
                        for x in range(aWidth):
                            for y in range(aHeight):
                                tile = Tile(setParams)
                                tileFile = 'tiles' + sep + tileSetFolder + sep + '%i_%i.png' % (
                                    selected[0][0][0] + 1,
                                    selected[0][0][1] + 1)
                                tile.set_base_tile(tileFile)
                                locX, locY = area[x][y]
                                tile.set_location(locX, locY)
                                mapSquare[locX][locY] = tile
                    elif sWidth == aWidth:
                        for x in range(aWidth):
                            sY = 0
                            for y in range(aHeight):
                                if sY == sHeight:
                                    sY = 0
                                tile = Tile(setParams)
                                tileFile = 'tiles' + sep + tileSetFolder + sep + '%i_%i.png' % (
                                    selected[x][sY][0] + 1,
                                    selected[x][sY][1] + 1)
                                tile.set_base_tile(tileFile)
                                locX, locY = area[x][y]
                                tile.set_location(locX, locY)
                                mapSquare[locX][locY] = tile
                                sY += 1

                    elif sHeight == aHeight:
                        for y in range(aHeight):
                            sX = 0
                            for x in range(aWidth):
                                if sX == sWidth:
                                    sX = 0
                                tile = Tile(setParams)
                                tileFile = 'tiles' + sep + tileSetFolder + sep + '%i_%i.png' % (
                                    selected[sX][y][0] + 1,
                                    selected[sX][y][1] + 1)
                                tile.set_base_tile(tileFile)
                                locX, locY = area[x][y]
                                tile.set_location(locX, locY)
                                mapSquare[locX][locY] = tile
                                sX += 1
                    else:
                        continue
                    return mapSquare, (squareX, squareY)

                elif event.key == K_q:
                    return mapSquare, (squareX, squareY)
            else:
                continue

        columns = mapCoords[xStart:xEnd]
        selected = [y[yStart:yEnd] for y in columns]
        highlight_area(selected, mapArea=False)
        pygame.display.update()
        FPSCLOCK.tick(FPS)