简体   繁体   中英

Top-Down map scrolling with python ncurses

I'm new to curses but I have some experience. I'm trying to make a top-down style game in python with ncurses, but I don't even know where to start. I'm wanting the character to be centered on the screen and move around the map, but the environment to not all be visible on the screen at once. Is this possible? I would like to know before I get started.

For the background, if it's text-based, you could draw the map using 2-layer list or tuple that gets printed using loops and slices with window .addstr(x,y, string )

example, with stdscr as the name of the window:

map_tiles = [['a','1','+'],['b','2','-'],['c','3','=']]
inx = 0
iny = 0
range = 1
def scroll(bx,by):
    stdscr.clear()
    for y, x_line in enumerate(map_tiles[by : by+range]):
        for x, tile in enumerate(x_line[bx : bx+range]):
            stdscr.addstr(y, x, f'{tile}')

then, by calling scroll(inx.iny) the tiles within range of the slices map_tiles[by: by+range] and map_tiles[bx: bx+range] will get printed in the terminal. You can then bind keys to add increments to inx and iny to change the visible tiles.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM