Example #1
0
    def changeMapHelper(self, mapFile, position, callback, face="down"):
        #executing code before killing the map
        if self.unloadScript != False:
            eval(self.unloadScript)

        #disabling all lights
        render.setLightOff()

        #manually removing tiles
        for t in self.tileset[:]:
            t.destroy()
            self.tileset.remove(t)

        #manually removing characters
        for c in self.characterset[:]:
            c.destroy()
            self.characterset.remove(c)

        #destroying every node
        for n in self.node.getChildren():
            n.removeNode()

        tks = position.split(',')
        if len(tks) > 1:
            x = int(tks[0])
            y = int(tks[1])
        else:
            print(
                'ERROR: please define a correct position in .map file, resetting to 0,0'
            )
            x = 0
            y = 0

        if not os.path.isfile(mapFile):
            self.loadMap(resourceManager.getResource('Mappe/' + mapFile),
                         LPoint2i(x, y))
        else:
            self.loadMap(mapFile, LPoint2i(x, y))

        if main.editormode == False:
            self.getPlayable().setFollowedByCamera(True)
            self.getPlayable().face(face)

        self.currentMapPath = mapFile
        self.currentMapName = mapFile.split('/')[-1].replace('.map', '')

        if self.loadScript != False and main.editormode == False:
            eval(self.loadScript)

        callback.start()
Example #2
0
 def getViewportCenterPixels(self):
     return LPoint2i(self.win.getXSize() // 2, self.win.getYSize() // 2)
Example #3
0
    def loadMap(self, file, playable_pos=LPoint2i(0, 0)):
        xmldoc = minidom.parse(file)

        data = xmldoc.getElementsByTagName('data')
        for d in data:
            if d.attributes > 0:
                if d.attributes.has_key('tilesize'):
                    self.tileDimension = float(d.attributes['tilesize'].value)
                else:
                    self.tileDimension = 32.0
                if d.attributes.has_key('showcollisions'):
                    if d.attributes['showcollisions'].value == 'false':
                        self.showCollisions = False
                    else:
                        self.showCollisions = True
                else:
                    self.showCollisions = False
                if d.attributes.has_key('camdistance'):
                    customCamera.setDistance(
                        float(d.attributes['camdistance'].value))
                else:
                    customCamera.setDistance(15)
                if d.attributes.has_key('onLoad'):
                    self.loadScript = d.attributes['onLoad'].value
                else:
                    self.loadScript = False

                if d.attributes.has_key('onUnload'):
                    self.unloadScript = d.attributes['onUnload'].value
                else:
                    self.unloadScript = False

        rowsdata = xmldoc.getElementsByTagName('row')

        currentx = 0
        currenty = 0

        for row in rowsdata:  #for every row
            for tile in row.childNodes:  #for every tile
                if tile.nodeType == Node.ELEMENT_NODE:  #if child is tile
                    t = Tile(self.tileDimension)
                    t.setX(currentx)
                    t.setY(currenty)

                    #apending lolol
                    self.tileset.append(t)

                    o = Once(
                    )  #lo switch viene fatto solo in presenza di una texture 'ground'

                    for res in tile.childNodes:
                        if res.nodeType == Node.ELEMENT_NODE:  # adding resources to tile
                            if res.nodeName == 'ground':
                                t.addTexture(res.attributes)
                                if o.get():
                                    currentx += 1
                            elif res.nodeName == 'object':
                                t.addObject(res.attributes)
                            elif res.nodeName == 'grass':
                                g = Grass(res.attributes,
                                          self.tileDimension)  #creating object
                                t.addCustomObject(
                                    g)  #setting coordinates of tile
                                g.getNode().wrtReparentTo(self.grassnode)
                            elif res.nodeName == 'light':
                                t.addLight(res.attributes)
                            elif res.nodeName == 'scrollable':
                                c = Scrollable(
                                    res.attributes['url'].value,
                                    res.attributes['inclination'].value,
                                    self.tileDimension)
                                c.setX(currentx)
                                c.setY(currenty)
                                self.scrollableset.append(c)
                            elif res.nodeName == 'character':
                                t.addCharacter(res.attributes,
                                               self.showCollisions,
                                               playable_pos)

                    t.node.reparentTo(self.node)
            currentx = 0
            currenty += 1

        self.grassnode.flattenStrong(
        )  #pumping performance for dynamic grass (like, 120x)