1 void GameLevel::ParseItem(TiXmlElement* ItemElem) 2 { 3 tLevelWall LevelWall; 4 tLevelItem LevelItem; 5 map SpecValues; 6 7 // store off position 8 cpVect Position; 9 10 Position.x = atof(ItemElem->FirstChild("Position")->FirstChild("X")->FirstChild()->Value()); 11 Position.y = atof(ItemElem->FirstChild("Position")->FirstChild("Y")->FirstChild()->Value()); 12 13 // check for custom properties and handle if found 14 if (ItemElem->FirstChildElement("CustomProperties")->FirstChild() != NULL) 15 { 16 string Key, Value; 17 for(TiXmlElement* PropElem = ItemElem->FirstChildElement("CustomProperties")->FirstChildElement(); PropElem; 18 PropElem = PropElem->NextSiblingElement()) 19 { 20 Key = PropElem->Attribute("Name"); 21 Value = PropElem->FirstChild()->ValueStr(); 22 printf("SpecField Key %s Val %s\n", Key.c_str(), Value.c_str()); 23 SpecValues[Key] = Value; 24 } 25 } 26 27 // check for spawn 1st 28 if (strncmp(ItemElem->Attribute("Name"), "Spawn", 5) == 0) 29 { 30 mSpawns.push_back(Position); 31 } 32 /* If it's a rectangle, it's made as a wall or spawn point */ 33 else if (strcmp(ItemElem->Attribute("xsi:type"), "RectangleItem") == 0) 34 { 35 LevelWall.StartingPoint = Position; 36 LevelWall.EndingPoint.x = atof(ItemElem->FirstChild("Width")->FirstChild()->Value()) + 37 Position.x; 38 LevelWall.EndingPoint.y = atof(ItemElem->FirstChild("Height")->FirstChild()->Value()) + 39 Position.y; 40 41 LevelWall.bIsRect = TRUE; 42 printf("Rect Start x %f end %f\n", LevelWall.StartingPoint.x, LevelWall.EndingPoint.x); 43 printf("Rect Start y %f end %f\n", LevelWall.StartingPoint.y, LevelWall.EndingPoint.y); 44 45 // add to vector 46 mWalls.push_back(LevelWall); 47 } 48 else if (strcmp(ItemElem->Attribute("xsi:type"), "TextureItem") == 0) 49 { 50 string TempString; 51 cpVect SecondLoc = cpvzero; 52 53 LevelItem.Location = Position; 54 55 printf("SpriteName %s\n", ItemElem->FirstChild("texture_filename")->FirstChild()->Value()); 56 57 // get name up to _ 58 TempString = string(ItemElem->Attribute("Name")); 59 LevelItem.ItemName = TempString.substr(0, TempString.find("_")); 60 61 cout << "LevelItem name " << LevelItem.ItemName << endl; 62 63 // load the texture here 64 LevelItem.pImage = Utilities::ImageGet(ItemElem->FirstChild("texture_filename")->FirstChild()->Value()); 65 66 mItems.push_back(LevelItem); 67 68 } 69 else if (strcmp(ItemElem->Attribute("xsi:type"), "PathItem") == 0) 70 { 71 // Parse the Path starting at WorldPoints 72 ParsePath(ItemElem->Attribute("Name"), 73 ItemElem->FirstChild("WorldPoints")->FirstChild("Vector2")); 74 } 75 76 }