Example #1
0
def debugInfo():
    #Print some info about the map.
    logger.msg(f"Window size: {conf.windowsize}%")
    logger.msg(f"Window width: {turtle.window_width()}px")
    logger.msg(f"Map width: {mapwidth}")
    logger.msg(f"Tile size: {tilesize}")
    logger.msg(f"Generator: {generator}")
Example #2
0
def printTextInStatus(text):
    logger.msg(f"Printing status: {text}")
    currentposition = turtle.position()
    currentheading = turtle.heading()
    turtle.up()
    turtle.goto(0, 0)
    turtle.seth(direct['NORTH'])
    turtle.forward(tilesize * (mapwidth / 2))
    turtle.color('white', 'white')
    turtle.down()
    turtle.begin_fill()
    turtle.seth(direct['WEST'])
    turtle.forward(tilesize * (mapwidth / 2))
    turtle.seth(direct['NORTH'])
    turtle.forward(turtle.window_height() * 0.1)
    turtle.seth(direct['EAST'])
    turtle.forward(tilesize * mapwidth)
    turtle.seth(direct['SOUTH'])
    turtle.forward(turtle.window_height() * 0.1)
    turtle.seth(direct['WEST'])
    turtle.forward(tilesize * (mapwidth / 2))
    turtle.end_fill()
    turtle.up()
    turtle.color('black')
    turtle.write(text, False, "center", ("Arial", 18, "bold"))
    turtle.goto(currentposition)
    turtle.seth(currentheading)
Example #3
0
def goToStart():
    #Go to the top left of the map.
    #Makes maps more or less centered.
    turtle.up()
    topleft = (
        (mapwidth * tilesize) / 2)  #Row width * tile size in px, halfed.
    turtle.setpos(-topleft, topleft)
    turtle.down()
    logger.msg(f"Start location: -{topleft}, {topleft}")
Example #4
0
 def draw(self):
     for y, row in enumerate(self._tilemap):
         for x, tileid in enumerate(row):
             logger.msg(
                 f"Drawing tile: ({x}, {y}) {tileid}/{tileset[tileid].name}"
             )
             tile = tileset[tileid]
             self.drawTile(tile)
             self.gotoNextCol()
         self.gotoNextRow()
     screen.tracer(True)
     turtle.hideturtle()
     screen.mainloop()
Example #5
0
def drawMap(zoom):
    #Draw the whole map.
    printTextInStatus("Zooming map...")
    global map
    if zoom > 1:
        zoommap(zoom)
    #Print the finished map.
    for row in map:
        logger.load(row)
    printTextInStatus("Drawing map...")
    currentrow = 0
    currentsquare = 0
    mentionedunicode = False
    for row in map:
        currentsquare = 0
        currentrow += 1
        for i in row:
            #printTextInStatus(f"Drawing map... ({currentrow}, {currentsquare})") #This is cool but really slow.
            currentsquare += 1
            if (chooseTile(i) == 'TREE'
                    or chooseTile(i) == 'HOUSE') and mentionedunicode == False:
                printTextInStatus("Loading Unicode...")
            logger.msg(
                f"Drawing tile: ({currentrow}, {currentsquare}) {i}/{chooseTile(i)}"
            )
            drawTile(i)
            if (chooseTile(i) == 'TREE'
                    or chooseTile(i) == 'HOUSE') and mentionedunicode == False:
                printTextInStatus("Drawing map...")
                mentionedunicode = True
            move(ROW)
        move(COL)
    turtle.tracer(True)
    turtle.hideturtle()
    printTextInStatus("")
    turtle.done()
