Exemple #1
0
    def __init__(self, filename=None):
        dict.__init__(self)

        self["tset"] = "tileset"
        self["tilemap"] = {}
        self["objects"] = {}
        self["max"] = (0, 0)
        self["options"] = {}
        self["options"]["clan"] = "fire"

        self["start"] = (128, 128)
        self["exit"] = (0, 0)
        self.filename = filename
        if self.filename is None:
            self.filename = ""

        try:
            data = load_object(filepath(map_folder, filename))
        except:
            print "Could not load map. Using empty map"
            return

        self["tset"] = data["tset"]
        self["tilemap"] = data["tilemap"]
        self["objects"] = data["objects"]
        self["options"] = data["options"]
Exemple #2
0
 def save_map(self, filename="tmp", path=""):
     if not path:
         path = filepath(map_folder, filename)
     mapdata = {}
     keys = ["tilemap", "tset", "objects", "options"]
     for k in keys:
         mapdata[k] = self[k]
     save_object(mapdata, path)
def save_map(mapdata, filename, folder):
    path = data.filepath(folder, filename)

    try:
        mapdata.filename = filename[:-4]
        data.save_object(mapdata, path)
        return 1
    except:
        return 0
Exemple #4
0
    def __init__(self, filename):
        #load file from ../maps/<filename>
        self.name = filename
        path = os.path.join("maps", filename)
        fullpath = data.filepath(path)
        try:
            f = open(fullpath, "r")
        except:
            print "Could not load file: ", fullpath
            sys.exit(1)

        #set tileset and optscore
        ln = f.readline().strip().split(",")
        self.tilesetname = ln[0] + ".png"
        if len(ln) < 2:
            self.optscore = 2500
        else:
            self.optscore = int(ln[1])

        #save mapdata in self.map
        self.start = (0, 0)
        self.exit = (1, 1)

        self.cats = 0
        self.crates = []
        self.keys = []
        self.bdoor = None
        y = 1
        map = {}
        for line in f:
            x = 1
            for char in line.strip():
                map[x, y] = char
                if char == "S":  #start
                    self.start = (x, y)
                elif char == "E":  #exit
                    self.exit = (x, y)
                elif char == "C":  #crateposition
                    self.crates.append((x, y))
                elif char == "K":
                    self.keys.append((x, y))
                elif char == "*":  #buttondoor
                    self.bdoor = (x, y)
                elif char == "P":
                    self.cats += 1
                x += 1
            y += 1
        f.close()

        self.map = map
        self.cur_map = {}
        pygame.Surface.__init__(self, (x * 32, y * 32))
Exemple #5
0
    def load_map(self, btn_nr):
        if btn_nr >= len(self.filenames):
            print "eek!"
            return

        filename = self.filenames[btn_nr + (self.cur_page * self.max_lines)]
        path = data.filepath(MAP_folder, filename)
        try:
            mapdata = data.load_object(path)
            self.show_msg("Map loaded.")
        except:
            self.show_msg("ERROR: Loading map failed.")

        if mapdata:
            self.kill_prev = True
            self.next = Editor(mapdata)
            self.quit()
Exemple #6
0
def get_maps(folder="lvl"):
    path = filepath(folder)
    return os.listdir(path)