def _loadInfo(self, infoTree): for infoNode in infoTree.childNodes: if infoNode.nodeName == 'type': pass elif infoNode.nodeName == "points": pass elif infoNode.nodeName == "life": self.life = int(infoNode.firstChild.data) elif infoNode.nodeName == 'movespeed': self.movespeed = Vector(int(infoNode.firstChild.data), 0) elif infoNode.nodeName == 'jumpspeed': self.jumpspeed = Vector(0, int(infoNode.firstChild.data)) elif infoNode.nodeName == 'jumpSound': for cNode in infoNode.childNodes: if cNode.nodeName == "soundFile": SoundManager.addSound("player_jump", str(cNode.firstChild.data)) elif infoNode.nodeName == 'sprite': for animationNode in infoNode.childNodes: if animationNode.nodeName == 'animation': animationIndex = animationNode.getAttribute('index') animationGraphics = [] for cNode in animationNode.childNodes: if cNode.nodeName == 'type': animationType = str(cNode.firstChild.data) elif cNode.nodeName == "image": for ccNode in cNode.childNodes: if ccNode.nodeName == "graphic": animationGraphics.append( str(ccNode.firstChild.data)) self.sprite.addAnimation(animationType, animationGraphics) elif infoNode.nodeName == 'colShape': for colRectNode in infoNode.childNodes: if colRectNode.nodeName == 'colRect': posUpperLeft = [0, 0] dimensions = [0, 0] isSpike = None isBody = None colRectIndex = int(colRectNode.getAttribute("index")) for colRectInfoNode in colRectNode.childNodes: if colRectInfoNode.nodeName == 'posUpperLeft': for posUpperLeftNode in colRectInfoNode.childNodes: if posUpperLeftNode.nodeName == 'horizontal': posUpperLeft[0] = int( posUpperLeftNode.firstChild.data) elif posUpperLeftNode.nodeName == 'vertical': posUpperLeft[1] = int( posUpperLeftNode.firstChild.data) elif colRectInfoNode.nodeName == 'dimensions': for dimensionsNode in colRectInfoNode.childNodes: if dimensionsNode.nodeName == 'horizontal': dimensions[0] = int( dimensionsNode.firstChild.data) elif dimensionsNode.nodeName == 'vertical': dimensions[1] = int( dimensionsNode.firstChild.data) elif colRectInfoNode.nodeName == 'isBody': isBody = util.string2bool( colRectInfoNode.firstChild.data) elif colRectInfoNode.nodeName == 'isSpike': isSpike = util.string2bool( colRectInfoNode.firstChild.data) self.colShape.addRect(posUpperLeft, dimensions, isBody, isSpike) self._calcDimensions()
def _loadMapFile(self, mapFile): xmlMapTree = minidom.parse(RessourceLoader.getCorrectLevelPath(mapFile)) docRoot = xmlMapTree.firstChild for node in docRoot.childNodes: #--------mapName-------- if node.nodeName == "name": self.mapTitle = node.firstChild.data.strip() #--------mapTiles-------- elif node.nodeName == 'tiles': self.tiles[0] = Tile("blank", "blank", None, False, False) self.tiles[1] = Tile("blocker", "blocker", None, True, False) self.tileCount = len([cNode for cNode in node.childNodes if cNode.nodeName == 'tile']) for cNode in node.childNodes: if cNode.nodeName == "tile": tileIndex = int(cNode.getAttribute('index')) for ccNode in cNode.childNodes: if ccNode.nodeName == "name": tileName = str(ccNode.firstChild.data.strip()) elif ccNode.nodeName == 'type': tileType = str(ccNode.firstChild.data.strip()) elif ccNode.nodeName == 'graphic': tileGraphic = str(ccNode.firstChild.data.strip()) elif ccNode.nodeName == 'accessibility': if ccNode.firstChild.data.strip() == 'true': tileAccessibility = True elif ccNode.firstChild.data.strip() == 'false': tileAccessibility = False elif ccNode.nodeName == 'dangerousness': if ccNode.firstChild.data.strip() == 'true': tileDangerousness = True elif ccNode.firstChild.data.strip() == 'false': tileDangerousness = False self.tiles[tileIndex] = Tile(tileName, tileType, tileGraphic, tileAccessibility, tileDangerousness) #--------mapBackground-------- elif node.nodeName == 'background': self.bgLayerCount = len([cNode for cNode in node.childNodes if cNode.nodeName == 'bgLayer']) #Anzahl der bgLayer-nodes for cNode in node.childNodes: if cNode.nodeName == 'bgLayer': bgLayerIndex = int(cNode.getAttribute('index')) for ccNode in cNode.childNodes: if ccNode.nodeName == 'speed': bgLayerSpeed = int(ccNode.firstChild.data.strip()) #bgLayerSpeed elif ccNode.nodeName == 'graphic': bgLayerGraphic = str(ccNode.firstChild.data.strip()) #bgLayerImage self.bgLayers[bgLayerIndex] = BgLayer(bgLayerSpeed, bgLayerGraphic) #0=position in px #--------mapMusic-------- elif node.nodeName == 'music': for cNode in node.childNodes: if cNode.nodeName == 'backgroundTheme': for ccNode in cNode.childNodes: if ccNode.nodeName == 'soundFile': SoundManager.addSound("background_theme",str(ccNode.firstChild.data.strip())) #--------mapGrid-------- elif node.nodeName == 'grid': self.gridLayerCount = len([cNode for cNode in node.childNodes if cNode.nodeName == 'gridLayer']) #Anzahl der gridlayer-nodes self.dimensions = [0,0] #start counting from 1 not 0!! #TODO: filter NOT rectangular grids and raise exception! for cNode in node.childNodes: if cNode.nodeName == 'gridLayer': gridLayerIndex = int(cNode.getAttribute('index')) self.mapGrid.append([]) for colNode in cNode.childNodes: if colNode.nodeName == 'column': columnIndex = int(colNode.getAttribute('index')) if columnIndex+1 > self.dimensions[0]: self.dimensions[0] = columnIndex+1 self.mapGrid[gridLayerIndex].append([]) for rowNode in colNode.childNodes: if rowNode.nodeName == 'row': rowIndex = int(rowNode.getAttribute('index')) if rowIndex+1 > self.dimensions[1]: self.dimensions[1] = rowIndex+1 self.mapGrid[gridLayerIndex][columnIndex].append(None) for tileIndex in rowNode.childNodes: if tileIndex.nodeName == 'tileIndex': self.mapGrid[gridLayerIndex][columnIndex][rowIndex] = int(tileIndex.firstChild.data.strip()) #mapGrid #--------entityFile-------- elif node.nodeName == 'entityFile': self.entityFilePath = node.firstChild.data.strip() #entityFile Path