Example #6
0
def gen1():
    #Generator 1: Overworld
    global map, zoomchoice

    lakechance = conf.lakerarity
    spreadpasses = conf.lakesize
    treechance = conf.treerarity
    rockchance = conf.rockrarity
    townchance = conf.townrarity
    townsize = conf.townsize
    zoomchoice = conf.zoomlevel

    #Fill the map with grass.
    printTextInStatus("Planting grass...")
    map = makeBlankMap(getTile('GRASS')[ID])

    #LAKE GEN
    #Dot lakes across the map.
    printTextInStatus("Seeding lakes...")
    for row in range(0, mapwidth - 1):
        for sq in range(0, mapwidth - 1):
            if random.randint(1, lakechance) == 1:
                map[row][sq] = getTile('WATER')[ID]

    #Spread those lakes!
    printTextInStatus("Digging lakes...")
    for x in range(0, spreadpasses):
        watertiles = []
        for row in range(0, mapwidth - 1):
            for sq in range(0, mapwidth - 1):
                if map[row][sq] == getTile('WATER')[ID]:
                    watertiles.append((row, sq))
        for wt in watertiles:
            st = spreadTiles(wt, 66)
            for newtile in st:
                map[newtile[ROW]][newtile[SQ]] = getTile('WATER')[ID]

    #Make beaches.
    printTextInStatus("Filling beaches...")
    watertiles = []
    for row in range(0, mapwidth - 1):
        for sq in range(0, mapwidth - 1):
            if map[row][sq] == getTile('WATER')[ID]:
                watertiles.append((row, sq))
    for wt in watertiles:
        st = spreadTiles(wt, 66)
        for newtile in st:
            if map[newtile[ROW]][newtile[SQ]] == getTile('GRASS')[ID]:
                map[newtile[ROW]][newtile[SQ]] = getTile('SAND')[ID]

    #Drop towns across the map.
    printTextInStatus("Starting towns...")
    for row in range(0, mapwidth - 1):
        for sq in range(0, mapwidth - 1):
            if random.randint(
                    1,
                    townchance) == 1 and map[row][sq] == getTile('GRASS')[ID]:
                map[row][sq] = getTile('HOUSE')[ID]

    #Grow towns.
    printTextInStatus("Expanding towns...")
    for x in range(0, townsize):
        housetiles = []
        for row in range(0, mapwidth - 1):
            for sq in range(0, mapwidth - 1):
                if map[row][sq] == getTile('HOUSE')[ID]:
                    watertiles.append((row, sq))
        for wt in watertiles:
            st = spreadTiles(wt, 80)
            for newtile in st:
                if map[newtile[ROW]][newtile[SQ]] == getTile('GRASS')[ID]:
                    map[newtile[ROW]][newtile[SQ]] = getTile('HOUSE')[ID]

    #Dot trees across the map.
    printTextInStatus("Planting trees...")
    for row in range(0, mapwidth - 1):
        for sq in range(0, mapwidth - 1):
            if random.randint(
                    1,
                    treechance) == 1 and map[row][sq] == getTile('GRASS')[ID]:
                logger.msg(f"Placing tree at ({row}, {sq}).")
                map[row][sq] = getTile('TREE')[ID]

    #Dot rocks across the map.
    printTextInStatus("Throwing rocks...")
    for row in range(0, mapwidth - 1):
        for sq in range(0, mapwidth - 1):
            if random.randint(
                    1,
                    rockchance) == 1 and map[row][sq] == getTile('GRASS')[ID]:
                logger.msg(f"Placing tree at ({row}, {sq}).")
                map[row][sq] = getTile('STONE')[ID]
Example #7
0
def spreadTiles(tile, chance):
    #Spread tiles around a tile with a chance% chance to spread.
    #Returns a list of tuples.

    logger.msg(f"Spreading lake {tile}.")

    returnthis = []

    chance /= 100

    sourcerow = tile[ROW]
    sourcecol = tile[SQ]

    up = (sourcerow - 1, sourcecol)
    left = (sourcerow, sourcecol - 1)
    down = (sourcerow + 1, sourcecol)
    right = (sourcerow, sourcecol + 1)
    topleft = (sourcerow - 1, sourcecol - 1)
    topright = (sourcerow - 1, sourcecol + 1)
    bottomleft = (sourcerow + 1, sourcecol - 1)
    bottomright = (sourcerow + 1, sourcecol + 1)

    topedge = False
    leftedge = False
    bottomedge = False
    rightedge = False

    spreadup = False
    spreaddown = False
    spreadleft = False
    spreadright = False
    spreadtopleft = False
    spreadtopright = False
    spreadbottomleft = False
    spreadbottomright = False

    if sourcerow == 0: topedge = True
    if sourcecol == 0: leftedge = True
    if sourcerow == mapwidth - 1: bottomedge = True
    if sourcecol == mapwidth - 1: rightedge = True

    if random.random() < chance: spreadup = True
    if random.random() < chance: spreaddown = True
    if random.random() < chance: spreadleft = True
    if random.random() < chance: spreadright = True
    if spreadup and spreadleft and random.random() < chance:
        spreadtopleft = True
    if spreadup and spreadright and random.random() < chance:
        spreadtopright = True
    if spreaddown and spreadleft and random.random() < chance:
        spreadbottomleft = True
    if spreaddown and spreadright and random.random() < chance:
        spreadbottomright = True

    if topedge: spreadup = spreadtopleft = spreadtopright = False
    if bottomedge: spreaddown = spreadbottomleft = spreadbottomright = False
    if leftedge: spreadleft = spreadtopleft = spreadbottomleft = False
    if rightedge: spreadright = spreadtopright = spreadbottomright = False

    if spreadup: returnthis.append(up)
    if spreaddown: returnthis.append(down)
    if spreadleft: returnthis.append(left)
    if spreadright: returnthis.append(right)
    if spreadtopleft: returnthis.append(topleft)
    if spreadtopright: returnthis.append(topright)
    if spreadbottomleft: returnthis.append(bottomleft)
    if spreadbottomright: returnthis.append(bottomright)

    spreadtopleft = False
    spreadtopright = False
    spreadbottomleft = False
    spreadbottomright = False

    #logger.msg(f"{returnthis}")
    return returnthis