Loading a map in Pygame / Python

前端 未结 3 696
面向向阳花
面向向阳花 2021-01-26 23:04

How would I go about loading a map file in Pygame / Python?

I would like to load a map file in this format;

http://pastebin.com/12DZhrtp

EDIT: I\'m guess

3条回答
  •  情书的邮戳
    2021-01-26 23:18

    If you're literally asking how to load a file in Python -- disregarding the pygame side of the question -- then it's very simple.

    >>> with open('a.map', 'r') as f:
    ...     for line in f:
    ...         print line,
    ... 
    x g g g x
    x g g g x
    x g x g x
    x g g g x
    x x x x x
    
    KEY:
    x = wall
    g = grass / floor
    

    Now instead of printing each line, you can simply read through it and store it in whatever data structure you're using.

    I don't know anything about pygame though -- if it has some custom function for this, I can't help with that.

提交回复
热议问题