1 GameLevel::GameLevel(char *pcFileToLoad) : 2 mbValid(FALSE) 3 { 4 TiXmlDocument doc(pcFileToLoad); 5 6 // load and check if it was successful 7 if (doc.LoadFile()) 8 { 9 TiXmlElement *root = doc.RootElement(); 10 11 // extract level name, can check at some point 12 printf("Level name %s\n", root->Attribute("Name")); 13 14 for(TiXmlElement* LayersElem = root->FirstChildElement(); LayersElem; 15 LayersElem = LayersElem->NextSiblingElement()) 16 { 17 printf("LayersElem %s\n", LayersElem->ValueStr().c_str()); 18 19 // this should be Layers 20 if (LayersElem->ValueStr() == string("Layers")) 21 { 22 for(TiXmlElement* LayerElem = LayersElem->FirstChildElement(); LayerElem; 23 LayerElem = LayerElem->NextSiblingElement()) 24 { 25 printf("LayerElem %s\n", LayerElem->ValueStr().c_str()); 26 // This should be Layer 27 if (LayerElem->ValueStr() == string("Layer")) 28 { 29 for(TiXmlElement* ItemsElem = LayerElem->FirstChildElement(); ItemsElem; 30 ItemsElem = ItemsElem->NextSiblingElement()) 31 { 32 printf("ItemsElem %s\n", ItemsElem->ValueStr().c_str()); 33 // This should be Items 34 if (ItemsElem->ValueStr() == string("Items")) 35 { 36 for(TiXmlElement* ItemElem = ItemsElem->FirstChildElement(); ItemElem; 37 ItemElem = ItemElem->NextSiblingElement()) 38 { 39 // This should be Item 40 if (ItemElem->ValueStr() == string("Item")) 41 { 42 ParseItem(ItemElem); 43 } 44 } 45 } 46 else 47 { 48 // it's scoll speed, we can ignore 49 printf("Skip Scroll\n"); 50 } 51 } 52 } 53 } 54 } 55 } 56 mbValid = TRUE; 57 } 58 else 59 { 60 printf("Failed opening %s, reason: %s\n", pcFileToLoad, doc.ErrorDesc()); 61 } 62 63 }